[ 
https://issues.apache.org/jira/browse/FLINK-41773?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18153874#comment-18153874
 ] 

Yanquan Lv commented on FLINK-41773:
------------------------------------

Assigned.

> [pipeline-connector/iceberg] Iceberg sink keeps column required after 
> AlterColumnTypeEvent makes it nullable, writing null fails
> --------------------------------------------------------------------------------------------------------------------------------
>
>                 Key: FLINK-41773
>                 URL: https://issues.apache.org/jira/browse/FLINK-41773
>             Project: Flink
>          Issue Type: Bug
>          Components: Flink CDC
>    Affects Versions: cdc-3.7.0
>         Environment: Flink CDC 3.7.0 and master (d7f6adedd85c), Flink 1.20.3 
> and 2.2.0, Iceberg 1.10.1, MySQL 8.0
>            Reporter: Kensuke Fukumoto
>            Assignee: Kensuke Fukumoto
>            Priority: Major
>
> h2. Description
> When an upstream column changes from {{NOT NULL}} to nullable, the Flink CDC 
> pipeline emits an {{AlterColumnTypeEvent}} whose new type is nullable. 
> {{IcebergMetadataApplier.applyAlterColumnType}} only calls 
> {{UpdateSchema.updateColumn(name, type)}}, which updates the primitive type 
> but not the nullability. The Iceberg field stays {{required}}, while the 
> writer's schema is already nullable. The first row with a null value in the 
> column fails with a {{NullPointerException}} in the Parquet writer, and the 
> job keeps failing over.
> The same happens with {{schema.change.behavior: lenient}}, where a 
> {{DropColumnEvent}} is turned into an {{AlterColumnTypeEvent}} that makes the 
> column nullable (see GitHub PR #4372, closed without being merged).
> Proposed fix: call {{UpdateSchema.makeColumnOptional}} when the new type is 
> nullable and the Iceberg field is required (a compatible change in Iceberg). 
> Identifier fields stay required. The opposite direction (nullable to {{NOT 
> NULL}}) is not applied.
> h2. Steps to reproduce
> # Create a MySQL table and start a pipeline {{MySQL source -> Iceberg sink}} 
> with {{schema.change.behavior: evolve}}:
> {code:sql}
> CREATE TABLE users (id BIGINT PRIMARY KEY, name VARCHAR(255) NOT NULL);
> INSERT INTO users VALUES (1, 'alice');
> {code}
> # Relax the constraint and insert a null value:
> {code:sql}
> ALTER TABLE users MODIFY name VARCHAR(255) NULL;
> INSERT INTO users VALUES (2, NULL);
> {code}
> # Expected: the Iceberg column {{name}} becomes optional and the table 
> contains {{(1, alice)}} and {{(2, null)}}.
>    Actual: the job fails with
> {code}
> java.lang.NullPointerException
>       at 
> org.apache.iceberg.flink.data.FlinkParquetWriters$StringDataWriter.write(FlinkParquetWriters.java:345)
>       at 
> org.apache.iceberg.parquet.ParquetValueWriters$StructWriter.write(ParquetValueWriters.java:665)
> {code}



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

Reply via email to