TAJO-896: Full outer join query with empty intermediate data doesn't terminate. 
(Hyoungjun Kim via hyunsik)

Closes #51


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

Branch: refs/heads/window_function
Commit: f5e999915a852473a77aa6958c46ae2389bafa2f
Parents: 88d0434
Author: Hyunsik Choi <[email protected]>
Authored: Mon Jun 30 20:54:48 2014 +0900
Committer: Hyunsik Choi <[email protected]>
Committed: Mon Jun 30 20:54:48 2014 +0900

----------------------------------------------------------------------
 .../tajo/master/querymaster/Repartitioner.java  | 13 +++++++++++++
 .../apache/tajo/engine/query/TestJoinQuery.java | 20 ++++++++++++++++++++
 2 files changed, 33 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tajo/blob/f5e99991/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 93e40fd..80274e2 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
@@ -126,6 +126,19 @@ public class Repartitioner {
     // If node is outer join and a preserved relation is empty, it should 
return zero rows.
     joinNode = PlannerUtil.findTopNode(execBlock.getPlan(), NodeType.JOIN);
     if (joinNode != null) {
+      // If all stats are zero, return
+      boolean isEmptyAllJoinTables = true;
+      for (int i = 0; i < stats.length; i++) {
+        if (stats[i] > 0) {
+          isEmptyAllJoinTables = false;
+          break;
+        }
+      }
+      if (isEmptyAllJoinTables) {
+        LOG.info("All input join tables are empty.");
+        return;
+      }
+
       // find left top scan node
       ScanNode leftScanNode = PlannerUtil.findTopNode(joinNode.getLeftChild(), 
NodeType.SCAN);
       ScanNode rightScanNode = 
PlannerUtil.findTopNode(joinNode.getRightChild(), NodeType.SCAN);

http://git-wip-us.apache.org/repos/asf/tajo/blob/f5e99991/tajo-core/src/test/java/org/apache/tajo/engine/query/TestJoinQuery.java
----------------------------------------------------------------------
diff --git 
a/tajo-core/src/test/java/org/apache/tajo/engine/query/TestJoinQuery.java 
b/tajo-core/src/test/java/org/apache/tajo/engine/query/TestJoinQuery.java
index e109616..8f8f86b 100644
--- a/tajo-core/src/test/java/org/apache/tajo/engine/query/TestJoinQuery.java
+++ b/tajo-core/src/test/java/org/apache/tajo/engine/query/TestJoinQuery.java
@@ -1010,4 +1010,24 @@ public class TestJoinQuery extends QueryTestCaseBase {
     assertResultSet(res);
     cleanupQuery(res);
   }
+
+  @Test
+  public void testFullOuterJoinWithEmptyIntermediateData() throws Exception {
+    ResultSet res = executeString(
+        "select a.l_orderkey \n" +
+            "from (select * from lineitem where l_orderkey < 0) a\n" +
+            "full outer join (select * from lineitem where l_orderkey < 0) 
b\n" +
+            "on a.l_orderkey = b.l_orderkey"
+    );
+
+    try {
+      String expected =
+          "l_orderkey\n" +
+              "-------------------------------\n";
+
+      assertEquals(expected, resultSetToString(res));
+    } finally {
+      cleanupQuery(res);
+    }
+  }
 }

Reply via email to