Fred Teunissen created FLINK-39247:
--------------------------------------

             Summary: ClassCastException when executing INSERT INTO with nested 
ROW containing NOT NULL MAP in Flink 2.2.0
                 Key: FLINK-39247
                 URL: https://issues.apache.org/jira/browse/FLINK-39247
             Project: Flink
          Issue Type: Bug
          Components: Table SQL / Planner, Table SQL / Runtime
    Affects Versions: 2.2.0
            Reporter: Fred Teunissen


*Overview*

A breaking change has been introduced in Flink 2.2.0 where executing an INSERT 
INTO statement with nested ROW types containing NOT NULL MAP fields fails with 
a ClassCastException. The exact same SQL statements execute without issues in 
Flink 1.20.3 and 2.1.1.

*Affected Scenario*

INSERT INTO queries that reference deeply nested ROW structures with NOT NULL 
constraints on MAP fields and use MAP_ENTRIES() with UNNEST fail in Flink 2.2.0.

*Failing SQL Statement*
_Table Definitions_
{code:sql}
CREATE TABLE orders (
    outerRow ROW<
            innerRow ROW<
                    headers MAP<STRING NOT NULL, STRING NOT NULL> NOT NULL
            >
        > NOT NULL,
        ingestionTime TIMESTAMP(3),
        WATERMARK FOR ingestionTime AS ingestionTime
) WITH (
    'connector' = 'datagen',
    'rows-per-second' = '2',
    'number-of-rows' = '10'
);

CREATE TABLE blackhole_table (key STRING) WITH ('connector' = 'blackhole');
{code}

*Query (Works in 1.20.3 and 2.1.1, fails in 2.2.0)*
{code:sql}
INSERT INTO blackhole_table
SELECT
    unnestedEntry.key
FROM orders
CROSS JOIN UNNEST (MAP_ENTRIES(orders.outerRow.innerRow.headers)) as 
unnestedEntry;
{code}

*Error Message*
{code:none}
[ERROR] Could not execute SQL statement. Reason:
java.lang.ClassCastException: class org.apache.calcite.rex.RexCall cannot be 
cast to class org.apache.calcite.rex.RexFieldAccess
    (org.apache.calcite.rex.RexCall and org.apache.calcite.rex.RexFieldAccess 
are in unnamed module of loader 
org.apache.flink.table.planner.loader.PlannerModule$PlannerComponentClassLoader 
@42bc14c1)
{code}

*Expected Behavior*
The INSERT INTO statement should execute successfully, accessing the nested 
field orders.outerRow.innerRow.headers and extracting keys from the MAP via 
MAP_ENTRIES() and UNNEST. The query should produce output without errors.



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to