This is an automated email from the ASF dual-hosted git repository.
hyuan pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/calcite.git
The following commit(s) were added to refs/heads/master by this push:
new fe9766aaa [CALCITE-5032] RelOptUtil#splitJoinCondition returns wrong
when there is no equal condition
fe9766aaa is described below
commit fe9766aaa5739f59f757206c57c1b9cc071cd6f6
Author: Benchao Li <[email protected]>
AuthorDate: Sun Mar 27 21:49:16 2022 +0800
[CALCITE-5032] RelOptUtil#splitJoinCondition returns wrong when there is no
equal condition
---
.../java/org/apache/calcite/plan/RelOptUtil.java | 35 ----------------------
.../org/apache/calcite/plan/RelOptUtilTest.java | 22 ++++++++++++++
2 files changed, 22 insertions(+), 35 deletions(-)
diff --git a/core/src/main/java/org/apache/calcite/plan/RelOptUtil.java
b/core/src/main/java/org/apache/calcite/plan/RelOptUtil.java
index f1e8b13b7..c7b5c7cbc 100644
--- a/core/src/main/java/org/apache/calcite/plan/RelOptUtil.java
+++ b/core/src/main/java/org/apache/calcite/plan/RelOptUtil.java
@@ -1387,41 +1387,6 @@ public abstract class RelOptUtil {
}
}
- if ((rangeOp == null)
- && ((leftKey == null) || (rightKey == null))) {
- // no equality join keys found yet:
- // try transforming the condition to
- // equality "join" conditions, e.g.
- // f(LHS) > 0 ===> ( f(LHS) > 0 ) = TRUE,
- // and make the RHS produce TRUE, but only if we're strictly
- // looking for equi-joins
- final ImmutableBitSet projRefs = InputFinder.bits(condition);
- leftKey = null;
- rightKey = null;
-
- boolean foundInput = false;
- for (int i = 0; i < inputs.size() && !foundInput; i++) {
- if (inputsRange[i].contains(projRefs)) {
- leftInput = i;
- leftFields = inputs.get(leftInput).getRowType().getFieldList();
-
- leftKey = condition.accept(
- new RelOptUtil.RexInputConverter(
- rexBuilder,
- leftFields,
- leftFields,
- adjustments));
-
- rightKey = rexBuilder.makeLiteral(true);
-
- // effectively performing an equality comparison
- kind = SqlKind.EQUALS;
-
- foundInput = true;
- }
- }
- }
-
if ((leftKey != null) && (rightKey != null)) {
// found suitable join keys
// add them to key list, ensuring that if there is a
diff --git a/core/src/test/java/org/apache/calcite/plan/RelOptUtilTest.java
b/core/src/test/java/org/apache/calcite/plan/RelOptUtilTest.java
index ce571c33c..2f22e78ee 100644
--- a/core/src/test/java/org/apache/calcite/plan/RelOptUtilTest.java
+++ b/core/src/test/java/org/apache/calcite/plan/RelOptUtilTest.java
@@ -56,6 +56,7 @@ import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.Collections;
import java.util.List;
@@ -285,6 +286,27 @@ class RelOptUtilTest {
relBuilder.literal(true));
}
+ @Test void testSplitJoinConditionWithoutEqualCondition() {
+ final List<RelDataTypeField> sysFieldList = Collections.emptyList();
+ final List<List<RexNode>> joinKeys = Arrays.asList(new ArrayList<>(), new
ArrayList<>());
+ final RexNode joinCondition = relBuilder.equals(
+ RexInputRef.of(0, empDeptJoinRelFields),
+ relBuilder.literal(1));
+ final RexNode result = RelOptUtil.splitJoinCondition(
+ sysFieldList,
+ Arrays.asList(empScan, deptScan),
+ joinCondition,
+ joinKeys,
+ null,
+ null
+ );
+ final List<List<RexNode>> expectedJoinKeys = Arrays.asList(
+ Collections.emptyList(),
+ Collections.emptyList());
+ assertEquals(joinKeys, expectedJoinKeys);
+ assertEquals(result, joinCondition);
+ }
+
/**
* Test {@link RelOptUtil#splitJoinCondition(RelNode, RelNode, RexNode,
List, List, List)}
* where the join condition contains just one which is a IS NOT DISTINCT
operator.