This is an automated email from the ASF dual-hosted git repository.

shaofengshi pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/kylin.git


The following commit(s) were added to refs/heads/master by this push:
     new b8d55d0  KYLIN-2971 Fix the wrong "Realization Names" and missing 
"Cuboid Ids" in logQuery when hit cache
b8d55d0 is described below

commit b8d55d08301779885dd6418651c979ccaaaf6165
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;
---
 .../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 3146d76..4f19e50 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;
@@ -325,12 +327,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();
@@ -411,6 +431,9 @@ public class QueryService extends BasicService {
         queryContext.setProject(sqlRequest.getProject());
 
         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();
@@ -660,8 +683,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();

Reply via email to