From 0ced1986f281f830c695ede94138a461431ed8f4 Mon Sep 17 00:00:00 2001 From: Amit Hadke Date: Mon, 7 Dec 2015 14:13:55 -0800 Subject: [PATCH 1/2] DRILL-4165 Fix a bug in counting records in outgoing batch. --- .../drill/exec/physical/impl/join/JoinStatus.java | 4 ++-- .../drill/exec/physical/impl/join/JoinTemplate.java | 8 ++++++-- .../physical/impl/join/TestMergeJoinAdvanced.java | 12 ++++++++++++ 3 files changed, 20 insertions(+), 4 deletions(-) diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/physical/impl/join/JoinStatus.java b/exec/java-exec/src/main/java/org/apache/drill/exec/physical/impl/join/JoinStatus.java index f7154f8226a..e96823611fc 100644 --- a/exec/java-exec/src/main/java/org/apache/drill/exec/physical/impl/join/JoinStatus.java +++ b/exec/java-exec/src/main/java/org/apache/drill/exec/physical/impl/join/JoinStatus.java @@ -99,7 +99,7 @@ public final void resetOutputPos() { } public final boolean isOutgoingBatchFull() { - return outputPosition == OUTPUT_BATCH_SIZE; + return outputPosition >= OUTPUT_BATCH_SIZE; } public final void incOutputPos() { @@ -160,4 +160,4 @@ private boolean eitherMatches(IterOutcome outcome) { return getLeftStatus() == outcome || getRightStatus() == outcome; } -} \ No newline at end of file +} diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/physical/impl/join/JoinTemplate.java b/exec/java-exec/src/main/java/org/apache/drill/exec/physical/impl/join/JoinTemplate.java index ed900dbae7b..40c47b3db78 100644 --- a/exec/java-exec/src/main/java/org/apache/drill/exec/physical/impl/join/JoinTemplate.java +++ b/exec/java-exec/src/main/java/org/apache/drill/exec/physical/impl/join/JoinTemplate.java @@ -83,6 +83,12 @@ public final boolean doJoin(final JoinStatus status) { doCopyRight(status.right.getCurrentPosition(), status.getOutPosition()); status.incOutputPos(); } + if (status.isOutgoingBatchFull()) { + // Leave iterators at their current positions and markers. + // Don't mark on all subsequent doJoin iterations. + status.disableMarking(); + return true; + } // Move to next position in right iterator. status.right.next(); while (!status.right.finished()) { @@ -91,8 +97,6 @@ public final boolean doJoin(final JoinStatus status) { doCopyRight(status.right.getCurrentPosition(), status.getOutPosition()); status.incOutputPos(); if (status.isOutgoingBatchFull()) { - // Leave iterators at their current positions and markers. - // Don't mark on all subsequent doJoin iterations. status.disableMarking(); return true; } diff --git a/exec/java-exec/src/test/java/org/apache/drill/exec/physical/impl/join/TestMergeJoinAdvanced.java b/exec/java-exec/src/test/java/org/apache/drill/exec/physical/impl/join/TestMergeJoinAdvanced.java index 87058f20817..05776d30966 100644 --- a/exec/java-exec/src/test/java/org/apache/drill/exec/physical/impl/join/TestMergeJoinAdvanced.java +++ b/exec/java-exec/src/test/java/org/apache/drill/exec/physical/impl/join/TestMergeJoinAdvanced.java @@ -202,4 +202,16 @@ public void testMergeRightJoinRandomized() throws Exception { final long left = r.nextInt(10001) + 1l; testMultipleBatchJoin(left, right, "right", left * right + 3l); } + + @Test + public void testDrill4165() throws Exception { + final String query1 = "select count(*) cnt from cp.`tpch/lineitem.parquet` l1, cp.`tpch/lineitem.parquet` l2 where l1.l_partkey = l2.l_partkey and l1.l_suppkey < 30 and l2.l_suppkey < 30"; + testBuilder() + .sqlQuery(query1) + .optionSettingQueriesForTestQuery("alter session set `planner.enable_hashjoin` = false") + .unOrdered() + .baselineColumns("cnt") + .baselineValues(202452l) + .go(); + } } From fe3da5ce96e06758618d5dd4d6255fdfffc9c00a Mon Sep 17 00:00:00 2001 From: Amit Hadke Date: Mon, 7 Dec 2015 14:41:34 -0800 Subject: [PATCH 2/2] DRILL-4165 remove redundant call to setting hash join session option. --- .../drill/exec/physical/impl/join/TestMergeJoinAdvanced.java | 1 - 1 file changed, 1 deletion(-) diff --git a/exec/java-exec/src/test/java/org/apache/drill/exec/physical/impl/join/TestMergeJoinAdvanced.java b/exec/java-exec/src/test/java/org/apache/drill/exec/physical/impl/join/TestMergeJoinAdvanced.java index 05776d30966..ac6ac893694 100644 --- a/exec/java-exec/src/test/java/org/apache/drill/exec/physical/impl/join/TestMergeJoinAdvanced.java +++ b/exec/java-exec/src/test/java/org/apache/drill/exec/physical/impl/join/TestMergeJoinAdvanced.java @@ -208,7 +208,6 @@ public void testDrill4165() throws Exception { final String query1 = "select count(*) cnt from cp.`tpch/lineitem.parquet` l1, cp.`tpch/lineitem.parquet` l2 where l1.l_partkey = l2.l_partkey and l1.l_suppkey < 30 and l2.l_suppkey < 30"; testBuilder() .sqlQuery(query1) - .optionSettingQueriesForTestQuery("alter session set `planner.enable_hashjoin` = false") .unOrdered() .baselineColumns("cnt") .baselineValues(202452l)