kylin-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From shaofeng...@apache.org
Subject [02/15] kylin git commit: KYLIN-2340 fix sub-query that creates two Filter nodes
Date Tue, 03 Jan 2017 06:42:38 GMT
KYLIN-2340 fix sub-query that creates two Filter nodes


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

Branch: refs/heads/sparkcubing-rebase
Commit: 6e4637c98814d8a3e8164dc366950bf8eb9ca716
Parents: 32d7244
Author: Li Yang <liyang@apache.org>
Authored: Fri Dec 30 15:17:44 2016 +0800
Committer: Li Yang <liyang@apache.org>
Committed: Fri Dec 30 15:17:44 2016 +0800

----------------------------------------------------------------------
 .../kylin/metadata/filter/TupleFilter.java      | 23 +++++++++++++++++++
 .../resources/query/sql_subquery/query14.sql    | 22 ++++++++++++++++++
 .../kylin/query/relnode/OLAPFilterRel.java      |  5 ++--
 .../relnode/OLAPToEnumerableConverter.java      | 24 +-------------------
 4 files changed, 49 insertions(+), 25 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/kylin/blob/6e4637c9/core-metadata/src/main/java/org/apache/kylin/metadata/filter/TupleFilter.java
----------------------------------------------------------------------
diff --git a/core-metadata/src/main/java/org/apache/kylin/metadata/filter/TupleFilter.java
b/core-metadata/src/main/java/org/apache/kylin/metadata/filter/TupleFilter.java
index 31de50b..f9d83f5 100644
--- a/core-metadata/src/main/java/org/apache/kylin/metadata/filter/TupleFilter.java
+++ b/core-metadata/src/main/java/org/apache/kylin/metadata/filter/TupleFilter.java
@@ -25,6 +25,7 @@ import java.util.List;
 import java.util.Map;
 import java.util.Set;
 
+import org.apache.kylin.metadata.filter.TupleFilter.FilterOperatorEnum;
 import org.apache.kylin.metadata.model.TblColRef;
 import org.apache.kylin.metadata.tuple.IEvaluatableTuple;
 import org.slf4j.Logger;
@@ -241,4 +242,26 @@ public abstract class TupleFilter {
         }
     }
 
+    public static TupleFilter and(TupleFilter f1, TupleFilter f2) {
+        if (f1 == null)
+            return f2;
+        if (f2 == null)
+            return f1;
+
+        if (f1.getOperator() == FilterOperatorEnum.AND) {
+            f1.addChild(f2);
+            return f1;
+        }
+
+        if (f2.getOperator() == FilterOperatorEnum.AND) {
+            f2.addChild(f1);
+            return f2;
+        }
+
+        LogicalTupleFilter and = new LogicalTupleFilter(FilterOperatorEnum.AND);
+        and.addChild(f1);
+        and.addChild(f2);
+        return and;
+    }
+
 }

http://git-wip-us.apache.org/repos/asf/kylin/blob/6e4637c9/kylin-it/src/test/resources/query/sql_subquery/query14.sql
----------------------------------------------------------------------
diff --git a/kylin-it/src/test/resources/query/sql_subquery/query14.sql b/kylin-it/src/test/resources/query/sql_subquery/query14.sql
new file mode 100644
index 0000000..b3b3b7e
--- /dev/null
+++ b/kylin-it/src/test/resources/query/sql_subquery/query14.sql
@@ -0,0 +1,22 @@
+select
+    lstg_format_name,
+    sum(price) as gvm
+from
+    (
+        select
+            cal_dt,
+            lstg_format_name,
+            price
+        from test_kylin_fact
+            inner JOIN test_category_groupings
+            ON test_kylin_fact.leaf_categ_id = test_category_groupings.leaf_categ_id AND
test_kylin_fact.lstg_site_id = test_category_groupings.site_id
+            inner JOIN edw.test_sites as test_sites
+            ON test_kylin_fact.lstg_site_id = test_sites.site_id
+        where
+            lstg_site_id = 0
+            and cal_dt > '2013-05-13'
+    ) f
+where
+    lstg_format_name ='Auction'
+group by
+    lstg_format_name
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/kylin/blob/6e4637c9/query/src/main/java/org/apache/kylin/query/relnode/OLAPFilterRel.java
----------------------------------------------------------------------
diff --git a/query/src/main/java/org/apache/kylin/query/relnode/OLAPFilterRel.java b/query/src/main/java/org/apache/kylin/query/relnode/OLAPFilterRel.java
index 151131e..d3d78a0 100755
--- a/query/src/main/java/org/apache/kylin/query/relnode/OLAPFilterRel.java
+++ b/query/src/main/java/org/apache/kylin/query/relnode/OLAPFilterRel.java
@@ -322,9 +322,10 @@ public class OLAPFilterRel extends Filter implements OLAPRel {
         }
 
         TupleFilterVisitor visitor = new TupleFilterVisitor(this.columnRowType, context);
-        context.filter = this.condition.accept(visitor);
+        TupleFilter filter = this.condition.accept(visitor);
 
-        context.filterColumns = visitor.columnsInFilter;
+        context.filter = TupleFilter.and(context.filter, filter);
+        context.filterColumns.addAll(visitor.columnsInFilter);
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/kylin/blob/6e4637c9/query/src/main/java/org/apache/kylin/query/relnode/OLAPToEnumerableConverter.java
----------------------------------------------------------------------
diff --git a/query/src/main/java/org/apache/kylin/query/relnode/OLAPToEnumerableConverter.java
b/query/src/main/java/org/apache/kylin/query/relnode/OLAPToEnumerableConverter.java
index 31cfc36..405a24e 100644
--- a/query/src/main/java/org/apache/kylin/query/relnode/OLAPToEnumerableConverter.java
+++ b/query/src/main/java/org/apache/kylin/query/relnode/OLAPToEnumerableConverter.java
@@ -135,33 +135,11 @@ public class OLAPToEnumerableConverter extends ConverterImpl implements
Enumerab
             if (null != tupleFilter) {
                 context.filterColumns.addAll(collectColumns(tupleFilter));
                 context.allColumns.addAll(collectColumns(tupleFilter));
-                context.filter = and(context.filter, tupleFilter);
+                context.filter = TupleFilter.and(context.filter, tupleFilter);
             }
         }
     }
 
-    private TupleFilter and(TupleFilter f1, TupleFilter f2) {
-        if (f1 == null)
-            return f2;
-        if (f2 == null)
-            return f1;
-
-        if (f1.getOperator() == FilterOperatorEnum.AND) {
-            f1.addChild(f2);
-            return f1;
-        }
-
-        if (f2.getOperator() == FilterOperatorEnum.AND) {
-            f2.addChild(f1);
-            return f2;
-        }
-
-        LogicalTupleFilter and = new LogicalTupleFilter(FilterOperatorEnum.AND);
-        and.addChild(f1);
-        and.addChild(f2);
-        return and;
-    }
-
     private Set<TblColRef> collectColumns(TupleFilter filter) {
         Set<TblColRef> ret = Sets.newHashSet();
         collectColumnsRecursively(filter, ret);


Mime
View raw message