Vladimir Steshin created IGNITE-26048:
-----------------------------------------
Summary: Calcite. Incorrect processing of IS NOT DISTINCT
condition in MergeJoin.
Key: IGNITE-26048
URL: https://issues.apache.org/jira/browse/IGNITE-26048
Project: Ignite
Issue Type: Bug
Affects Versions: 2.17
Reporter: Vladimir Steshin
*Reproducer:*
{code:java}
@RunWith(Parameterized.class) public class JoinIntegrationTest extends
AbstractBasicIntegrationTransactionalTest {
@Test public void testIsNotDistinctFrom() {
assertQuery("select t1.c1, t2.c1, t2.c2 from t1 join t2 on t1.c2 is not
distinct from t2.c2 and t1.c1 = t2.c3 - 1")
.returns(2, 3, null)
.check();
}
}
{code}
*Error:*
{code:java}
Test failed
[test=JoinIntegrationTest#testIsNotDistinctFrom[sqlTxMode=ALL,joinType=MERGE],
duration=117]
java.lang.AssertionError: Collections sizes are not equal:
Expected: [[2, 3, null]] Actual: []
expected:<1> but was:<0> {code}
*Note:*
Works for _NL_JOIN_ and {_}CNL_JOIN{_}.
*Suppose:*
We incorrectly parse join condition in `{_}MergeJoinConverterRule{_}`:
{code:java}
@Override public boolean matchesJoin(RelOptRuleCall call) {
LogicalJoin logicalJoin = call.rel(0);
return !F.isEmpty(logicalJoin.analyzeCondition().pairs()) &&
logicalJoin.analyzeCondition().isEqui();
} {code}
and when creating the comparator in
`{_}LogicalRelImplementor#visit(IgniteMergeJoin rel){_}`:
{code:java}
Comparator<Row> comp = expressionFactory.comparator(
rel.leftCollation().getFieldCollations().subList(0, pairsCnt),
rel.rightCollation().getFieldCollations().subList(0, pairsCnt),
rel.getCondition().getKind() == IS_NOT_DISTINCT_FROM ||
rel.getCondition().getKind() == IS_DISTINCT_FROM
);
Node<Row> node = MergeJoinNode.create(ctx, outType, leftType, rightType,
joinType, comp, hasExchange(rel)); {code}
We assume that there is only one pair or all of the pairs are of _equi_
condition or of {_}distinct/is not distinct{_}. But only one of several the
conditions might be {_}is not distinct{_}.
*Suggestions:*
# Disable _MergeJoin_ for this case for a while.
# Use more intelligent join condition analysis like
`{_}RelOptUtil#splitJoinCondition(){_}` and use separated comparators in merge
join node for join pair entries.
--
This message was sent by Atlassian Jira
(v8.20.10#820010)