calcite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jh...@apache.org
Subject incubator-calcite git commit: Fix spurious extra row from FULL JOIN
Date Sun, 11 Jan 2015 04:09:29 GMT
Repository: incubator-calcite
Updated Branches:
  refs/heads/master 1edcba060 -> 89d42b505


Fix spurious extra row from FULL JOIN


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

Branch: refs/heads/master
Commit: 89d42b505053979d7a9a0a8c7c7af37bcec33a69
Parents: 1edcba0
Author: Julian Hyde <jhyde@apache.org>
Authored: Sat Jan 10 19:43:19 2015 -0800
Committer: Julian Hyde <jhyde@apache.org>
Committed: Sat Jan 10 19:43:19 2015 -0800

----------------------------------------------------------------------
 .../java/org/apache/calcite/test/JdbcTest.java  |  1 -
 core/src/test/resources/sql/outer.oq            | 24 ++++++++++----------
 .../calcite/linq4j/EnumerableDefaults.java      | 17 +++++++-------
 .../apache/calcite/linq4j/test/Linq4jTest.java  |  3 +--
 4 files changed, 21 insertions(+), 24 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-calcite/blob/89d42b50/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 8d45b6c..add91fa 100644
--- a/core/src/test/java/org/apache/calcite/test/JdbcTest.java
+++ b/core/src/test/java/org/apache/calcite/test/JdbcTest.java
@@ -4248,7 +4248,6 @@ public class JdbcTest {
             "deptno=10; deptno=10",
             "deptno=10; deptno=10",
             "deptno=20; deptno=null",
-            "deptno=null; deptno=null",
             "deptno=null; deptno=30",
             "deptno=null; deptno=40");
   }

http://git-wip-us.apache.org/repos/asf/incubator-calcite/blob/89d42b50/core/src/test/resources/sql/outer.oq
----------------------------------------------------------------------
diff --git a/core/src/test/resources/sql/outer.oq b/core/src/test/resources/sql/outer.oq
index 0355f64..5d08047 100644
--- a/core/src/test/resources/sql/outer.oq
+++ b/core/src/test/resources/sql/outer.oq
@@ -223,9 +223,8 @@ select * from (select * from emp where gender ='F') as emp full join dept
on emp
 | Wilma |        | F      |         |             |
 |       |        |        |      20 | Marketing   |
 |       |        |        |      40 | Empty       |
-|       |        |        |         |             |
 +-------+--------+--------+---------+-------------+
-(9 rows)
+(8 rows)
 
 !ok
 
@@ -286,6 +285,7 @@ select t1.x from t1 left join t2 on t1.x = t2.x;
 !ok
 
 # Equivalent query, using CAST, and skipping unnecessary aliases
+# (Postgres doesn't like the missing alias, or the missing parentheses.)
 with t1(x) as (select * from (values 1, 2, cast(null as integer))),
   t2(x) as (select * from (values 1, cast(null as integer)))
 select t1.x from t1 left join t2 on t1.x = t2.x;
@@ -300,9 +300,9 @@ select t1.x from t1 left join t2 on t1.x = t2.x;
 
 !ok
 
-# Similar query, projecting both columns
-with t1(x) as (select * from (values 1, 2, cast(null as integer))),
-  t2(x) as (select * from (values 1, cast(null as integer)))
+# Similar query, projecting left and right key columns
+with t1(x) as (select * from (values (1), (2), (cast(null as integer))) as t),
+  t2(x) as (select * from (values (1), (cast(null as integer))) as t)
 select t1.x, t2.x from t1 left join t2 on t1.x = t2.x;
 +---+---+
 | X | X |
@@ -316,31 +316,31 @@ select t1.x, t2.x from t1 left join t2 on t1.x = t2.x;
 !ok
 
 # Similar, with 2 columns on each side projecting both columns
-with t1(x, y) as (select * from (values (1, 10), (2, 20), (cast(null as integer), 30))),
-  t2(x, y) as (select * from (values (1, 100), (cast(null as integer), 200)))
+with t1(x, y) as (select * from (values (1, 10), (2, 20), (cast(null as integer), 30)) as
t),
+  t2(x, y) as (select * from (values (1, 100), (cast(null as integer), 200)) as t)
 select * from t1 left join t2 on t1.x = t2.x;
 +---+----+----+-----+
 | X | Y  | X0 | Y0  |
 +---+----+----+-----+
 | 1 | 10 |  1 | 100 |
 | 2 | 20 |    |     |
-|   | 30 |    | 200 |
+|   | 30 |    |     |
 +---+----+----+-----+
 (3 rows)
 
 !ok
 
 # Similar, full join
-with t1(x, y) as (select * from (values (1, 10), (2, 20), (cast(null as integer), 30))),
-  t2(x, y) as (select * from (values (1,100), (cast(null as integer), 200)))
+with t1(x, y) as (select * from (values (1, 10), (2, 20), (cast(null as integer), 30)) as
t),
+  t2(x, y) as (select * from (values (1,100), (cast(null as integer), 200)) as t)
 select * from t1 full join t2 on t1.x = t2.x;
 +---+----+----+-----+
 | X | Y  | X0 | Y0  |
 +---+----+----+-----+
 | 1 | 10 |  1 | 100 |
 | 2 | 20 |    |     |
-|   | 30 |    | 200 |
-|   |    |    |     |
+|   | 30 |    |     |
+|   |    |    | 200 |
 +---+----+----+-----+
 (4 rows)
 

http://git-wip-us.apache.org/repos/asf/incubator-calcite/blob/89d42b50/linq4j/src/main/java/org/apache/calcite/linq4j/EnumerableDefaults.java
----------------------------------------------------------------------
diff --git a/linq4j/src/main/java/org/apache/calcite/linq4j/EnumerableDefaults.java b/linq4j/src/main/java/org/apache/calcite/linq4j/EnumerableDefaults.java
index f0d68d8..a4df14e 100644
--- a/linq4j/src/main/java/org/apache/calcite/linq4j/EnumerableDefaults.java
+++ b/linq4j/src/main/java/org/apache/calcite/linq4j/EnumerableDefaults.java
@@ -984,14 +984,9 @@ public abstract class EnumerableDefaults {
                       list.add(tInner);
                     }
                   }
-                  list = new ArrayList<TInner>();
-                  for (TKey key : unmatchedKeys) {
-                    for (TInner inner : innerLookup.get(key)) {
-                      list.add(inner);
-                    }
-                  }
                   inners = Linq4j.enumerator(list);
                   outers = Linq4j.singletonNullEnumerator();
+                  outers.moveNext();
                   unmatchedKeys = null; // don't do the 'leftovers' again
                   continue;
                 }
@@ -1003,10 +998,14 @@ public abstract class EnumerableDefaults {
                 innerEnumerable = null;
               } else {
                 final TKey outerKey = outerKeySelector.apply(outer);
-                if (unmatchedKeys != null) {
-                  unmatchedKeys.remove(outerKey);
+                if (outerKey == null) {
+                  innerEnumerable = null;
+                } else {
+                  if (unmatchedKeys != null) {
+                    unmatchedKeys.remove(outerKey);
+                  }
+                  innerEnumerable = innerLookup.get(outerKey);
                 }
-                innerEnumerable = innerLookup.get(outerKey);
               }
               if (innerEnumerable == null
                   || !innerEnumerable.any()) {

http://git-wip-us.apache.org/repos/asf/incubator-calcite/blob/89d42b50/linq4j/src/test/java/org/apache/calcite/linq4j/test/Linq4jTest.java
----------------------------------------------------------------------
diff --git a/linq4j/src/test/java/org/apache/calcite/linq4j/test/Linq4jTest.java b/linq4j/src/test/java/org/apache/calcite/linq4j/test/Linq4jTest.java
index 216aaff..4e133c1 100644
--- a/linq4j/src/test/java/org/apache/calcite/linq4j/test/Linq4jTest.java
+++ b/linq4j/src/test/java/org/apache/calcite/linq4j/test/Linq4jTest.java
@@ -973,8 +973,7 @@ public class Linq4jTest {
             + "Eric works in Sales, "
             + "Fred works in Sales, "
             + "Janet works in Sales, "
-            + "null works in HR, "
-            + "null works in null]",
+            + "null works in HR]",
         s);
   }
 


Mime
View raw message