[ 
https://issues.apache.org/jira/browse/KYLIN-2200?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16661794#comment-16661794
 ] 

ASF GitHub Bot commented on KYLIN-2200:
---------------------------------------

shaofengshi closed pull request #307: KYLIN-2200 Verify CompileException on 
UNION ALL query when result onl…
URL: https://github.com/apache/kylin/pull/307
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

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 59cb4d5048..c6d1f62066 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
@@ -244,6 +244,11 @@ public void testUnionQuery() throws Exception {
         execAndCompQuery(getQueryFolderPrefix() + 
"src/test/resources/query/sql_union", null, true);
     }
 
+    @Test
+    public void testUnionallQuery() throws Exception {
+        execAndCompQuery(getQueryFolderPrefix() + 
"src/test/resources/query/sql_unionall", null, true);
+    }
+
     @Test
     public void testTimeStampAdd() throws Exception {
         execAndCompQuery(getQueryFolderPrefix() + 
"src/test/resources/query/sql_timestamp", null, true);
diff --git a/kylin-it/src/test/resources/query/sql_unionall/query01.sql 
b/kylin-it/src/test/resources/query/sql_unionall/query01.sql
new file mode 100644
index 0000000000..428981153d
--- /dev/null
+++ b/kylin-it/src/test/resources/query/sql_unionall/query01.sql
@@ -0,0 +1,7 @@
+-- unionall
+select count(ORDER_ID) as ORDER_ID
+from TEST_KYLIN_FACT as TEST_A
+where ORDER_ID <> 1
+union all
+select count(ORDER_ID) as ORDER_ID
+from TEST_KYLIN_FACT as TEST_B
diff --git a/kylin-it/src/test/resources/query/sql_unionall/query02.sql 
b/kylin-it/src/test/resources/query/sql_unionall/query02.sql
new file mode 100644
index 0000000000..882828529b
--- /dev/null
+++ b/kylin-it/src/test/resources/query/sql_unionall/query02.sql
@@ -0,0 +1,8 @@
+-- unionall
+select count(*) as count_a
+from TEST_KYLIN_FACT as TEST_A
+where lstg_format_name='FP-GTC'
+union all
+select count(*) as count_a
+from TEST_KYLIN_FACT as TEST_A
+where lstg_format_name='FP-GTC'
\ No newline at end of file
diff --git a/kylin-it/src/test/resources/query/sql_unionall/query03.sql 
b/kylin-it/src/test/resources/query/sql_unionall/query03.sql
new file mode 100644
index 0000000000..b1366f15b2
--- /dev/null
+++ b/kylin-it/src/test/resources/query/sql_unionall/query03.sql
@@ -0,0 +1,10 @@
+-- unionall subquery under join
+select count(*) as cnt
+FROM TEST_KYLIN_FACT as TEST_A
+join (
+    select * from TEST_KYLIN_FACT where CAL_DT < DATE '2012-02-01'
+    union all
+    select * from TEST_KYLIN_FACT where CAL_DT > DATE '2013-12-31'
+) TEST_B
+on TEST_A.ORDER_ID = TEST_B.ORDER_ID
+group by TEST_A.SELLER_ID
diff --git 
a/query/src/main/java/org/apache/kylin/query/relnode/KylinEnumerableUnion.java 
b/query/src/main/java/org/apache/kylin/query/relnode/KylinEnumerableUnion.java
new file mode 100644
index 0000000000..67ed0eeaa9
--- /dev/null
+++ 
b/query/src/main/java/org/apache/kylin/query/relnode/KylinEnumerableUnion.java
@@ -0,0 +1,95 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.kylin.query.relnode;
+
+import org.apache.calcite.adapter.enumerable.EnumerableRel;
+import org.apache.calcite.adapter.enumerable.EnumerableRelImplementor;
+import org.apache.calcite.adapter.enumerable.EnumerableUnion;
+import org.apache.calcite.adapter.enumerable.JavaRowFormat;
+import org.apache.calcite.adapter.enumerable.PhysType;
+import org.apache.calcite.adapter.enumerable.PhysTypeImpl;
+import org.apache.calcite.linq4j.Enumerable;
+import org.apache.calcite.linq4j.ExtendedEnumerable;
+import org.apache.calcite.linq4j.Ord;
+import org.apache.calcite.linq4j.function.EqualityComparer;
+import org.apache.calcite.linq4j.function.Functions;
+import org.apache.calcite.linq4j.tree.BlockBuilder;
+import org.apache.calcite.linq4j.tree.Expression;
+import org.apache.calcite.linq4j.tree.Expressions;
+import org.apache.calcite.linq4j.tree.Types;
+import org.apache.calcite.plan.RelOptCluster;
+import org.apache.calcite.plan.RelTraitSet;
+import org.apache.calcite.rel.RelNode;
+import org.apache.calcite.util.BuiltInMethod;
+
+import java.lang.reflect.Method;
+import java.util.List;
+
+/**
+ * KYLIN-2200
+ */
+public class KylinEnumerableUnion extends EnumerableUnion {
+    private Method unionArray;
+    private Method arrayComparer;
+
+    public KylinEnumerableUnion(RelOptCluster cluster, RelTraitSet traitSet, 
List<RelNode> inputs, boolean all) {
+        super(cluster, traitSet, inputs, all);
+
+        unionArray = Types.lookupMethod(ExtendedEnumerable.class, "union", 
Enumerable.class, EqualityComparer.class);
+        arrayComparer = Types.lookupMethod(Functions.class, "arrayComparer");
+    }
+
+    private Expression createUnionExpression(Expression left, Expression 
right, boolean arrayInput) {
+        if (all) {
+            return Expressions.call(left, BuiltInMethod.CONCAT.method, right);
+        }
+
+        return arrayInput
+                ? Expressions.call(left, unionArray, right, 
Expressions.call(arrayComparer))
+                : Expressions.call(left, BuiltInMethod.UNION.method, right);
+    }
+
+    @Override
+    public Result implement(EnumerableRelImplementor implementor, Prefer pref) 
{
+        final BlockBuilder builder = new BlockBuilder();
+        Expression unionExp = null;
+        for (Ord<RelNode> ord : Ord.zip(inputs)) {
+            EnumerableRel input = (EnumerableRel) ord.e;
+            final Result result = implementor.visitChild(this, ord.i, input, 
pref);
+            Expression childExp =
+                    builder.append(
+                            "child" + ord.i,
+                            result.block);
+
+            if (unionExp == null) {
+                unionExp = childExp;
+            } else {
+                unionExp = createUnionExpression(unionExp, childExp, 
result.format == JavaRowFormat.ARRAY);
+            }
+        }
+
+        builder.add(unionExp);
+        final PhysType physType =
+                PhysTypeImpl.of(
+                        implementor.getTypeFactory(),
+                        getRowType(),
+                        pref.prefer(JavaRowFormat.CUSTOM));
+        return implementor.result(physType, builder.toBlock());
+    }
+}
diff --git 
a/query/src/main/java/org/apache/kylin/query/relnode/OLAPUnionRel.java 
b/query/src/main/java/org/apache/kylin/query/relnode/OLAPUnionRel.java
index 11f0a92a59..7366eeb8d2 100644
--- a/query/src/main/java/org/apache/kylin/query/relnode/OLAPUnionRel.java
+++ b/query/src/main/java/org/apache/kylin/query/relnode/OLAPUnionRel.java
@@ -23,7 +23,6 @@
 
 import org.apache.calcite.adapter.enumerable.EnumerableConvention;
 import org.apache.calcite.adapter.enumerable.EnumerableRel;
-import org.apache.calcite.adapter.enumerable.EnumerableUnion;
 import org.apache.calcite.plan.RelOptCluster;
 import org.apache.calcite.plan.RelOptCost;
 import org.apache.calcite.plan.RelOptPlanner;
@@ -46,7 +45,6 @@
  */
 public class OLAPUnionRel extends Union implements OLAPRel {
 
-    final boolean localAll ; // avoid same name in parent class
     ColumnRowType columnRowType;
     OLAPContext context;
 
@@ -56,7 +54,6 @@ public OLAPUnionRel(RelOptCluster cluster, RelTraitSet 
traitSet, List<RelNode> i
         for (RelNode child : inputs) {
             Preconditions.checkArgument(getConvention() == 
child.getConvention());
         }
-        this.localAll = all;
     }
 
     @Override
@@ -138,7 +135,7 @@ public EnumerableRel 
implementEnumerable(List<EnumerableRel> inputs) {
             }
             relInputs.add(input);
         }
-        return new EnumerableUnion(getCluster(), 
traitSet.replace(EnumerableConvention.INSTANCE), relInputs, localAll);
+        return new KylinEnumerableUnion(getCluster(), 
traitSet.replace(EnumerableConvention.INSTANCE), relInputs, all);
     }
 
     @Override


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


> CompileException on UNION ALL query when result only contains one column
> ------------------------------------------------------------------------
>
>                 Key: KYLIN-2200
>                 URL: https://issues.apache.org/jira/browse/KYLIN-2200
>             Project: Kylin
>          Issue Type: Bug
>          Components: Query Engine
>    Affects Versions: v1.5.4.1
>            Reporter: Dayue Gao
>            Assignee: Dayue Gao
>            Priority: Major
>             Fix For: v2.5.1
>
>         Attachments: KYLIN-2200.patch
>
>
> {code:sql}
> select count(*) from kylin_sales
> union all
> select count(*) from kylin_sales
> {code}
> got following exception
> {noformat}
> Caused by: org.codehaus.commons.compiler.CompileException: Line 82, Column 
> 32: Cannot determine simple type name "Record11_1"
>         at 
> org.codehaus.janino.UnitCompiler.compileError(UnitCompiler.java:10092)
>         at 
> org.codehaus.janino.UnitCompiler.getReferenceType(UnitCompiler.java:5375)
>         at 
> org.codehaus.janino.UnitCompiler.getReferenceType(UnitCompiler.java:5184)
>         at org.codehaus.janino.UnitCompiler.getType2(UnitCompiler.java:5165)
>         at 
> org.codehaus.janino.UnitCompiler.access$12600(UnitCompiler.java:183)
>         at 
> org.codehaus.janino.UnitCompiler$16.visitReferenceType(UnitCompiler.java:5096)
>         at org.codehaus.janino.Java$ReferenceType.accept(Java.java:2880)
>         at org.codehaus.janino.UnitCompiler.getType(UnitCompiler.java:5136)
>         at org.codehaus.janino.UnitCompiler.getType2(UnitCompiler.java:5598)
>         at 
> org.codehaus.janino.UnitCompiler.access$13300(UnitCompiler.java:183)
>         at 
> org.codehaus.janino.UnitCompiler$16.visitCast(UnitCompiler.java:5104)
> {noformat}



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Reply via email to