This is an automated email from the ASF dual-hosted git repository.

JingsongLi pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/paimon.git


The following commit(s) were added to refs/heads/master by this push:
     new 91208b464d [cdc] Return an empty string for canal/aliyun enum index 0 
(#10371)
91208b464d is described below

commit 91208b464d26eaca5e4f3c44ec40ee71cb4e6601
Author: jackylee <[email protected]>
AuthorDate: Mon Oct 5 20:44:51 2026 +0800

    [cdc] Return an empty string for canal/aliyun enum index 0 (#10371)
---
 .../cdc/format/aliyun/AliyunFieldParser.java       |  5 +++
 .../action/cdc/format/canal/CanalFieldParser.java  |  5 +++
 .../cdc/format/aliyun/AliyunFieldParserTest.java   | 37 ++++++++++++++++++++++
 .../cdc/format/canal/CanalFieldParserTest.java     | 37 ++++++++++++++++++++++
 4 files changed, 84 insertions(+)

diff --git 
a/paimon-flink/paimon-flink-cdc/src/main/java/org/apache/paimon/flink/action/cdc/format/aliyun/AliyunFieldParser.java
 
b/paimon-flink/paimon-flink-cdc/src/main/java/org/apache/paimon/flink/action/cdc/format/aliyun/AliyunFieldParser.java
index 824ed91459..13e371483d 100644
--- 
a/paimon-flink/paimon-flink-cdc/src/main/java/org/apache/paimon/flink/action/cdc/format/aliyun/AliyunFieldParser.java
+++ 
b/paimon-flink/paimon-flink-cdc/src/main/java/org/apache/paimon/flink/action/cdc/format/aliyun/AliyunFieldParser.java
@@ -70,6 +70,11 @@ public class AliyunFieldParser {
     protected static String getEnumValueByIndex(String mysqlType, int 
elementIndex) {
         String[] options = extractEnumValueByIndex(mysqlType);
 
+        // MySQL uses enum index 0 for an empty or invalid value; map it to 
the empty
+        // string instead of indexing options[-1].
+        if (elementIndex <= 0) {
+            return "";
+        }
         return options[elementIndex - 1];
     }
 
diff --git 
a/paimon-flink/paimon-flink-cdc/src/main/java/org/apache/paimon/flink/action/cdc/format/canal/CanalFieldParser.java
 
b/paimon-flink/paimon-flink-cdc/src/main/java/org/apache/paimon/flink/action/cdc/format/canal/CanalFieldParser.java
index 6dcca098e8..5f2fbe4c07 100644
--- 
a/paimon-flink/paimon-flink-cdc/src/main/java/org/apache/paimon/flink/action/cdc/format/canal/CanalFieldParser.java
+++ 
b/paimon-flink/paimon-flink-cdc/src/main/java/org/apache/paimon/flink/action/cdc/format/canal/CanalFieldParser.java
@@ -70,6 +70,11 @@ public class CanalFieldParser {
     protected static String getEnumValueByIndex(String mysqlType, int 
elementIndex) {
         String[] options = extractEnumValueByIndex(mysqlType);
 
+        // MySQL uses enum index 0 for an empty or invalid value; map it to 
the empty
+        // string instead of indexing options[-1].
+        if (elementIndex <= 0) {
+            return "";
+        }
         return options[elementIndex - 1];
     }
 
diff --git 
a/paimon-flink/paimon-flink-cdc/src/test/java/org/apache/paimon/flink/action/cdc/format/aliyun/AliyunFieldParserTest.java
 
b/paimon-flink/paimon-flink-cdc/src/test/java/org/apache/paimon/flink/action/cdc/format/aliyun/AliyunFieldParserTest.java
new file mode 100644
index 0000000000..51cdf19388
--- /dev/null
+++ 
b/paimon-flink/paimon-flink-cdc/src/test/java/org/apache/paimon/flink/action/cdc/format/aliyun/AliyunFieldParserTest.java
@@ -0,0 +1,37 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.paimon.flink.action.cdc.format.aliyun;
+
+import org.junit.jupiter.api.Test;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+/** Unit tests for {@link AliyunFieldParser}. */
+public class AliyunFieldParserTest {
+
+    @Test
+    public void testEnumIndexZeroMapsToEmptyString() {
+        // MySQL stores enum index 0 for an empty or invalid value, so it must 
map to the empty
+        // string rather than indexing options[-1] and throwing 
ArrayIndexOutOfBoundsException.
+        assertThat(AliyunFieldParser.getEnumValueByIndex("enum('a','b','c')", 
0)).isEmpty();
+        // Valid 1-based indices still resolve to their members.
+        assertThat(AliyunFieldParser.getEnumValueByIndex("enum('a','b','c')", 
1)).isEqualTo("a");
+        assertThat(AliyunFieldParser.getEnumValueByIndex("enum('a','b','c')", 
3)).isEqualTo("c");
+    }
+}
diff --git 
a/paimon-flink/paimon-flink-cdc/src/test/java/org/apache/paimon/flink/action/cdc/format/canal/CanalFieldParserTest.java
 
b/paimon-flink/paimon-flink-cdc/src/test/java/org/apache/paimon/flink/action/cdc/format/canal/CanalFieldParserTest.java
new file mode 100644
index 0000000000..0f6b650064
--- /dev/null
+++ 
b/paimon-flink/paimon-flink-cdc/src/test/java/org/apache/paimon/flink/action/cdc/format/canal/CanalFieldParserTest.java
@@ -0,0 +1,37 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.paimon.flink.action.cdc.format.canal;
+
+import org.junit.jupiter.api.Test;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+/** Unit tests for {@link CanalFieldParser}. */
+public class CanalFieldParserTest {
+
+    @Test
+    public void testEnumIndexZeroMapsToEmptyString() {
+        // MySQL stores enum index 0 for an empty or invalid value, so it must 
map to the empty
+        // string rather than indexing options[-1] and throwing 
ArrayIndexOutOfBoundsException.
+        assertThat(CanalFieldParser.getEnumValueByIndex("enum('a','b','c')", 
0)).isEmpty();
+        // Valid 1-based indices still resolve to their members.
+        assertThat(CanalFieldParser.getEnumValueByIndex("enum('a','b','c')", 
1)).isEqualTo("a");
+        assertThat(CanalFieldParser.getEnumValueByIndex("enum('a','b','c')", 
3)).isEqualTo("c");
+    }
+}

Reply via email to