Github user amansinha100 commented on a diff in the pull request: https://github.com/apache/drill/pull/462#discussion_r58761755 --- Diff: exec/java-exec/src/main/java/org/apache/drill/exec/planner/common/DrillRelOptUtil.java --- @@ -169,4 +176,223 @@ private static boolean containIdentity(List<? extends RexNode> exps, } return true; } + + /** + * Copied from {@link RelOptUtil#splitJoinCondition(RelNode, RelNode, RexNode, List, List)}. Modified to rewrite + * the null equal join condition using IS NOT DISTINCT FROM operator. + * + * Splits out the equi-join components of a join condition, and returns + * what's left. For example, given the condition + * + * <blockquote><code>L.A = R.X AND L.B = L.C AND (L.D = 5 OR L.E = + * R.Y)</code></blockquote> + * + * returns + * + * <ul> + * <li>leftKeys = {A} + * <li>rightKeys = {X} + * <li>rest = L.B = L.C AND (L.D = 5 OR L.E = R.Y)</li> + * </ul> + * + * @param left left input to join + * @param right right input to join + * @param condition join condition + * @param leftKeys The ordinals of the fields from the left input which are + * equi-join keys + * @param rightKeys The ordinals of the fields from the right input which + * are equi-join keys + * @param joinOps List of equi-join operators (EQUALS or IS NOT DISTINCT FROM) used to join the left and right keys. + * @return remaining join filters that are not equijoins; may return a + * {@link RexLiteral} true, but never null + */ + public static RexNode splitJoinCondition( + RelNode left, + RelNode right, + RexNode condition, + List<Integer> leftKeys, + List<Integer> rightKeys, + List<SqlBinaryOperator> joinOps) { + final List<RexNode> nonEquiList = new ArrayList<>(); + + splitJoinCondition( + left.getRowType().getFieldCount(), + condition, + leftKeys, + rightKeys, + joinOps, + nonEquiList); + + return RexUtil.composeConjunction( + left.getCluster().getRexBuilder(), nonEquiList, false); + } + + /** + * Copied from {@link RelOptUtil#splitJoinCondition(int, RexNode, List, List, List)}. Modified to rewrite the null + * equal join condition using IS NOT DISTINCT FROM operator. + */ + private static void splitJoinCondition( --- End diff -- Can you confirm if this rewrite does *not* do the conversion if the join condition happens to involve columns coming from not just 2 tables but from 3 tables ? e.g if the user accidentally gives: SELECT * FROM t1, t2, t3 WHERE t1.a = t2.a OR (t1.b is null and t3.b is null)
--- If your project is set up for it, you can reply to this email and have your reply appear on GitHub as well. If your project does not have this feature enabled and wishes so, or if the feature is enabled but not working, please contact infrastructure at infrastruct...@apache.org or file a JIRA ticket with INFRA. ---