You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@kylin.apache.org by sh...@apache.org on 2016/04/27 08:33:38 UTC

kylin git commit: KYLIN-1622 fix the validation check for topN query

Repository: kylin
Updated Branches:
  refs/heads/master dd855a512 -> 34ac81fb0


KYLIN-1622 fix the validation check for topN query

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

Branch: refs/heads/master
Commit: 34ac81fb00e0056877cfe6bf5220d1ea79bfe70e
Parents: dd855a5
Author: shaofengshi <sh...@apache.org>
Authored: Wed Apr 27 14:33:12 2016 +0800
Committer: shaofengshi <sh...@apache.org>
Committed: Wed Apr 27 14:33:12 2016 +0800

----------------------------------------------------------------------
 .../apache/kylin/measure/topn/TopNMeasureType.java  | 12 +++++++-----
 .../metadata/cube_desc/kylin_sales_cube_desc.json   | 16 ++++++++++++++++
 2 files changed, 23 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/kylin/blob/34ac81fb/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 507a2b0..093afa0 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
@@ -234,19 +234,21 @@ public class TopNMeasureType extends MeasureType<TopNCounter<ByteArray>> {
         if (sqlDigest.groupbyColumns.contains(topnLiteralCol) == false)
             return;
 
-        if (sqlDigest.aggregations.size() != 1) {
+        if (sqlDigest.aggregations.size() > 1) {
             throw new IllegalStateException("When query with topN, only one metrics is allowed.");
         }
 
-        FunctionDesc origFunc = sqlDigest.aggregations.iterator().next();
-        if (origFunc.isSum() == false) {
-            throw new IllegalStateException("When query with topN, only SUM function is allowed.");
+        if (sqlDigest.aggregations.size() > 0) {
+            FunctionDesc origFunc = sqlDigest.aggregations.iterator().next();
+            if (origFunc.isSum() == false) {
+                throw new IllegalStateException("When query with topN, only SUM function is allowed.");
+            }
+            logger.info("Rewrite function " + origFunc + " to " + topnFunc);
         }
 
         sqlDigest.aggregations = Lists.newArrayList(topnFunc);
         sqlDigest.groupbyColumns.remove(topnLiteralCol);
         sqlDigest.metricColumns.add(topnLiteralCol);
-        logger.info("Rewrite function " + origFunc + " to " + topnFunc);
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/kylin/blob/34ac81fb/examples/sample_cube/metadata/cube_desc/kylin_sales_cube_desc.json
----------------------------------------------------------------------
diff --git a/examples/sample_cube/metadata/cube_desc/kylin_sales_cube_desc.json b/examples/sample_cube/metadata/cube_desc/kylin_sales_cube_desc.json
index c7d1a13..be1b7a9 100644
--- a/examples/sample_cube/metadata/cube_desc/kylin_sales_cube_desc.json
+++ b/examples/sample_cube/metadata/cube_desc/kylin_sales_cube_desc.json
@@ -106,6 +106,22 @@
       "returntype" : "hllc(10)"
     },
     "dependent_measure_ref" : null
+  }, {
+    "name": "TOP_SELLER",
+    "function": {
+      "expression": "TOP_N",
+      "parameter": {
+        "type": "column",
+        "value": "PRICE",
+        "next_parameter": {
+          "type": "column",
+          "value": "SELLER_ID",
+          "next_parameter": null
+        }
+      },
+      "returntype": "topn(100)"
+    },
+    "dependent_measure_ref": null
   } ],
   "rowkey" : {
     "rowkey_columns" : [ {