Kensuke Fukumoto created FLINK-41774:
----------------------------------------
Summary: [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
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)