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

Kensuke Fukumoto commented on FLINK-41774:
------------------------------------------

Hi, I'd like to work on this issue. Could someone assign it to me?

My understanding: MySqlTypeUtils declares SET columns as ARRAY<STRING>, but the 
values are built from the Debezium value schema, where a SET is a comma 
separated string (io.debezium.data.EnumSet) inferred as STRING. The record 
therefore holds a string in a field declared as an array.

Proposed change: infer ARRAY<STRING> for io.debezium.data.EnumSet in 
MySqlSchemaDataTypeInference, and split the string into an array in 
MySqlEventDeserializer (the empty set becomes an empty array). This matches 
what the MySQL SQL connector already does in 
MySqlDeserializationConverterFactory.

I have a fix with a new unit test that fails on master and passes with the 
change; MySqlFullTypesITCase, MySqlPipelineITCase and the rest of the module 
tests pass on both Flink 1.20 and -Pflink2. This is independent of FLINK-41775 
(Iceberg sink ARRAY support), but both are needed for SET columns to reach an 
Iceberg table. I'll open a PR once the issue is assigned.


> [connect/mysql] MySQL pipeline source declares SET columns as ARRAY<STRING> 
> but emits the values as STRING
> ----------------------------------------------------------------------------------------------------------
>
>                 Key: FLINK-41774
>                 URL: https://issues.apache.org/jira/browse/FLINK-41774
>             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
> {{MySqlTypeUtils}} maps MySQL {{SET}} columns to {{ARRAY<STRING>}} in the 
> table schema of {{CreateTableEvent}} / {{AddColumnEvent}}. The values in 
> {{DataChangeEvent}}s, however, are built from the Debezium value schema. 
> Debezium represents a {{SET}} value as a comma separated string with the 
> logical name {{io.debezium.data.EnumSet}}, which 
> {{DebeziumSchemaDataTypeInference}} maps to {{STRING}}. The record therefore 
> stores a string where the schema says array.
> A sink that reads the field with the declared type reads string bytes as an 
> array and fails, e.g. with {{IndexOutOfBoundsException}} in 
> {{BinaryArrayData.pointTo}}.
> The MySQL SQL connector already handles this 
> ({{MySqlDeserializationConverterFactory}} splits the string into an array); 
> the pipeline source does not.
> Proposed fix: infer {{ARRAY<STRING>}} for {{io.debezium.data.EnumSet}} in 
> {{MySqlSchemaDataTypeInference}}, and split the string in 
> {{MySqlEventDeserializer}} (the empty set becomes an empty array).
> h2. Steps to reproduce
> # Start a pipeline {{MySQL source -> Iceberg sink}} (with ARRAY support, see 
> the linked issue) on:
> {code:sql}
> CREATE TABLE items (id INT PRIMARY KEY, title VARCHAR(64));
> {code}
> # Run:
> {code:sql}
> ALTER TABLE items ADD COLUMN tags SET('a', 'b', 'c');
> INSERT INTO items VALUES (2, 'cup', 'a,b');
> {code}
> # Expected: the row {{(2, cup, [a, b])}}.
>    Actual:
> {code}
> java.lang.IndexOutOfBoundsException
>       at 
> org.apache.flink.core.memory.MemorySegment.getInt(MemorySegment.java:801)
>       at 
> org.apache.flink.cdc.common.data.binary.BinarySegmentUtils.getInt(BinarySegmentUtils.java:632)
>       at 
> org.apache.flink.cdc.common.data.binary.BinaryArrayData.pointTo(BinaryArrayData.java:181)
> {code}
> The mismatch can also be seen without a sink: the {{DataChangeEvent}} 
> produced for the row above carries {{BinaryStringData("a,b")}} in a field 
> whose schema type is {{ARRAY<STRING>}}.



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

Reply via email to