This is an automated email from the ASF dual-hosted git repository. xxyu pushed a commit to branch kylin-on-parquet-v2 in repository https://gitbox.apache.org/repos/asf/kylin.git
commit ff338de3d3fcd30508b8973bc740d0daf5da597d Author: Zhichao Zhang <441586...@qq.com> AuthorDate: Tue May 19 23:27:52 2020 +0800 KYLIN-2971 Fix the wrong "Realization Names" and missing "Cuboid Ids" in logQuery when hit cache Problems: 1. The value of "Realization Names" in logQuery is wrong when query two different sqls within the same thread and second sql hits cache: Example: 1). query Q1 hit project P1 and cube C1; 2). query Q2 hit project P2 and cube C2 in the same thread with Q1; 3). Q1 comes again and hits cache, it will show project P1 and cube C2. However, it should be cube C1. 2. Missing "Cuboid Ids" in logQuery when hit cache in a new thread which does not have OLAPContext; Solutions: 1. Call 'OLAPContext.clearThreadLocalContexts()' before a query starts; 2. Get "Cuboid Ids" from SQLResponse when "OLAPContext.getThreadLocalContexts()" is null; (cherry picked from commit b8d55d08301779885dd6418651c979ccaaaf6165) --- .../apache/kylin/rest/service/QueryService.java | 25 ++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/server-base/src/main/java/org/apache/kylin/rest/service/QueryService.java b/server-base/src/main/java/org/apache/kylin/rest/service/QueryService.java index b6eb54f..ee79c99 100644 --- a/server-base/src/main/java/org/apache/kylin/rest/service/QueryService.java +++ b/server-base/src/main/java/org/apache/kylin/rest/service/QueryService.java @@ -55,6 +55,8 @@ import org.apache.calcite.prepare.CalcitePrepareImpl; import org.apache.calcite.prepare.OnlyPrepareEarlyAbortException; import org.apache.calcite.rel.type.RelDataTypeField; import org.apache.calcite.sql.type.BasicSqlType; +import org.apache.commons.collections.CollectionUtils; +import org.apache.commons.collections.MapUtils; import org.apache.commons.lang.StringUtils; import org.apache.commons.lang3.exception.ExceptionUtils; import org.apache.commons.pool2.BaseKeyedPooledObjectFactory; @@ -324,12 +326,30 @@ public class QueryService extends BasicService { } } + // 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(); @@ -410,6 +430,9 @@ public class QueryService extends BasicService { final QueryContext queryContext = QueryContextFacade.current(); try (SetThreadName ignored = new SetThreadName("Query %s", queryContext.getQueryId())) { + // force clear the query context before a new query + OLAPContext.clearThreadLocalContexts(); + SQLResponse sqlResponse = null; String sql = sqlRequest.getSql(); String project = sqlRequest.getProject(); @@ -663,8 +686,6 @@ public class QueryService extends BasicService { parameters.put(OLAPContext.PRM_USER_AUTHEN_INFO, userInfo); parameters.put(OLAPContext.PRM_ACCEPT_PARTIAL_RESULT, String.valueOf(sqlRequest.isAcceptPartial())); OLAPContext.setParameters(parameters); - // force clear the query context before a new query - OLAPContext.clearThreadLocalContexts(); // special case for prepare query. List<List<String>> results = Lists.newArrayList();