TAJO-898: Left outer join with union returns empty result. (Hyoungjun Kim via 
hyunsik)

Closes #55


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

Branch: refs/heads/window_function
Commit: 9fdd1ebe120976df53de4cee890de88413847146
Parents: 844ffd7
Author: Hyunsik Choi <[email protected]>
Authored: Mon Jul 7 11:48:19 2014 +0900
Committer: Hyunsik Choi <[email protected]>
Committed: Mon Jul 7 11:49:52 2014 +0900

----------------------------------------------------------------------
 CHANGES                                         |  3 +++
 .../tajo/master/querymaster/Repartitioner.java  | 11 +++++++--
 .../tajo/engine/query/TestUnionQuery.java       | 25 ++++++++++++++++++++
 3 files changed, 37 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tajo/blob/9fdd1ebe/CHANGES
----------------------------------------------------------------------
diff --git a/CHANGES b/CHANGES
index 986af7a..74db949 100644
--- a/CHANGES
+++ b/CHANGES
@@ -74,6 +74,9 @@ Release 0.9.0 - unreleased
 
   BUG FIXES
 
+    TAJO-898: Left outer join with union returns empty result. 
+    (Hyoungjun Kim via hyunsik)
+
     TAJO-897: PartitionedTableRewriter is repeated several times with same 
     table. (Hyoungjun Kim via hyunsik)
 

http://git-wip-us.apache.org/repos/asf/tajo/blob/9fdd1ebe/tajo-core/src/main/java/org/apache/tajo/master/querymaster/Repartitioner.java
----------------------------------------------------------------------
diff --git 
a/tajo-core/src/main/java/org/apache/tajo/master/querymaster/Repartitioner.java 
b/tajo-core/src/main/java/org/apache/tajo/master/querymaster/Repartitioner.java
index 80274e2..0046dbe 100644
--- 
a/tajo-core/src/main/java/org/apache/tajo/master/querymaster/Repartitioner.java
+++ 
b/tajo-core/src/main/java/org/apache/tajo/master/querymaster/Repartitioner.java
@@ -88,8 +88,15 @@ public class Repartitioner {
       TableDesc tableDesc = 
masterContext.getTableDescMap().get(scans[i].getCanonicalName());
       if (tableDesc == null) { // if it is a real table stored on storage
         tablePath = storageManager.getTablePath(scans[i].getTableName());
-        ExecutionBlockId scanEBId = 
TajoIdUtils.createExecutionBlockId(scans[i].getTableName());
-        stats[i] = 
masterContext.getSubQuery(scanEBId).getResultStats().getNumBytes();
+        if (execBlock.getUnionScanMap() != null && 
!execBlock.getUnionScanMap().isEmpty()) {
+          for (Map.Entry<ExecutionBlockId, ExecutionBlockId> unionScanEntry: 
execBlock.getUnionScanMap().entrySet()) {
+            ExecutionBlockId originScanEbId = unionScanEntry.getKey();
+            stats[i] += 
masterContext.getSubQuery(originScanEbId).getResultStats().getNumBytes();
+          }
+        } else {
+          ExecutionBlockId scanEBId = 
TajoIdUtils.createExecutionBlockId(scans[i].getTableName());
+          stats[i] = 
masterContext.getSubQuery(scanEBId).getResultStats().getNumBytes();
+        }
         fragments[i] = new FileFragment(scans[i].getCanonicalName(), 
tablePath, 0, 0, new String[]{UNKNOWN_HOST});
       } else {
         tablePath = tableDesc.getPath();

http://git-wip-us.apache.org/repos/asf/tajo/blob/9fdd1ebe/tajo-core/src/test/java/org/apache/tajo/engine/query/TestUnionQuery.java
----------------------------------------------------------------------
diff --git 
a/tajo-core/src/test/java/org/apache/tajo/engine/query/TestUnionQuery.java 
b/tajo-core/src/test/java/org/apache/tajo/engine/query/TestUnionQuery.java
index 1ec2c33..3d292a4 100644
--- a/tajo-core/src/test/java/org/apache/tajo/engine/query/TestUnionQuery.java
+++ b/tajo-core/src/test/java/org/apache/tajo/engine/query/TestUnionQuery.java
@@ -425,4 +425,29 @@ public class TestUnionQuery extends QueryTestCaseBase {
 
     cleanupQuery(res);
   }
+
+  @Test
+  public void testUnionCaseOfFirstEmptyAndJoin() throws Exception {
+    ResultSet res = executeString(
+        "select a.c_custkey, b.c_custkey from " +
+            "  (select c_custkey, c_nationkey from customer where c_nationkey 
< 0 " +
+            "   union all " +
+            "   select c_custkey, c_nationkey from customer where c_nationkey 
> 0 " +
+            ") a " +
+            "left outer join customer b " +
+            "on a.c_custkey = b.c_custkey "
+    );
+
+    String expected =
+        "c_custkey,c_custkey\n" +
+            "-------------------------------\n" +
+            "1,1\n" +
+            "2,2\n" +
+            "3,3\n" +
+            "4,4\n" +
+            "5,5\n";
+
+    assertEquals(expected, resultSetToString(res));
+    res.close();
+  }
 }
\ No newline at end of file

Reply via email to