DRILL-2963: Fix NestedLoopJoinBatch when left batch is empty

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

Branch: refs/heads/master
Commit: 31e51832db216ca16525af83abd445b812c569c4
Parents: 3ab9683
Author: Mehant Baid <[email protected]>
Authored: Wed Apr 29 17:35:33 2015 -0700
Committer: Mehant Baid <[email protected]>
Committed: Wed May 6 11:21:57 2015 -0700

----------------------------------------------------------------------
 .../physical/impl/join/NestedLoopJoinBatch.java |  6 +++
 .../apache/drill/TestDisabledFunctionality.java | 12 -----
 .../physical/impl/join/TestNestedLoopJoin.java  | 52 ++++++++++++++++++++
 3 files changed, 58 insertions(+), 12 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/drill/blob/31e51832/exec/java-exec/src/main/java/org/apache/drill/exec/physical/impl/join/NestedLoopJoinBatch.java
----------------------------------------------------------------------
diff --git 
a/exec/java-exec/src/main/java/org/apache/drill/exec/physical/impl/join/NestedLoopJoinBatch.java
 
b/exec/java-exec/src/main/java/org/apache/drill/exec/physical/impl/join/NestedLoopJoinBatch.java
index d20bfa1..aa4b300 100644
--- 
a/exec/java-exec/src/main/java/org/apache/drill/exec/physical/impl/join/NestedLoopJoinBatch.java
+++ 
b/exec/java-exec/src/main/java/org/apache/drill/exec/physical/impl/join/NestedLoopJoinBatch.java
@@ -140,6 +140,12 @@ public class NestedLoopJoinBatch extends 
AbstractRecordBatch<NestedLoopJoinPOP>
 
     // Accumulate batches on the right in a hyper container
     if (state == BatchState.FIRST) {
+
+      // exit if we have an empty left batch
+      if (leftUpstream == IterOutcome.NONE) {
+        return IterOutcome.NONE;
+      }
+
       boolean drainRight = true;
       while (drainRight == true) {
         rightUpstream = next(RIGHT_INPUT, right);

http://git-wip-us.apache.org/repos/asf/drill/blob/31e51832/exec/java-exec/src/test/java/org/apache/drill/TestDisabledFunctionality.java
----------------------------------------------------------------------
diff --git 
a/exec/java-exec/src/test/java/org/apache/drill/TestDisabledFunctionality.java 
b/exec/java-exec/src/test/java/org/apache/drill/TestDisabledFunctionality.java
index 504524d..fd002c5 100644
--- 
a/exec/java-exec/src/test/java/org/apache/drill/TestDisabledFunctionality.java
+++ 
b/exec/java-exec/src/test/java/org/apache/drill/TestDisabledFunctionality.java
@@ -252,18 +252,6 @@ public class TestDisabledFunctionality extends 
BaseTestQuery{
     }
   }
 
-  @Test(expected = UnsupportedRelOperatorException.class) // see DRILL-1325,
-  @Ignore // TODO: currently errors out in NLJ
-  public void testSubqueryWithoutCorrelatedJoinCondition() throws Exception {
-    try {
-      test("select a.lastname " +
-          "from cp.`employee.json` a " +
-          "where exists (select n_name from cp.`tpch/nation.parquet` b) AND 
a.position_id = 10");
-    } catch(UserException ex) {
-      throwAsUnsupportedException(ex);
-    }
-  }
-
   @Test(expected = UnsupportedRelOperatorException.class) // see DRILL-2068, 
DRILL-1325
   public void testExplainPlanForCartesianJoin() throws Exception {
     try {

http://git-wip-us.apache.org/repos/asf/drill/blob/31e51832/exec/java-exec/src/test/java/org/apache/drill/exec/physical/impl/join/TestNestedLoopJoin.java
----------------------------------------------------------------------
diff --git 
a/exec/java-exec/src/test/java/org/apache/drill/exec/physical/impl/join/TestNestedLoopJoin.java
 
b/exec/java-exec/src/test/java/org/apache/drill/exec/physical/impl/join/TestNestedLoopJoin.java
index 35a95dd..6059a5b 100644
--- 
a/exec/java-exec/src/test/java/org/apache/drill/exec/physical/impl/join/TestNestedLoopJoin.java
+++ 
b/exec/java-exec/src/test/java/org/apache/drill/exec/physical/impl/join/TestNestedLoopJoin.java
@@ -19,7 +19,9 @@
 package org.apache.drill.exec.physical.impl.join;
 
 import org.apache.drill.PlanTestBase;
+import org.apache.drill.common.exceptions.UserException;
 import org.apache.drill.common.util.TestTools;
+import org.apache.drill.exec.work.foreman.UnsupportedRelOperatorException;
 import org.junit.Ignore;
 import org.junit.Test;
 
@@ -201,4 +203,54 @@ public class TestNestedLoopJoin extends PlanTestBase {
         .go();
   }
 
+  @Test
+  public void testNLJWithEmptyBatch() throws Exception {
+    Long result = 0l;
+
+    test(DISABLE_NLJ_SCALAR);
+    test(DISABLE_HJ);
+    test(DISABLE_MJ);
+
+    // We have a false filter causing empty left batch
+    String query = "select count(*) col from (select a.lastname " +
+        "from cp.`employee.json` a " +
+        "where exists (select n_name from cp.`tpch/nation.parquet` b) AND 1 = 
0)";
+
+    testBuilder()
+        .sqlQuery(query)
+        .unOrdered()
+        .baselineColumns("col")
+        .baselineValues(result)
+        .go();
+
+    // Below tests use NLJ in a general case (non-scalar subqueries, followed 
by filter) with empty batches
+    query = "select count(*) col from " +
+        "(select t1.department_id " +
+        "from cp.`employee.json` t1 inner join cp.`department.json` t2 " +
+        "on t1.department_id = t2.department_id where t1.department_id = -1)";
+
+    testBuilder()
+        .sqlQuery(query)
+        .unOrdered()
+        .baselineColumns("col")
+        .baselineValues(result)
+        .go();
+
+    query = "select count(*) col from " +
+        "(select t1.department_id " +
+        "from cp.`employee.json` t1 inner join cp.`department.json` t2 " +
+        "on t1.department_id = t2.department_id where t2.department_id = -1)";
+
+
+    testBuilder()
+        .sqlQuery(query)
+        .unOrdered()
+        .baselineColumns("col")
+        .baselineValues(result)
+        .go();
+
+    test(ENABLE_NLJ_SCALAR);
+    test(ENABLE_HJ);
+    test(ENABLE_MJ);
+  }
 }

Reply via email to