Skip to content

Commit 5c4d5f2

Browse files
author
zhongqs
committed
[hotfix][cdc-connector][mysql] Fix the default length of CHAR data type of Add column DDL
1 parent 2d5fe19 commit 5c4d5f2

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

flink-cdc-connect/flink-cdc-pipeline-connectors/flink-cdc-pipeline-connector-mysql/src/main/java/org/apache/flink/cdc/connectors/mysql/utils/MySqlTypeUtils.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ private static DataType convertFromColumn(Column column) {
198198
? DataTypes.TIMESTAMP_LTZ(column.length())
199199
: DataTypes.TIMESTAMP_LTZ(0);
200200
case CHAR:
201-
return DataTypes.CHAR(column.length());
201+
return DataTypes.CHAR(column.length() > 0 ? column.length() : 1);
202202
case VARCHAR:
203203
return DataTypes.VARCHAR(column.length());
204204
case TINYTEXT:

flink-cdc-connect/flink-cdc-pipeline-connectors/flink-cdc-pipeline-connector-mysql/src/test/java/org/apache/flink/cdc/connectors/mysql/source/MySqlPipelineITCase.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,16 @@ public void testParseAlterStatement() throws Exception {
311311
Collections.singletonList(
312312
new AddColumnEvent.ColumnWithPosition(
313313
Column.physicalColumn("cols6", DataTypes.BINARY(1))))));
314+
statement.execute(
315+
String.format(
316+
"ALTER TABLE `%s`.`products` ADD COLUMN `cols7` CHAR NULL;",
317+
inventoryDatabase.getDatabaseName()));
318+
expected.add(
319+
new AddColumnEvent(
320+
tableId,
321+
Collections.singletonList(
322+
new AddColumnEvent.ColumnWithPosition(
323+
Column.physicalColumn("cols7", DataTypes.CHAR(1))))));
314324
}
315325
List<Event> actual = fetchResults(events, expected.size());
316326
assertThat(actual).isEqualTo(expected);

0 commit comments

Comments
 (0)