Java Code Examples for org.apache.kylin.query.relnode.OLAPContext#getThreadLocalContexts()

The following examples show how to use org.apache.kylin.query.relnode.OLAPContext#getThreadLocalContexts() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: QueryService.java    From kylin-on-parquet-v2 with Apache License 2.0 5 votes vote down vote up
private static PreparedContext createPreparedContext(String project, String sql) throws Exception {
    Connection conn = QueryConnection.getConnection(project);
    PreparedStatement preparedStatement = conn.prepareStatement(sql);
    Collection<OLAPContext> olapContexts = OLAPContext.getThreadLocalContexts();
    // If the preparedContext is first initialized, then set the borrowed tag to false
    for (OLAPContext olapContext : olapContexts) {
        olapContext.isBorrowedContext = false;
    }
    return new PreparedContext(conn, preparedStatement, olapContexts);
}
 
Example 2
Source File: QueryService.java    From kylin with Apache License 2.0 5 votes vote down vote up
private static PreparedContext createPreparedContext(String project, String sql) throws Exception {
    Connection conn = QueryConnection.getConnection(project);
    PreparedStatement preparedStatement = conn.prepareStatement(sql);
    Collection<OLAPContext> olapContexts = OLAPContext.getThreadLocalContexts();
    // If the preparedContext is first initialized, then set the borrowed tag to false
    for (OLAPContext olapContext : olapContexts) {
        olapContext.isBorrowedContext = false;
    }
    return new PreparedContext(conn, preparedStatement, olapContexts);
}
 
Example 3
Source File: QueryService.java    From kylin-on-parquet-v2 with Apache License 2.0 4 votes vote down vote up
/**
 * @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 = Lists.newArrayList();
    List<SelectedColumnMeta> columnMetas = Lists.newArrayList();

    try {
        conn = QueryConnection.getConnection(sqlRequest.getProject());
        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)));
        }

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

            results.add(oneRow);
        }
    } finally {
        close(resultSet, stat, conn);
    }
    QueryContext queryContext = QueryContextFacade.current();
    StringBuilder cubeSb = new StringBuilder();
    StringBuilder logSb = new StringBuilder("Processed rows for each storageContext: ");
    boolean isPartialResult = false;

    if (OLAPContext.getThreadLocalContexts() != null) { // contexts can be null in case of 'explain plan for'
        for (OLAPContext ctx : OLAPContext.getThreadLocalContexts()) {
            String realizationName = "NULL";
            int realizationType = -1;
            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(" ");

                realizationName = ctx.realization.getName();
                realizationType = ctx.realization.getStorageType();
            }
            queryContext.setContextRealization(ctx.id, realizationName, realizationType);
        }
    }

    SQLResponse response = new SQLResponse(columnMetas, results, cubeSb.toString(), 0, false, null, isPartialResult);
    response.setTotalScanCount(queryContext.getScannedRows());

    return response;
}
 
Example 4
Source File: QueryService.java    From kylin-on-parquet-v2 with Apache License 2.0 4 votes vote down vote up
public void logQuery(final String queryId, 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());
            }

        }
    }

    if (realizationNames.isEmpty()) {
        if (!Strings.isNullOrEmpty(response.getCube())) {
            realizationNames.addAll(Lists.newArrayList(StringUtil.splitByComma(response.getCube())));
        }
    }

    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(queryId).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("Is Prepare: ").append(BackdoorToggles.getPrepareOnly()).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());
}
 
Example 5
Source File: QueryService.java    From kylin-on-parquet-v2 with Apache License 2.0 4 votes vote down vote up
private SQLResponse buildSqlResponse(String projectName, Boolean isPushDown, List<List<String>> results,
        List<SelectedColumnMeta> columnMetas, boolean isException, String exceptionMessage) {

    boolean isPartialResult = false;

    List<String> realizations = Lists.newLinkedList();
    StringBuilder cubeSb = new StringBuilder();
    StringBuilder logSb = new StringBuilder("Processed rows for each storageContext: ");
    QueryContext queryContext = QueryContextFacade.current();
    if (OLAPContext.getThreadLocalContexts() != null) { // contexts can be null in case of 'explain plan for'
        for (OLAPContext ctx : OLAPContext.getThreadLocalContexts()) {
            String realizationName = "NULL";
            int realizationType = -1;
            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(" ");

                realizationName = ctx.realization.getName();
                realizationType = ctx.realization.getStorageType();

                realizations.add(realizationName);
            }
            queryContext.setContextRealization(ctx.id, realizationName, realizationType);
        }
    }
    logger.info(logSb.toString());

    SQLResponse response = new SQLResponse(columnMetas, results, cubeSb.toString(), 0, isException,
            exceptionMessage, isPartialResult, isPushDown);
    response.setTotalScanCount(queryContext.getScannedRows());
    response.setTotalScanBytes(queryContext.getScannedBytes());
    response.setCubeSegmentStatisticsList(queryContext.getCubeSegmentStatisticsResultList());
    if (getConfig().isQueryCacheSignatureEnabled()) {
        response.setSignature(SQLResponseSignatureUtil.createSignature(getConfig(), response, projectName));
    }
    return response;
}
 
Example 6
Source File: QueryService.java    From kylin with Apache License 2.0 4 votes vote down vote up
/**
 * @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 = Lists.newArrayList();
    List<SelectedColumnMeta> columnMetas = Lists.newArrayList();

    try {
        conn = QueryConnection.getConnection(sqlRequest.getProject());
        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)));
        }

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

            results.add(oneRow);
        }
    } finally {
        close(resultSet, stat, conn);
    }
    QueryContext queryContext = QueryContextFacade.current();
    StringBuilder cubeSb = new StringBuilder();
    StringBuilder logSb = new StringBuilder("Processed rows for each storageContext: ");
    boolean isPartialResult = false;

    if (OLAPContext.getThreadLocalContexts() != null) { // contexts can be null in case of 'explain plan for'
        for (OLAPContext ctx : OLAPContext.getThreadLocalContexts()) {
            String realizationName = "NULL";
            int realizationType = -1;
            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(" ");

                realizationName = ctx.realization.getName();
                realizationType = ctx.realization.getStorageType();
            }
            queryContext.setContextRealization(ctx.id, realizationName, realizationType);
        }
    }

    SQLResponse response = new SQLResponse(columnMetas, results, cubeSb.toString(), 0, false, null, isPartialResult);
    response.setTotalScanCount(queryContext.getScannedRows());

    return response;
}
 
Example 7
Source File: QueryService.java    From kylin with Apache License 2.0 4 votes vote down vote up
public void logQuery(final String queryId, 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());
            }

        }
    }

    // if Realization Names is empty, get value from SQLResponse.
    if (realizationNames.isEmpty()) {
        if (!Strings.isNullOrEmpty(response.getCube())) {
            realizationNames.addAll(Lists.newArrayList(StringUtil.splitByComma(response.getCube())));
        }
    }

    // if Cuboid Ids is empty, get value from SQLResponse.
    if (cuboidIds.isEmpty()) {
        List<QueryContext.CubeSegmentStatisticsResult> cubeSegmentStatisticsList =
                response.getCubeSegmentStatisticsList();
        if (CollectionUtils.isNotEmpty(cubeSegmentStatisticsList)) {
            cubeSegmentStatisticsList.forEach(cubeSegmentStatResult -> {
                if (MapUtils.isNotEmpty(cubeSegmentStatResult.getCubeSegmentStatisticsMap())) {
                    cubeSegmentStatResult.getCubeSegmentStatisticsMap().values().forEach(cubeSegmentStatMap -> {
                        cubeSegmentStatMap.values().forEach(cubeSegmentStat -> {
                            cuboidIds.add(cubeSegmentStat.getTargetCuboidId());
                        });
                    });
                }
            });
        }
    }

    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(queryId).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("Is Prepare: ").append(BackdoorToggles.getPrepareOnly()).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());
}
 
Example 8
Source File: QueryService.java    From kylin with Apache License 2.0 4 votes vote down vote up
private SQLResponse buildSqlResponse(String projectName, Boolean isPushDown, List<List<String>> results,
        List<SelectedColumnMeta> columnMetas, boolean isException, String exceptionMessage) {

    boolean isPartialResult = false;

    List<String> realizations = Lists.newLinkedList();
    StringBuilder cubeSb = new StringBuilder();
    StringBuilder logSb = new StringBuilder("Processed rows for each storageContext: ");
    QueryContext queryContext = QueryContextFacade.current();
    if (OLAPContext.getThreadLocalContexts() != null) { // contexts can be null in case of 'explain plan for'
        for (OLAPContext ctx : OLAPContext.getThreadLocalContexts()) {
            String realizationName = "NULL";
            int realizationType = -1;
            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(" ");

                realizationName = ctx.realization.getName();
                realizationType = ctx.realization.getStorageType();

                realizations.add(realizationName);
            }
            queryContext.setContextRealization(ctx.id, realizationName, realizationType);
        }
    }
    logger.info(logSb.toString());

    SQLResponse response = new SQLResponse(columnMetas, results, cubeSb.toString(), 0, isException,
            exceptionMessage, isPartialResult, isPushDown);
    response.setTotalScanCount(queryContext.getScannedRows());
    response.setTotalScanBytes(queryContext.getScannedBytes());
    response.setCubeSegmentStatisticsList(queryContext.getCubeSegmentStatisticsResultList());
    if (getConfig().isQueryCacheSignatureEnabled()) {
        response.setSignature(SQLResponseSignatureUtil.createSignature(getConfig(), response, projectName));
    }
    return response;
}
 
Example 9
Source File: QueryService.java    From Kylin with Apache License 2.0 4 votes vote down vote up
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());
}
 
Example 10
Source File: QueryService.java    From Kylin with Apache License 2.0 4 votes vote down vote up
/**
 * @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;
}