Weiwei Su created FLINK-41616:
---------------------------------

             Summary: NullPointerException in 
RelMdPredicates$JoinConditionBasedPredicateInference for uncorrelated IN 
subquery in LEFT/RIGHT/FULL JOIN ON
                 Key: FLINK-41616
                 URL: https://issues.apache.org/jira/browse/FLINK-41616
             Project: Flink
          Issue Type: Bug
          Components: Table SQL / Planner
    Affects Versions: 2.3.0, 1.19.1
         Environment: Apache Flink 1.19.1 and 2.3.0 (SQL Gateway, batch 
execution mode, VALUES-only / connector-independent)

            Reporter: Weiwei Su


h3. Summary
In Flink SQL batch mode (reproduced 3/3 times on both Flink 1.19.1 and Flink 
2.3.0), an uncorrelated {{IN (subquery)}} predicate in the {{ON}} clause of a 
{{LEFT}}, {{RIGHT}}, or {{FULL}} outer join throws an internal 
{{NullPointerException}} during Calcite predicate inference:
{{java.lang.NullPointerException: equivalence.get(p2) for 2}}
at 
{{org.apache.calcite.rel.metadata.RelMdPredicates$JoinConditionBasedPredicateInference.markAsEquivalent(RelMdPredicates.java:778)}}.

The reproducer uses only {{VALUES}} (connector-independent). Spark and Trino 
both execute the same query successfully.

h3. Minimal Reproducer
{code:sql}
SELECT l.id AS left_id, r.id AS right_id
FROM (VALUES (CAST(1 AS INTEGER)), (CAST(2 AS INTEGER))) AS l(id)
LEFT JOIN (VALUES (CAST(1 AS INTEGER)), (CAST(3 AS INTEGER))) AS r(id)
  ON l.id IN (
    SELECT q.id
    FROM (VALUES (CAST(1 AS INTEGER)), (CAST(2 AS INTEGER)), (CAST(NULL AS 
INTEGER))) AS q(id)
  )
ORDER BY left_id, right_id;
{code}

(Also reproduces 3/3 with {{RIGHT JOIN}} and {{FULL JOIN}}.)

h3. Observed Error
{code:text}
Caused by: java.lang.NullPointerException: equivalence.get(p2) for 2
  at 
org.apache.calcite.rel.metadata.RelMdPredicates$JoinConditionBasedPredicateInference.markAsEquivalent(RelMdPredicates.java:778)
  at 
org.apache.calcite.rel.metadata.RelMdPredicates$JoinConditionBasedPredicateInference$EquivalenceFinder.visitCall(RelMdPredicates.java:796)
  at 
org.apache.calcite.rel.metadata.RelMdPredicates$JoinConditionBasedPredicateInference.<init>(RelMdPredicates.java:618)
{code}

h3. Expected Behavior
The query should plan and execute without a {{NullPointerException}} in 
{{RelMdPredicates}} (matching Spark and Trino).




--
This message was sent by Atlassian Jira
(v10.3.26#10030026)

Reply via email to