Skip to content

Commit 2d5fe19

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

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
@@ -218,7 +218,7 @@ private static DataType convertFromColumn(Column column) {
218218
case MULTILINESTRING:
219219
return DataTypes.STRING();
220220
case BINARY:
221-
return DataTypes.BINARY(column.length());
221+
return DataTypes.BINARY(column.length() > 0 ? column.length() : 1);
222222
case VARBINARY:
223223
return DataTypes.VARBINARY(column.length());
224224
case TINYBLOB:

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
@@ -301,6 +301,16 @@ public void testParseAlterStatement() throws Exception {
301301
Collections.singletonList(
302302
new AddColumnEvent.ColumnWithPosition(
303303
Column.physicalColumn("cols5", DataTypes.BOOLEAN())))));
304+
statement.execute(
305+
String.format(
306+
"ALTER TABLE `%s`.`products` ADD COLUMN `cols6` BINARY NULL;",
307+
inventoryDatabase.getDatabaseName()));
308+
expected.add(
309+
new AddColumnEvent(
310+
tableId,
311+
Collections.singletonList(
312+
new AddColumnEvent.ColumnWithPosition(
313+
Column.physicalColumn("cols6", DataTypes.BINARY(1))))));
304314
}
305315
List<Event> actual = fetchResults(events, expected.size());
306316
assertThat(actual).isEqualTo(expected);

0 commit comments

Comments
 (0)