當前位置: 首頁>>代碼示例>>Java>>正文


Java OLAPContext.getThreadLocalContexts方法代碼示例

本文整理匯總了Java中org.apache.kylin.query.relnode.OLAPContext.getThreadLocalContexts方法的典型用法代碼示例。如果您正苦於以下問題:Java OLAPContext.getThreadLocalContexts方法的具體用法?Java OLAPContext.getThreadLocalContexts怎麽用?Java OLAPContext.getThreadLocalContexts使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.apache.kylin.query.relnode.OLAPContext的用法示例。


在下文中一共展示了OLAPContext.getThreadLocalContexts方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: buildSqlResponse

import org.apache.kylin.query.relnode.OLAPContext; //導入方法依賴的package包/類
private SQLResponse buildSqlResponse(Boolean isPushDown, List<List<String>> results,
        List<SelectedColumnMeta> columnMetas) {

    boolean isPartialResult = false;
    StringBuilder cubeSb = new StringBuilder();
    StringBuilder logSb = new StringBuilder("Processed rows for each storageContext: ");
    if (OLAPContext.getThreadLocalContexts() != null) { // contexts can be null in case of 'explain plan for'
        for (OLAPContext ctx : OLAPContext.getThreadLocalContexts()) {
            if (ctx.realization != null) {
                isPartialResult |= ctx.storageContext.isPartialResultReturned();
                if (cubeSb.length() > 0) {
                    cubeSb.append(",");
                }
                cubeSb.append(ctx.realization.getCanonicalName());
                logSb.append(ctx.storageContext.getProcessedRowCount()).append(" ");
            }
        }
    }
    logger.info(logSb.toString());

    SQLResponse response = new SQLResponse(columnMetas, results, cubeSb.toString(), 0, false, null, isPartialResult,
            isPushDown);
    response.setTotalScanCount(QueryContext.current().getScannedRows());
    response.setTotalScanBytes(QueryContext.current().getScannedBytes());
    return response;
}
 
開發者ID:apache,項目名稱:kylin,代碼行數:27,代碼來源:QueryService.java

示例2: logQuery

import org.apache.kylin.query.relnode.OLAPContext; //導入方法依賴的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());
}
 
開發者ID:apache,項目名稱:kylin,代碼行數:55,代碼來源:QueryService.java

示例3: logQuery

import org.apache.kylin.query.relnode.OLAPContext; //導入方法依賴的package包/類
public void logQuery(final SQLRequest request, final SQLResponse response, final Date startTime, final Date endTime) {
    final String user = SecurityContextHolder.getContext().getAuthentication().getName();
    final Set<String> realizationNames = new HashSet<String>();
    final Set<Long> cuboidIds = new HashSet<Long>();
    long totalScanCount = 0;
    float duration = (endTime.getTime() - startTime.getTime()) / (float) 1000;

    if (!response.isHitCache() && 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) {
                String realizationName = ctx.realization.getName();
                realizationNames.add(realizationName);
            }

            totalScanCount += ctx.storageContext.getTotalScanCount();
        }
    }

    int resultRowCount = 0;
    if (!response.getIsException() && response.getResults() != null) {
        resultRowCount = response.getResults().size();
    }

    QueryMetrics.getInstance().increase("duration", duration);
    QueryMetrics.getInstance().increase("totalScanCount", (float) totalScanCount);
    QueryMetrics.getInstance().increase("count", (float) 1);

    String newLine = System.getProperty("line.separator");
    StringBuilder stringBuilder = new StringBuilder();
    stringBuilder.append(newLine);
    stringBuilder.append("==========================[QUERY]===============================").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(totalScanCount).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 Cache: ").append(response.isHitCache()).append(newLine);
    stringBuilder.append("Message: ").append(response.getExceptionMessage()).append(newLine);
    stringBuilder.append("==========================[QUERY]===============================").append(newLine);

    logger.info(stringBuilder.toString());
}
 
開發者ID:KylinOLAP,項目名稱:Kylin,代碼行數:55,代碼來源:QueryService.java

示例4: execute

import org.apache.kylin.query.relnode.OLAPContext; //導入方法依賴的package包/類
/**
 * @param sql
 * @param sqlRequest
 * @return
 * @throws Exception
 */
private SQLResponse execute(String sql, SQLRequest sqlRequest) throws Exception {
    Connection conn = null;
    Statement stat = null;
    ResultSet resultSet = null;
    List<List<String>> results = new LinkedList<List<String>>();
    List<SelectedColumnMeta> columnMetas = new LinkedList<SelectedColumnMeta>();

    try {
        conn = getOLAPDataSource(sqlRequest.getProject()).getConnection();

        if (sqlRequest instanceof PrepareSqlRequest) {
            PreparedStatement preparedState = conn.prepareStatement(sql);

            for (int i = 0; i < ((PrepareSqlRequest) sqlRequest).getParams().length; i++) {
                setParam(preparedState, i + 1, ((PrepareSqlRequest) sqlRequest).getParams()[i]);
            }

            resultSet = preparedState.executeQuery();
        } else {
            stat = conn.createStatement();
            resultSet = stat.executeQuery(sql);
        }

        ResultSetMetaData metaData = resultSet.getMetaData();
        int columnCount = metaData.getColumnCount();

        // Fill in selected column meta
        for (int i = 1; i <= columnCount; ++i) {
            columnMetas.add(new SelectedColumnMeta(metaData.isAutoIncrement(i), metaData.isCaseSensitive(i), metaData.isSearchable(i), metaData.isCurrency(i), metaData.isNullable(i), metaData.isSigned(i), metaData.getColumnDisplaySize(i), metaData.getColumnLabel(i), metaData.getColumnName(i), metaData.getSchemaName(i), metaData.getCatalogName(i), metaData.getTableName(i), metaData.getPrecision(i), metaData.getScale(i), metaData.getColumnType(i), metaData.getColumnTypeName(i), metaData.isReadOnly(i), metaData.isWritable(i), metaData.isDefinitelyWritable(i)));
        }

        List<String> oneRow = new LinkedList<String>();

        // fill in results
        while (resultSet.next()) {
            for (int i = 0; i < columnCount; i++) {
                oneRow.add((resultSet.getString(i + 1)));
            }

            results.add(new LinkedList<String>(oneRow));
            oneRow.clear();
        }
    } finally {
        close(resultSet, stat, conn);
    }

    boolean isPartialResult = false;
    String cube = "";
    long totalScanCount = 0;
    if (OLAPContext.getThreadLocalContexts() != null) { // contexts can be null in case of 'explain plan for'
        for (OLAPContext ctx : OLAPContext.getThreadLocalContexts()) {
            isPartialResult |= ctx.storageContext.isPartialResultReturned();
            cube = ctx.realization.getName();
            totalScanCount += ctx.storageContext.getTotalScanCount();
        }
    }

    SQLResponse response = new SQLResponse(columnMetas, results, cube, 0, false, null, isPartialResult);
    response.setTotalScanCount(totalScanCount);

    return response;
}
 
開發者ID:KylinOLAP,項目名稱:Kylin,代碼行數:69,代碼來源:QueryService.java


注:本文中的org.apache.kylin.query.relnode.OLAPContext.getThreadLocalContexts方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。