From 35b42ebdfd645b92330ad5dcac363aa0036696a7 Mon Sep 17 00:00:00 2001 From: Sorabh Hamirwasia Date: Tue, 29 Jan 2019 21:09:55 -0800 Subject: DRILL-7016: Wrong query result with RuntimeFilter enabled when order of join and filter condition is swapped close apache/drill#1628 --- .../physical/visitor/RuntimeFilterVisitor.java | 8 +- .../impl/join/TestHashJoinJPPDCorrectness.java | 178 +++++++++++++++++++++ 2 files changed, 183 insertions(+), 3 deletions(-) create mode 100644 exec/java-exec/src/test/java/org/apache/drill/exec/physical/impl/join/TestHashJoinJPPDCorrectness.java diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/planner/physical/visitor/RuntimeFilterVisitor.java b/exec/java-exec/src/main/java/org/apache/drill/exec/planner/physical/visitor/RuntimeFilterVisitor.java index 4d309aea0..acc597705 100644 --- a/exec/java-exec/src/main/java/org/apache/drill/exec/planner/physical/visitor/RuntimeFilterVisitor.java +++ b/exec/java-exec/src/main/java/org/apache/drill/exec/planner/physical/visitor/RuntimeFilterVisitor.java @@ -162,12 +162,14 @@ public class RuntimeFilterVisitor extends BasePrelVisitor leftFields = left.getRowType().getFieldNames(); List rightFields = right.getRowType().getFieldNames(); List leftKeys = hashJoinPrel.getLeftKeys(); + List rightKeys = hashJoinPrel.getRightKeys(); RelMetadataQuery metadataQuery = left.getCluster().getMetadataQuery(); int i = 0; for (Integer leftKey : leftKeys) { String leftFieldName = leftFields.get(leftKey); - String rightFieldName = rightFields.get(i); - i++; + Integer rightKey = rightKeys.get(i++); + String rightFieldName = rightFields.get(rightKey); + //This also avoids the left field of the join condition with a function call. ScanPrel scanPrel = findLeftScanPrel(leftFieldName, left); if (scanPrel != null) { @@ -405,4 +407,4 @@ public class RuntimeFilterVisitor extends BasePrelVisitor