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 2017/02/22 02:31:38 UTC

[04/13] kylin git commit: KYLIN-2456 fix select * from .. join ..

KYLIN-2456 fix select * from .. join ..


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

Branch: refs/heads/master-hbase0.98
Commit: f2feae22a6cb5940213d040b96181b89bc51c46c
Parents: e77a848
Author: Li Yang <li...@apache.org>
Authored: Tue Feb 21 15:10:58 2017 +0800
Committer: Li Yang <li...@apache.org>
Committed: Tue Feb 21 15:10:58 2017 +0800

----------------------------------------------------------------------
 .../calcite/sql2rel/SqlToRelConverter.java      | 56 +++++++++++---------
 .../apache/kylin/query/ITKylinQueryTest.java    |  1 +
 2 files changed, 33 insertions(+), 24 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/kylin/blob/f2feae22/atopcalcite/src/main/java/org/apache/calcite/sql2rel/SqlToRelConverter.java
----------------------------------------------------------------------
diff --git a/atopcalcite/src/main/java/org/apache/calcite/sql2rel/SqlToRelConverter.java b/atopcalcite/src/main/java/org/apache/calcite/sql2rel/SqlToRelConverter.java
index cc9c9a1..a7be94f 100644
--- a/atopcalcite/src/main/java/org/apache/calcite/sql2rel/SqlToRelConverter.java
+++ b/atopcalcite/src/main/java/org/apache/calcite/sql2rel/SqlToRelConverter.java
@@ -16,6 +16,25 @@
  */
 package org.apache.calcite.sql2rel;
 
+import static org.apache.calcite.sql.SqlUtil.stripAs;
+import static org.apache.calcite.util.Static.RESOURCE;
+
+import java.lang.reflect.Type;
+import java.math.BigDecimal;
+import java.util.AbstractList;
+import java.util.ArrayDeque;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Deque;
+import java.util.EnumSet;
+import java.util.HashMap;
+import java.util.LinkedHashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.TreeSet;
+
 import org.apache.calcite.avatica.util.Spaces;
 import org.apache.calcite.linq4j.Ord;
 import org.apache.calcite.plan.Convention;
@@ -159,6 +178,7 @@ import org.apache.calcite.util.NumberUtil;
 import org.apache.calcite.util.Pair;
 import org.apache.calcite.util.Util;
 import org.apache.calcite.util.trace.CalciteTrace;
+import org.slf4j.Logger;
 
 import com.google.common.base.Function;
 import com.google.common.base.Preconditions;
@@ -170,27 +190,6 @@ import com.google.common.collect.Iterables;
 import com.google.common.collect.Lists;
 import com.google.common.collect.Maps;
 
-import org.slf4j.Logger;
-
-import java.lang.reflect.Type;
-import java.math.BigDecimal;
-import java.util.AbstractList;
-import java.util.ArrayDeque;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.Deque;
-import java.util.EnumSet;
-import java.util.HashMap;
-import java.util.LinkedHashSet;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-import java.util.TreeSet;
-
-import static org.apache.calcite.sql.SqlUtil.stripAs;
-import static org.apache.calcite.util.Static.RESOURCE;
-
 /*
  * The code has synced with calcite. Hope one day, we could remove the hardcode override point.
  * OVERRIDE POINT:
@@ -602,7 +601,7 @@ public class SqlToRelConverter {
          *   LogicalSort (optional)
          *    |- LogicalProject
          *        |- LogicalFilter (optional)
-         *            |- OLAPTableScan
+         *            |- OLAPTableScan or LogicalJoin
          */
         LogicalProject rootPrj = null;
         LogicalSort rootSort = null;
@@ -617,8 +616,8 @@ public class SqlToRelConverter {
 
         RelNode input = rootPrj.getInput();
         if (!(//
-                input.getClass().getSimpleName().equals("OLAPTableScan")//
-                || (input.getClass().getSimpleName().equals("LogicalFilter") && input.getInput(0).getClass().getSimpleName().equals("OLAPTableScan"))//
+                isAmong(input, "OLAPTableScan", "LogicalJoin")//
+                || (isAmong(input, "LogicalFilter") && isAmong(input.getInput(0), "OLAPTableScan", "LogicalJoin"))//
              ))
             return root;
 
@@ -654,6 +653,15 @@ public class SqlToRelConverter {
         return root;
     }
 
+    private boolean isAmong(RelNode rel, String... names) {
+        String simpleName = rel.getClass().getSimpleName();
+        for (String n : names) {
+            if (simpleName.equals(n))
+                return true;
+        }
+        return false;
+    }
+
     private static boolean isStream(SqlNode query) {
         return query instanceof SqlSelect
                 && ((SqlSelect) query).isKeywordPresent(SqlSelectKeyword.STREAM);

http://git-wip-us.apache.org/repos/asf/kylin/blob/f2feae22/kylin-it/src/test/java/org/apache/kylin/query/ITKylinQueryTest.java
----------------------------------------------------------------------
diff --git a/kylin-it/src/test/java/org/apache/kylin/query/ITKylinQueryTest.java b/kylin-it/src/test/java/org/apache/kylin/query/ITKylinQueryTest.java
index 4590e60..d30371a 100644
--- a/kylin-it/src/test/java/org/apache/kylin/query/ITKylinQueryTest.java
+++ b/kylin-it/src/test/java/org/apache/kylin/query/ITKylinQueryTest.java
@@ -396,6 +396,7 @@ public class ITKylinQueryTest extends KylinTestBase {
     public void testSelectStarColumnCount() throws Exception {
         execAndCompColumnCount("select * from test_kylin_fact limit 10", 11);
         execAndCompColumnCount("select * from test_kylin_fact", 11);
+        execAndCompColumnCount("select * from     test_kylin_fact left join edw.test_cal_dt on test_kylin_fact.cal_dt = edw.test_cal_dt.CAL_DT    limit 10", 13);
     }
 
     @Test