You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@calcite.apache.org by jh...@apache.org on 2014/12/31 21:15:20 UTC

[1/2] incubator-calcite git commit: Test case for [CALCITE-212] Join condition with OR

Repository: incubator-calcite
Updated Branches:
  refs/heads/master 167623f40 -> 0fda7afc8


Test case for [CALCITE-212] Join condition with OR


Project: http://git-wip-us.apache.org/repos/asf/incubator-calcite/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-calcite/commit/1d9e784d
Tree: http://git-wip-us.apache.org/repos/asf/incubator-calcite/tree/1d9e784d
Diff: http://git-wip-us.apache.org/repos/asf/incubator-calcite/diff/1d9e784d

Branch: refs/heads/master
Commit: 1d9e784d9a331b7c44dcc95cb6dcad17d3348bba
Parents: 167623f
Author: julianhyde <jh...@apache.org>
Authored: Wed Dec 31 10:21:26 2014 -0800
Committer: julianhyde <jh...@apache.org>
Committed: Wed Dec 31 10:21:26 2014 -0800

----------------------------------------------------------------------
 .../java/org/apache/calcite/test/JdbcTest.java  |   4 +
 core/src/test/resources/sql/join.oq             | 115 +++++++++++++++++++
 2 files changed, 119 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-calcite/blob/1d9e784d/core/src/test/java/org/apache/calcite/test/JdbcTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/calcite/test/JdbcTest.java b/core/src/test/java/org/apache/calcite/test/JdbcTest.java
index 6a44e01..52b3b01 100644
--- a/core/src/test/java/org/apache/calcite/test/JdbcTest.java
+++ b/core/src/test/java/org/apache/calcite/test/JdbcTest.java
@@ -4354,6 +4354,10 @@ public class JdbcTest {
     checkRun("sql/agg.oq");
   }
 
+  @Test public void testRunJoin() throws Exception {
+    checkRun("sql/join.oq");
+  }
+
   @Test public void testRunOuter() throws Exception {
     checkRun("sql/outer.oq");
   }

http://git-wip-us.apache.org/repos/asf/incubator-calcite/blob/1d9e784d/core/src/test/resources/sql/join.oq
----------------------------------------------------------------------
diff --git a/core/src/test/resources/sql/join.oq b/core/src/test/resources/sql/join.oq
new file mode 100644
index 0000000..28031ac
--- /dev/null
+++ b/core/src/test/resources/sql/join.oq
@@ -0,0 +1,115 @@
+# join.oq - Join query tests
+#
+# 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.
+#
+!use post
+!set outputformat mysql
+
+# OR is a theta join
+select *
+from emp
+join dept
+on emp.deptno = dept.deptno or emp.ename = dept.dname;
++-------+--------+--------+---------+-------------+
+| ENAME | DEPTNO | GENDER | DEPTNO0 | DNAME       |
++-------+--------+--------+---------+-------------+
+| Alice |     30 | F      |      30 | Engineering |
+| Bob   |     10 | M      |      10 | Sales       |
+| Eric  |     20 | M      |      20 | Marketing   |
+| Jane  |     10 | F      |      10 | Sales       |
+| Susan |     30 | F      |      30 | Engineering |
++-------+--------+--------+---------+-------------+
+(5 rows)
+
+!ok
+
+# As an INNER join, it can be executed as an equi-join followed by a filter
+EnumerableCalc(expr#0..5=[{inputs}], expr#6=[=($t3, $t0)], expr#7=[=($t5, $t1)], expr#8=[OR($t6, $t7)], ENAME=[$t2], DEPTNO=[$t3], GENDER=[$t4], DEPTNO0=[$t0], DNAME=[$t1], $condition=[$t8])
+  EnumerableJoin(condition=[true], joinType=[inner])
+    EnumerableCalc(expr#0..1=[{inputs}], proj#0..1=[{exprs}])
+      EnumerableValues(tuples=[[{ 10, 'Sales      ' }, { 20, 'Marketing  ' }, { 30, 'Engineering' }, { 40, 'Empty      ' }]])
+    EnumerableCalc(expr#0..2=[{inputs}], expr#3=[CAST($t0):CHAR(11) CHARACTER SET "ISO-8859-1" COLLATE "ISO-8859-1$en_US$primary" NOT NULL], proj#0..3=[{exprs}])
+      EnumerableUnion(all=[true])
+        EnumerableCalc(expr#0=[{inputs}], expr#1=['Jane'], expr#2=[10], expr#3=['F'], EXPR$0=[$t1], EXPR$1=[$t2], EXPR$2=[$t3])
+          EnumerableValues(tuples=[[{ 0 }]])
+        EnumerableCalc(expr#0=[{inputs}], expr#1=['Bob'], expr#2=[10], expr#3=['M'], EXPR$0=[$t1], EXPR$1=[$t2], EXPR$2=[$t3])
+          EnumerableValues(tuples=[[{ 0 }]])
+        EnumerableCalc(expr#0=[{inputs}], expr#1=['Eric'], expr#2=[20], expr#3=['M'], EXPR$0=[$t1], EXPR$1=[$t2], EXPR$2=[$t3])
+          EnumerableValues(tuples=[[{ 0 }]])
+        EnumerableCalc(expr#0=[{inputs}], expr#1=['Susan'], expr#2=[30], expr#3=['F'], EXPR$0=[$t1], EXPR$1=[$t2], EXPR$2=[$t3])
+          EnumerableValues(tuples=[[{ 0 }]])
+        EnumerableCalc(expr#0=[{inputs}], expr#1=['Alice'], expr#2=[30], expr#3=['F'], EXPR$0=[$t1], EXPR$1=[$t2], EXPR$2=[$t3])
+          EnumerableValues(tuples=[[{ 0 }]])
+        EnumerableCalc(expr#0=[{inputs}], expr#1=['Adam'], expr#2=[50], expr#3=['M'], EXPR$0=[$t1], EXPR$1=[$t2], EXPR$2=[$t3])
+          EnumerableValues(tuples=[[{ 0 }]])
+        EnumerableCalc(expr#0=[{inputs}], expr#1=['Eve'], expr#2=[50], expr#3=['F'], EXPR$0=[$t1], EXPR$1=[$t2], EXPR$2=[$t3])
+          EnumerableValues(tuples=[[{ 0 }]])
+        EnumerableCalc(expr#0=[{inputs}], expr#1=['Grace'], expr#2=[60], expr#3=['F'], EXPR$0=[$t1], EXPR$1=[$t2], EXPR$2=[$t3])
+          EnumerableValues(tuples=[[{ 0 }]])
+        EnumerableCalc(expr#0=[{inputs}], expr#1=['Wilma'], expr#2=[null], expr#3=['F'], EXPR$0=[$t1], EXPR$1=[$t2], EXPR$2=[$t3])
+          EnumerableValues(tuples=[[{ 0 }]])
+!plan
+
+# Now the same, but LEFT join
+select *
+from emp
+left join dept
+on emp.deptno = dept.deptno or emp.ename = dept.dname;
++-------+--------+--------+---------+-------------+
+| ENAME | DEPTNO | GENDER | DEPTNO0 | DNAME       |
++-------+--------+--------+---------+-------------+
+| Adam  |     50 | M      |         |             |
+| Alice |     30 | F      |      30 | Engineering |
+| Bob   |     10 | M      |      10 | Sales       |
+| Eric  |     20 | M      |      20 | Marketing   |
+| Eve   |     50 | F      |         |             |
+| Grace |     60 | F      |         |             |
+| Jane  |     10 | F      |      10 | Sales       |
+| Susan |     30 | F      |      30 | Engineering |
+| Wilma |        | F      |         |             |
++-------+--------+--------+---------+-------------+
+(9 rows)
+
+!ok
+
+# Cannot be decomposed into an equi-join; plan uses EnumerableThetaJoin
+EnumerableCalc(expr#0..5=[{inputs}], proj#0..2=[{exprs}], DEPTNO0=[$t4], DNAME=[$t5])
+  EnumerableThetaJoin(condition=[OR(=($1, $4), =($3, $5))], joinType=[left])
+    EnumerableCalc(expr#0..2=[{inputs}], expr#3=[CAST($t0):CHAR(11) CHARACTER SET "ISO-8859-1" COLLATE "ISO-8859-1$en_US$primary" NOT NULL], proj#0..3=[{exprs}])
+      EnumerableUnion(all=[true])
+        EnumerableCalc(expr#0=[{inputs}], expr#1=['Jane'], expr#2=[10], expr#3=['F'], EXPR$0=[$t1], EXPR$1=[$t2], EXPR$2=[$t3])
+          EnumerableValues(tuples=[[{ 0 }]])
+        EnumerableCalc(expr#0=[{inputs}], expr#1=['Bob'], expr#2=[10], expr#3=['M'], EXPR$0=[$t1], EXPR$1=[$t2], EXPR$2=[$t3])
+          EnumerableValues(tuples=[[{ 0 }]])
+        EnumerableCalc(expr#0=[{inputs}], expr#1=['Eric'], expr#2=[20], expr#3=['M'], EXPR$0=[$t1], EXPR$1=[$t2], EXPR$2=[$t3])
+          EnumerableValues(tuples=[[{ 0 }]])
+        EnumerableCalc(expr#0=[{inputs}], expr#1=['Susan'], expr#2=[30], expr#3=['F'], EXPR$0=[$t1], EXPR$1=[$t2], EXPR$2=[$t3])
+          EnumerableValues(tuples=[[{ 0 }]])
+        EnumerableCalc(expr#0=[{inputs}], expr#1=['Alice'], expr#2=[30], expr#3=['F'], EXPR$0=[$t1], EXPR$1=[$t2], EXPR$2=[$t3])
+          EnumerableValues(tuples=[[{ 0 }]])
+        EnumerableCalc(expr#0=[{inputs}], expr#1=['Adam'], expr#2=[50], expr#3=['M'], EXPR$0=[$t1], EXPR$1=[$t2], EXPR$2=[$t3])
+          EnumerableValues(tuples=[[{ 0 }]])
+        EnumerableCalc(expr#0=[{inputs}], expr#1=['Eve'], expr#2=[50], expr#3=['F'], EXPR$0=[$t1], EXPR$1=[$t2], EXPR$2=[$t3])
+          EnumerableValues(tuples=[[{ 0 }]])
+        EnumerableCalc(expr#0=[{inputs}], expr#1=['Grace'], expr#2=[60], expr#3=['F'], EXPR$0=[$t1], EXPR$1=[$t2], EXPR$2=[$t3])
+          EnumerableValues(tuples=[[{ 0 }]])
+        EnumerableCalc(expr#0=[{inputs}], expr#1=['Wilma'], expr#2=[null], expr#3=['F'], EXPR$0=[$t1], EXPR$1=[$t2], EXPR$2=[$t3])
+          EnumerableValues(tuples=[[{ 0 }]])
+    EnumerableCalc(expr#0..1=[{inputs}], proj#0..1=[{exprs}])
+      EnumerableValues(tuples=[[{ 10, 'Sales      ' }, { 20, 'Marketing  ' }, { 30, 'Engineering' }, { 40, 'Empty      ' }]])
+!plan
+
+# End join.oq


[2/2] incubator-calcite git commit: Fix indeterminacy in a test

Posted by jh...@apache.org.
Fix indeterminacy in a test


Project: http://git-wip-us.apache.org/repos/asf/incubator-calcite/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-calcite/commit/0fda7afc
Tree: http://git-wip-us.apache.org/repos/asf/incubator-calcite/tree/0fda7afc
Diff: http://git-wip-us.apache.org/repos/asf/incubator-calcite/diff/0fda7afc

Branch: refs/heads/master
Commit: 0fda7afc84af372553e3fd21e666cc683d456f1f
Parents: 1d9e784
Author: julianhyde <jh...@apache.org>
Authored: Wed Dec 31 11:36:24 2014 -0800
Committer: julianhyde <jh...@apache.org>
Committed: Wed Dec 31 11:36:24 2014 -0800

----------------------------------------------------------------------
 .../org/apache/calcite/runtime/EnumerablesTest.java   |  5 +++--
 .../org/apache/calcite/linq4j/function/Functions.java | 14 ++++++++++++++
 2 files changed, 17 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-calcite/blob/0fda7afc/core/src/test/java/org/apache/calcite/runtime/EnumerablesTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/calcite/runtime/EnumerablesTest.java b/core/src/test/java/org/apache/calcite/runtime/EnumerablesTest.java
index bfbf339..33a2593 100644
--- a/core/src/test/java/org/apache/calcite/runtime/EnumerablesTest.java
+++ b/core/src/test/java/org/apache/calcite/runtime/EnumerablesTest.java
@@ -218,8 +218,9 @@ public class EnumerablesTest {
   @Test public void testThetaFullJoinLeftEmpty() {
     assertThat(
         Enumerables.thetaJoin(EMPS.take(0), DEPTS, EQUAL_DEPTNO,
-            EMP_DEPT_TO_STRING, true, true).toList().toString(),
-        equalTo("[{null, null, 20, Sales}, {null, null, 15, Marketing}]"));
+            EMP_DEPT_TO_STRING, true, true)
+            .orderBy(Functions.<String>identitySelector()).toList().toString(),
+        equalTo("[{null, null, 15, Marketing}, {null, null, 20, Sales}]"));
   }
 
   @Test public void testThetaFullJoinRightEmpty() {

http://git-wip-us.apache.org/repos/asf/incubator-calcite/blob/0fda7afc/linq4j/src/main/java/org/apache/calcite/linq4j/function/Functions.java
----------------------------------------------------------------------
diff --git a/linq4j/src/main/java/org/apache/calcite/linq4j/function/Functions.java b/linq4j/src/main/java/org/apache/calcite/linq4j/function/Functions.java
index 12b0a18..76e6bb8 100644
--- a/linq4j/src/main/java/org/apache/calcite/linq4j/function/Functions.java
+++ b/linq4j/src/main/java/org/apache/calcite/linq4j/function/Functions.java
@@ -83,6 +83,13 @@ public abstract class Functions {
         }
       };
 
+  private static final Function1 TO_STRING_FUNCTION1 =
+      new Function1<Object, String>() {
+        public String apply(Object a0) {
+          return a0.toString();
+        }
+      };
+
   @SuppressWarnings("unchecked")
   private static <K, V> Map<K, V> map(K k, V v, Object... rest) {
     final Map<K, V> map = new HashMap<K, V>();
@@ -171,6 +178,13 @@ public abstract class Functions {
     return (Function1) Function1.IDENTITY;
   }
 
+  /** Returns a selector that calls the {@link Object#toString()} method on
+   * each element. */
+  public static <TSource> Function1<TSource, String> toStringSelector() {
+    //noinspection unchecked
+    return TO_STRING_FUNCTION1;
+  }
+
   /**
    * Creates a predicate that returns whether an object is an instance of a
    * particular type or is null.