当前位置: 首页>>代码示例>>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;未经允许,请勿转载。