Weiwei Su created FLINK-41615:
---------------------------------

             Summary: CodeGenException: Incomparable types: BIGINT NOT NULL and 
BOOLEAN NOT NULL for RIGHT JOIN with OR + IN subquery inside scalar WHERE
                 Key: FLINK-41615
                 URL: https://issues.apache.org/jira/browse/FLINK-41615
             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), a scalar subquery in {{WHERE}} containing a {{RIGHT JOIN}} whose {{ON}} 
condition combines a comparison and an {{IN (subquery)}} predicate with {{OR}} 
reaches code generation and fails with:
{{org.apache.flink.table.planner.codegen.CodeGenException: Incomparable types: 
BIGINT NOT NULL and BOOLEAN NOT NULL}}.

The query uses only {{VALUES}} (connector-independent). Spark executes the 
exact same query successfully and returns {{[3], [4]}}.

h3. Minimal Reproducer
{code:sql}
SELECT o.id
FROM (VALUES (CAST(1 AS BIGINT)), (CAST(2 AS BIGINT)),
             (CAST(3 AS BIGINT)), (CAST(4 AS BIGINT))) AS o(id)
WHERE (
  SELECT r.id
  FROM (VALUES (CAST(1 AS BIGINT)), (CAST(2 AS BIGINT)),
               (CAST(NULL AS BIGINT))) AS l(id)
  RIGHT JOIN (VALUES (CAST(1 AS BIGINT)),
                     (CAST(3 AS BIGINT))) AS r(id)
    ON l.id >= r.id
    OR l.id IN (SELECT q.id FROM
        (VALUES (CAST(1 AS BIGINT)),
                (CAST(NULL AS BIGINT))) AS q(id))
  ORDER BY r.id DESC
  LIMIT 1
) <= o.id
ORDER BY o.id;
{code}

h3. Observed Error
{code:text}
Caused by: org.apache.flink.table.planner.codegen.CodeGenException: 
Incomparable types: BIGINT NOT NULL and BOOLEAN NOT NULL
{code}

h3. Expected Behavior
The scalar subquery evaluates to {{3}}, so the query should execute without a 
{{CodeGenException}} and return {{3}} and {{4}} (matching Spark).




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

Reply via email to