Repository: kylin
Updated Branches:
  refs/heads/master ef0c9e5c6 -> 3924672be


KYLIN-2098 TopN support query UHC column without sorting by sum value

Project: http://git-wip-us.apache.org/repos/asf/kylin/repo
Commit: http://git-wip-us.apache.org/repos/asf/kylin/commit/3924672b
Tree: http://git-wip-us.apache.org/repos/asf/kylin/tree/3924672b
Diff: http://git-wip-us.apache.org/repos/asf/kylin/diff/3924672b

Branch: refs/heads/master
Commit: 3924672be05305a9374b4ba757500d89af8e125c
Parents: ef0c9e5
Author: shaofengshi <shaofeng...@apache.org>
Authored: Mon Oct 17 13:51:05 2016 +0800
Committer: shaofengshi <shaofeng...@apache.org>
Committed: Mon Oct 17 13:51:53 2016 +0800

----------------------------------------------------------------------
 .../kylin/measure/topn/TopNMeasureType.java     | 55 +++++++++++++-------
 1 file changed, 35 insertions(+), 20 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/kylin/blob/3924672b/core-metadata/src/main/java/org/apache/kylin/measure/topn/TopNMeasureType.java
----------------------------------------------------------------------
diff --git 
a/core-metadata/src/main/java/org/apache/kylin/measure/topn/TopNMeasureType.java
 
b/core-metadata/src/main/java/org/apache/kylin/measure/topn/TopNMeasureType.java
index b67c374..fcf6d5e 100644
--- 
a/core-metadata/src/main/java/org/apache/kylin/measure/topn/TopNMeasureType.java
+++ 
b/core-metadata/src/main/java/org/apache/kylin/measure/topn/TopNMeasureType.java
@@ -231,34 +231,49 @@ public class TopNMeasureType extends 
MeasureType<TopNCounter<ByteArray>> {
         // TopN measure can (and only can) provide one numeric measure and one 
literal dimension
         // e.g. select seller, sum(gmv) from ... group by seller order by 2 
desc limit 100
 
-        // check digest requires only one measure
-        if (digest.aggregations.size() != 1)
-            return null;
-
-        // the measure function must be SUM
-        FunctionDesc onlyFunction = digest.aggregations.iterator().next();
-        if (isTopNCompatibleSum(topN.getFunction(), onlyFunction) == false)
-            return null;
-
         List<TblColRef> literalCol = getTopNLiteralColumn(topN.getFunction());
+        for (TblColRef colRef : literalCol) {
+            if (digest.filterColumns.contains(colRef) == true) {
+                // doesn't allow filtering by topn literal column
+                return null;
+            }
+        }
+
         if (unmatchedDimensions.containsAll(literalCol) == false)
             return null;
         if (digest.groupbyColumns.containsAll(literalCol) == false)
             return null;
 
-        for (TblColRef colRef : literalCol) {
-            if (digest.filterColumns.contains(colRef) == true) {
+        // check digest requires only one measure
+        if (digest.aggregations.size() == 1) {
+
+            // the measure function must be SUM
+            FunctionDesc onlyFunction = digest.aggregations.iterator().next();
+            if (isTopNCompatibleSum(topN.getFunction(), onlyFunction) == false)
                 return null;
-            }
+
+            unmatchedDimensions.removeAll(literalCol);
+            unmatchedAggregations.remove(onlyFunction);
+            return new CapabilityInfluence() {
+                @Override
+                public double suggestCostMultiplier() {
+                    return 0.3; // make sure TopN get ahead of other matched 
realizations
+                }
+            };
         }
-        unmatchedDimensions.removeAll(literalCol);
-        unmatchedAggregations.remove(onlyFunction);
-        return new CapabilityInfluence() {
-            @Override
-            public double suggestCostMultiplier() {
-                return 0.3; // make sure TopN get ahead of other matched 
realizations
-            }
-        };
+
+        if (digest.aggregations.size() == 0 ) {
+            // directly query the UHC column without sorting
+            unmatchedDimensions.removeAll(literalCol);
+            return new CapabilityInfluence() {
+                @Override
+                public double suggestCostMultiplier() {
+                    return 2.0; // topn can answer but with a higher cost
+                }
+            };
+        }
+
+        return null;
     }
 
     private boolean isTopNCompatibleSum(FunctionDesc topN, FunctionDesc sum) {

Reply via email to