Weiwei Su created FLINK-41625:
---------------------------------

             Summary: AssertionError: mismatched type in 
RexUtil$FixNullabilityShuttle when JOIN ON contains OR with EXISTS over chained 
RIGHT JOINs
                 Key: FLINK-41625
                 URL: https://issues.apache.org/jira/browse/FLINK-41625
             Project: Flink
          Issue Type: Bug
          Components: Table SQL / Planner
    Affects Versions: 2.3.0, 1.19.1
         Environment: Apache Flink 2.3.0 (official Docker image 
flink:2.3.0-scala_2.12-java17), SQL Gateway REST API, 
execution.runtime-mode=batch. Also observed on Flink 1.19.1.
            Reporter: Weiwei Su


h3. Summary
In batch execution mode, planning a {{JOIN}} against a derived table ({{GROUP 
BY ... LIMIT}}) whose {{ON}} clause combines an {{EXISTS}} subquery over 
chained {{RIGHT JOIN}}s with an {{OR}} predicate crashes with 
{{java.lang.AssertionError: mismatched type $2 VARCHAR(2147483647)}} inside 
{{org.apache.calcite.rex.RexUtil$FixNullabilityShuttle.visitInputRef}}.

The inner {{EXISTS}} query plans cleanly on its own.

h3. Steps to Reproduce
Run the following self-contained SQL in Flink SQL Client or SQL Gateway (batch 
mode, built-in {{datagen}} connector, no external catalog required):

{code:sql}
SET 'execution.runtime-mode' = 'batch';

CREATE TEMPORARY TABLE t (
  id BIGINT,
  v INT,
  s STRING
) WITH (
  'connector' = 'datagen',
  'number-of-rows' = '10'
);

EXPLAIN PLAN FOR
SELECT 1
FROM t t3
JOIN (
  SELECT t5.v, t5.s
  FROM t t5
  GROUP BY t5.v, t5.s
  LIMIT 5
) sq4
  ON (
    t3.v > sq4.v
    AND EXISTS (
      SELECT 1
      FROM t t5
      RIGHT JOIN t t6 ON t6.id <= 1
      RIGHT JOIN t t7 ON 'b' < t5.s
    )
  )
  OR t3.id IS NOT NULL;
{code}

h3. Actual Behavior
Planning crashes with an internal {{AssertionError}} in 
{{RexUtil$FixNullabilityShuttle}}:

{noformat}
Caused by: java.lang.AssertionError: mismatched type $2 VARCHAR(2147483647)
  at 
org.apache.calcite.rex.RexUtil$FixNullabilityShuttle.visitInputRef(RexUtil.java:2860)
  at 
org.apache.calcite.rex.RexUtil$FixNullabilityShuttle.visitInputRef(RexUtil.java:2837)
{noformat}

h3. Expected Behavior
The planner should preserve input reference types consistently during subquery 
decorrelation / nullability fixing and produce a valid execution plan.




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

Reply via email to