kasakrisz commented on code in PR #6055:
URL: https://github.com/apache/hive/pull/6055#discussion_r2318092008
##########
ql/src/test/queries/clientpositive/antijoin_conversion.q:
##########
@@ -20,3 +20,31 @@ select n.* from n left outer join t on (n.a=t.a) where
cast(t.a as float) is nul
select assert_true(count(1)=4) from n left outer join t on (n.a=t.a) where
cast(t.a as float) is null;
+create table tab1 (col1 int, col2 int, col3 int, col4 int);
+create table tab2 (col1 int, col2 int, col3 int, col4 int);
+
+insert into tab1 values (123, 1000, 5000, 9), (456, 1000, 7000, 7), (789,
1000, 5000, 8);
+insert into tab2 values (123, 1000, 5000, 2), (456, 1000, 7000, 7), (123,
5000, 4000, 2);
+
+select t1.col1, t1.col2, t1.col3 from tab2 t1
+left join tab1 t2
Review Comment:
Could you please swap the aliases so let
tab1 t1 and tab2 t2
##########
ql/src/java/org/apache/hadoop/hive/ql/optimizer/calcite/HiveCalciteUtil.java:
##########
@@ -1272,6 +1272,28 @@ public static boolean
hasAllExpressionsFromRightSide(RelNode joinRel, List<RexNo
return true;
}
+ /**
+ * Checks the operands in the join conditions are from right table or only
from left table.
+ *
+ * @param joinRel Join node
+ * @return true if the join condition operands are from right and left
table, false otherwise.
+ */
+ public static boolean hasJoinConditionOperandFromRightTable(Join joinRel) {
+ RexNode condition = joinRel.getCondition();
+ RelNode leftRel = joinRel.getLeft();
+ int leftFieldCount = leftRel.getRowType().getFieldCount();
+ ImmutableBitSet leftBitmap = ImmutableBitSet.range(leftFieldCount);
+ List<RexNode> conditions = RelOptUtil.conjunctions(condition);
+ for (RexNode cond : conditions) {
+ ImmutableBitSet condBitmap = RelOptUtil.InputFinder.bits(cond);
+ // if condition becomes true if both the operands are from left table
Review Comment:
Typo: if ... if
##########
ql/src/java/org/apache/hadoop/hive/ql/optimizer/calcite/rules/HiveAntiSemiJoinRule.java:
##########
@@ -97,6 +97,12 @@ protected void perform(RelOptRuleCall call, Project project,
Filter filter, Join
return;
}
+ // if one of the operand from join condition is not from right table then
no need to convert to anti join.
+ boolean hasConditionMet =
HiveCalciteUtil.hasJoinConditionOperandFromRightTable(join);
+ if (!hasConditionMet) {
Review Comment:
The local variable `hasConditionMet` can be removed and the function call
`hasJoinConditionOperandFromRightTable` can be inlined.
##########
ql/src/java/org/apache/hadoop/hive/ql/optimizer/calcite/HiveCalciteUtil.java:
##########
@@ -1272,6 +1272,28 @@ public static boolean
hasAllExpressionsFromRightSide(RelNode joinRel, List<RexNo
return true;
}
+ /**
+ * Checks the operands in the join conditions are from right table or only
from left table.
+ *
+ * @param joinRel Join node
+ * @return true if the join condition operands are from right and left
table, false otherwise.
+ */
+ public static boolean hasJoinConditionOperandFromRightTable(Join joinRel) {
+ RexNode condition = joinRel.getCondition();
+ RelNode leftRel = joinRel.getLeft();
+ int leftFieldCount = leftRel.getRowType().getFieldCount();
+ ImmutableBitSet leftBitmap = ImmutableBitSet.range(leftFieldCount);
Review Comment:
nit:
1. The method name says that it looks for references in the join condition
coming from the right side. However the implementation search for references in
the left side only.
It seems to be valid to assume that if a reference is not in the left side
then it must be in the right. It just not what I expect when reading the method
name and the implementation.
2. Is the right side always a table (TableScan), or can it be any subtree?
If it’s the latter, then the word Table is misleading.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]