本文整理汇总了Java中org.apache.kylin.rest.response.SQLResponse.getDuration方法的典型用法代码示例。如果您正苦于以下问题:Java SQLResponse.getDuration方法的具体用法?Java SQLResponse.getDuration怎么用?Java SQLResponse.getDuration使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.kylin.rest.response.SQLResponse
的用法示例。
在下文中一共展示了SQLResponse.getDuration方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: logQuery
import org.apache.kylin.rest.response.SQLResponse; //导入方法依赖的package包/类
public void logQuery(final SQLRequest request, final SQLResponse response) {
final String user = aclEvaluate.getCurrentUserName();
final List<String> realizationNames = new LinkedList<>();
final Set<Long> cuboidIds = new HashSet<Long>();
float duration = response.getDuration() / (float) 1000;
boolean storageCacheUsed = response.isStorageCacheUsed();
boolean isPushDown = response.isPushDown();
if (!response.isHitExceptionCache() && null != OLAPContext.getThreadLocalContexts()) {
for (OLAPContext ctx : OLAPContext.getThreadLocalContexts()) {
Cuboid cuboid = ctx.storageContext.getCuboid();
if (cuboid != null) {
//Some queries do not involve cuboid, e.g. lookup table query
cuboidIds.add(cuboid.getId());
}
if (ctx.realization != null) {
realizationNames.add(ctx.realization.getCanonicalName());
}
}
}
int resultRowCount = 0;
if (!response.getIsException() && response.getResults() != null) {
resultRowCount = response.getResults().size();
}
String newLine = System.getProperty("line.separator");
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.append(newLine);
stringBuilder.append("==========================[QUERY]===============================").append(newLine);
stringBuilder.append("Query Id: ").append(QueryContext.current().getQueryId()).append(newLine);
stringBuilder.append("SQL: ").append(request.getSql()).append(newLine);
stringBuilder.append("User: ").append(user).append(newLine);
stringBuilder.append("Success: ").append((null == response.getExceptionMessage())).append(newLine);
stringBuilder.append("Duration: ").append(duration).append(newLine);
stringBuilder.append("Project: ").append(request.getProject()).append(newLine);
stringBuilder.append("Realization Names: ").append(realizationNames).append(newLine);
stringBuilder.append("Cuboid Ids: ").append(cuboidIds).append(newLine);
stringBuilder.append("Total scan count: ").append(response.getTotalScanCount()).append(newLine);
stringBuilder.append("Total scan bytes: ").append(response.getTotalScanBytes()).append(newLine);
stringBuilder.append("Result row count: ").append(resultRowCount).append(newLine);
stringBuilder.append("Accept Partial: ").append(request.isAcceptPartial()).append(newLine);
stringBuilder.append("Is Partial Result: ").append(response.isPartial()).append(newLine);
stringBuilder.append("Hit Exception Cache: ").append(response.isHitExceptionCache()).append(newLine);
stringBuilder.append("Storage cache used: ").append(storageCacheUsed).append(newLine);
stringBuilder.append("Is Query Push-Down: ").append(isPushDown).append(newLine);
stringBuilder.append("Trace URL: ").append(response.getTraceUrl()).append(newLine);
stringBuilder.append("Message: ").append(response.getExceptionMessage()).append(newLine);
stringBuilder.append("==========================[QUERY]===============================").append(newLine);
logger.info(stringBuilder.toString());
}
示例2: doQuery
import org.apache.kylin.rest.response.SQLResponse; //导入方法依赖的package包/类
private SQLResponse doQuery(SQLRequest sqlRequest) {
String sql = sqlRequest.getSql();
String project = sqlRequest.getProject();
logger.info("Using project: " + project);
logger.info("The original query: " + sql);
String serverMode = KylinConfig.getInstanceFromEnv().getServerMode();
if (!(Constant.SERVER_MODE_QUERY.equals(serverMode.toLowerCase()) || Constant.SERVER_MODE_ALL.equals(serverMode.toLowerCase()))) {
throw new InternalErrorException("Query is not allowed in " + serverMode + " mode.");
}
if (sql.toLowerCase().contains("select") == false) {
logger.debug("Directly return expection as not supported");
throw new InternalErrorException(QueryUtil.makeErrorMsgUserFriendly("Not Supported SQL."));
}
SQLResponse sqlResponse = searchQueryInCache(sqlRequest);
try {
if (null == sqlResponse) {
sqlResponse = queryService.query(sqlRequest);
long durationThreshold = KylinConfig.getInstanceFromEnv().getQueryDurationCacheThreshold();
long scancountThreshold = KylinConfig.getInstanceFromEnv().getQueryScanCountCacheThreshold();
if (!sqlResponse.getIsException() && (sqlResponse.getDuration() > durationThreshold || sqlResponse.getTotalScanCount() > scancountThreshold)) {
cacheManager.getCache(SUCCESS_QUERY_CACHE).put(new Element(sqlRequest, sqlResponse));
}
}
checkQueryAuth(sqlResponse);
return sqlResponse;
} catch (AccessDeniedException ade) {
// Access exception is bind with each user, it will not be cached
logger.error("Exception when execute sql", ade);
throw new ForbiddenException(ade.getLocalizedMessage());
} catch (Throwable e) { // calcite may throw AssertError
SQLResponse exceptionRes = new SQLResponse(null, null, 0, true, e.getMessage());
Cache exceptionCache = cacheManager.getCache(EXCEPTION_QUERY_CACHE);
exceptionCache.put(new Element(sqlRequest, exceptionRes));
logger.error("Exception when execute sql", e);
throw new InternalErrorException(QueryUtil.makeErrorMsgUserFriendly(e.getLocalizedMessage()));
}
}