You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@kylin.apache.org by li...@apache.org on 2016/12/08 05:53:29 UTC

[04/19] kylin git commit: KYLIN-1875 Support measure on non-root-fact-table

KYLIN-1875 Support measure on non-root-fact-table


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

Branch: refs/heads/master-cdh5.7
Commit: 79e48011bd3f4696a916f0bfee244ec28355f3b3
Parents: 64d9b8b
Author: Li Yang <li...@apache.org>
Authored: Thu Dec 1 18:59:08 2016 +0800
Committer: Li Yang <li...@apache.org>
Committed: Wed Dec 7 17:53:38 2016 +0800

----------------------------------------------------------------------
 .../kylin/metadata/project/ProjectL2Cache.java  | 26 +++++++++++++-------
 .../template/cube_desc/kylin_sales_cube.json    | 18 +++++++-------
 .../kylin/query/relnode/OLAPTableScan.java      |  4 +++
 3 files changed, 30 insertions(+), 18 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/kylin/blob/79e48011/core-metadata/src/main/java/org/apache/kylin/metadata/project/ProjectL2Cache.java
----------------------------------------------------------------------
diff --git a/core-metadata/src/main/java/org/apache/kylin/metadata/project/ProjectL2Cache.java b/core-metadata/src/main/java/org/apache/kylin/metadata/project/ProjectL2Cache.java
index 82c0de3..14d7843 100644
--- a/core-metadata/src/main/java/org/apache/kylin/metadata/project/ProjectL2Cache.java
+++ b/core-metadata/src/main/java/org/apache/kylin/metadata/project/ProjectL2Cache.java
@@ -25,6 +25,7 @@ import java.util.Set;
 
 import org.apache.kylin.metadata.MetadataManager;
 import org.apache.kylin.metadata.model.ColumnDesc;
+import org.apache.kylin.metadata.model.DataModelDesc;
 import org.apache.kylin.metadata.model.ExternalFilterDesc;
 import org.apache.kylin.metadata.model.FunctionDesc;
 import org.apache.kylin.metadata.model.MeasureDesc;
@@ -126,17 +127,17 @@ class ProjectL2Cache {
             return Collections.unmodifiableSet(tableCache.realizations);
     }
 
-    public List<MeasureDesc> listEffectiveRewriteMeasures(String project, String factTable, boolean onlyRewriteMeasure) {
-        Set<IRealization> realizations = getRealizationsByTable(project, factTable);
+    public List<MeasureDesc> listEffectiveRewriteMeasures(String project, String table, boolean onlyRewriteMeasure) {
+        Set<IRealization> realizations = getRealizationsByTable(project, table);
         List<MeasureDesc> result = Lists.newArrayList();
         for (IRealization r : realizations) {
-            if (r.getModel().isFactTable(factTable) && r.isReady()) {
-                for (MeasureDesc m : r.getMeasures()) {
-                    FunctionDesc func = m.getFunction();
-                    if (onlyRewriteMeasure) {
-                        if (func.needRewrite())
-                            result.add(m);
-                    } else {
+            if (!r.isReady())
+                continue;
+
+            for (MeasureDesc m : r.getMeasures()) {
+                FunctionDesc func = m.getFunction();
+                if (belongToTable(func, table, r.getModel())) {
+                    if (!onlyRewriteMeasure || func.needRewrite()) {
                         result.add(m);
                     }
                 }
@@ -145,6 +146,13 @@ class ProjectL2Cache {
         return result;
     }
 
+    private boolean belongToTable(FunctionDesc func, String table, DataModelDesc model) {
+        // measure belong to the first column parameter's table
+        List<TblColRef> cols = func.getParameter().getColRefs();
+        String belongTo = cols.isEmpty() ? model.getRootFactTable().getTableIdentity() : cols.get(0).getTable();
+        return belongTo.equals(table);
+    }
+
     // ============================================================================
     // build the cache
     // ----------------------------------------------------------------------------

http://git-wip-us.apache.org/repos/asf/kylin/blob/79e48011/examples/sample_cube/template/cube_desc/kylin_sales_cube.json
----------------------------------------------------------------------
diff --git a/examples/sample_cube/template/cube_desc/kylin_sales_cube.json b/examples/sample_cube/template/cube_desc/kylin_sales_cube.json
index 48eef46..2a27305 100644
--- a/examples/sample_cube/template/cube_desc/kylin_sales_cube.json
+++ b/examples/sample_cube/template/cube_desc/kylin_sales_cube.json
@@ -103,26 +103,26 @@
       "returntype" : "decimal(19,4)"
     }
   }, {
-    "name" : "GMV_MIN",
+    "name" : "BUYER_LEVEL_SUM",
     "function" : {
-      "expression" : "MIN",
+      "expression" : "SUM",
       "parameter" : {
         "type" : "column",
-        "value" : "PRICE",
+        "value" : "BUYER_ACCOUNT.ACCOUNT_BUYER_LEVEL",
         "next_parameter" : null
       },
-      "returntype" : "decimal(19,4)"
+      "returntype" : "bigint"
     }
   }, {
-    "name" : "GMV_MAX",
+    "name" : "SELLER_LEVEL_SUM",
     "function" : {
-      "expression" : "MAX",
+      "expression" : "SUM",
       "parameter" : {
         "type" : "column",
-        "value" : "PRICE",
+        "value" : "SELLER_ACCOUNT.ACCOUNT_SELLER_LEVEL",
         "next_parameter" : null
       },
-      "returntype" : "decimal(19,4)"
+      "returntype" : "bigint"
     }
   }, {
     "name" : "TRANS_CNT",
@@ -224,7 +224,7 @@
       "name" : "F1",
       "columns" : [ {
         "qualifier" : "M",
-        "measure_refs" : [ "GMV_SUM", "GMV_MIN", "GMV_MAX", "TRANS_CNT" ]
+        "measure_refs" : [ "GMV_SUM", "BUYER_LEVEL_SUM", "SELLER_LEVEL_SUM", "TRANS_CNT" ]
       } ]
     }, {
       "name" : "F2",

http://git-wip-us.apache.org/repos/asf/kylin/blob/79e48011/query/src/main/java/org/apache/kylin/query/relnode/OLAPTableScan.java
----------------------------------------------------------------------
diff --git a/query/src/main/java/org/apache/kylin/query/relnode/OLAPTableScan.java b/query/src/main/java/org/apache/kylin/query/relnode/OLAPTableScan.java
index 14758c9..b157f34 100644
--- a/query/src/main/java/org/apache/kylin/query/relnode/OLAPTableScan.java
+++ b/query/src/main/java/org/apache/kylin/query/relnode/OLAPTableScan.java
@@ -236,6 +236,10 @@ public class OLAPTableScan extends TableScan implements OLAPRel, EnumerableRel {
             TblColRef colRef = TblColRef.columnForUnknownModel(tableRef, sourceColumn);
             columns.add(colRef);
         }
+        
+        if (columns.size() != rowType.getFieldCount()) {
+            throw new IllegalStateException("RowType=" + rowType.getFieldCount() + ", ColumnRowType=" + columns.size());
+        }
         return new ColumnRowType(columns);
     }