[
https://issues.apache.org/jira/browse/FLINK-41773?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18153840#comment-18153840
]
Kensuke Fukumoto commented on FLINK-41773:
------------------------------------------
Hi, I'd like to work on this issue. Could someone assign it to me?
My understanding: IcebergMetadataApplier#applyAlterColumnType only calls
UpdateSchema#updateColumn(name, type), which changes the primitive type but not
the nullability, so the Iceberg field stays required while the writer already
sends nulls.
Proposed change: in applyAlterColumnType, when the new type is nullable and the
Iceberg field is required, also call UpdateSchema#makeColumnOptional (a
compatible change in Iceberg). Identifier fields are left required, and the
opposite direction (nullable to NOT NULL) is not applied, since it would need
allowIncompatibleChanges() and existing rows may contain nulls.
I have a fix with a unit test in IcebergWriterTest that fails on master and
passes with the change; it passes the module tests and IcebergSinkITCase on
both Flink 1.20 and -Pflink2. I'll open a PR once the issue is 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
> 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)