You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@kylin.apache.org by ni...@apache.org on 2019/04/11 10:30:19 UTC

[kylin] branch master updated: KYLIN-3946 Fix count column compatibility

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

nic 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 7deb204  KYLIN-3946 Fix count column compatibility
7deb204 is described below

commit 7deb2048a8477fdd27735fd128f28968bea7fb8e
Author: chao long <wa...@qq.com>
AuthorDate: Thu Apr 11 11:24:00 2019 +0800

    KYLIN-3946 Fix count column compatibility
---
 .../org/apache/kylin/cube/CubeCapabilityChecker.java |  7 +++++++
 .../apache/kylin/query/relnode/OLAPAggregateRel.java | 20 +++++++++++++++++++-
 2 files changed, 26 insertions(+), 1 deletion(-)

diff --git a/core-cube/src/main/java/org/apache/kylin/cube/CubeCapabilityChecker.java b/core-cube/src/main/java/org/apache/kylin/cube/CubeCapabilityChecker.java
index ea6a862..438af8d 100644
--- a/core-cube/src/main/java/org/apache/kylin/cube/CubeCapabilityChecker.java
+++ b/core-cube/src/main/java/org/apache/kylin/cube/CubeCapabilityChecker.java
@@ -224,6 +224,13 @@ public class CubeCapabilityChecker {
         while (it.hasNext()) {
             FunctionDesc functionDesc = it.next();
 
+            // let calcite handle count
+            if (functionDesc.isCount()) {
+                logger.warn("No count measure found for column {}, will use count(1) to replace it, please note that it will count all value(include null value)", functionDesc.getParameter() == null ? "" : functionDesc.getParameter().getColRef().getName());
+                it.remove();
+                continue;
+            }
+
             // calcite can do aggregation from columns on-the-fly
             ParameterDesc parameterDesc = functionDesc.getParameter();
             if (parameterDesc == null) {
diff --git a/query/src/main/java/org/apache/kylin/query/relnode/OLAPAggregateRel.java b/query/src/main/java/org/apache/kylin/query/relnode/OLAPAggregateRel.java
index ccbd726..a6a43b9 100755
--- a/query/src/main/java/org/apache/kylin/query/relnode/OLAPAggregateRel.java
+++ b/query/src/main/java/org/apache/kylin/query/relnode/OLAPAggregateRel.java
@@ -497,12 +497,30 @@ public class OLAPAggregateRel extends Aggregate implements OLAPRel {
 
     FunctionDesc findInMeasures(FunctionDesc aggFunc, List<MeasureDesc> measures) {
         for (MeasureDesc m : measures) {
-            if (aggFunc.equals(m.getFunction()))
+            if (aggFunc.equals(m.getFunction())) {
                 return m.getFunction();
+            }
+        }
+
+        // no count(col) measure found, use count(1) to replace it.
+        if (aggFunc.isCount()) {
+            FunctionDesc func = findCountConstantFunc(measures);
+            if (func != null)
+                return func;
         }
+
         return aggFunc;
     }
 
+    private FunctionDesc findCountConstantFunc(List<MeasureDesc> measures) {
+        for (MeasureDesc measure : measures) {
+            if (measure.getFunction().isCountConstant()) {
+                return measure.getFunction();
+            }
+        }
+        return null;
+    }
+
     void buildRewriteFieldsAndMetricsColumns() {
         ColumnRowType inputColumnRowType = ((OLAPRel) getInput()).getColumnRowType();
         RelDataTypeFactory typeFactory = getCluster().getTypeFactory();