From 5d96bc5306b8b4488fdbaf079ef441c9c662e634 Mon Sep 17 00:00:00 2001 From: StrikeW Date: Wed, 30 Oct 2024 11:56:17 +0800 Subject: [PATCH 1/2] fix enum default value --- .../src/source/cdc/external/mysql.rs | 24 +++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/src/connector/src/source/cdc/external/mysql.rs b/src/connector/src/source/cdc/external/mysql.rs index c45f6143431d..535a89441014 100644 --- a/src/connector/src/source/cdc/external/mysql.rs +++ b/src/connector/src/source/cdc/external/mysql.rs @@ -121,7 +121,19 @@ impl MySqlExternalTable { DataType::Int16 => Some(ScalarImpl::Int16(val as _)), DataType::Int32 => Some(ScalarImpl::Int32(val as _)), DataType::Int64 => Some(ScalarImpl::Int64(val)), - _ => Err(anyhow!("unexpected default value type for integer column"))?, + DataType::Varchar => { + // should be the Enum type which is mapped to Varchar + Some(ScalarImpl::from(val.to_string())) + } + _ => { + tracing::error!( + column = col_name, + ?data_type, + default_val = val, + "unexpected default value type for column, set default to null" + ); + None + } }, ColumnDefault::Real(val) => match data_type { DataType::Float32 => Some(ScalarImpl::Float32(F32::from(val as f32))), @@ -131,7 +143,15 @@ impl MySqlExternalTable { anyhow!("failed to convert default value to decimal").context(err) })?, )), - _ => Err(anyhow!("unexpected default value type for float column"))?, + _ => { + tracing::error!( + column = col_name, + ?data_type, + default_val = val, + "unexpected default value type for column, set default to null" + ); + None + } }, ColumnDefault::String(mut val) => { // mysql timestamp is mapped to timestamptz, we use UTC timezone to From bc005f643b0321b89d9d1a91ebe97f69b99e5bec Mon Sep 17 00:00:00 2001 From: StrikeW Date: Wed, 30 Oct 2024 14:10:51 +0800 Subject: [PATCH 2/2] add test --- e2e_test/source_legacy/cdc_inline/auto_schema_map_mysql.slt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/e2e_test/source_legacy/cdc_inline/auto_schema_map_mysql.slt b/e2e_test/source_legacy/cdc_inline/auto_schema_map_mysql.slt index 08afa5d1988a..098ddfc8cf02 100644 --- a/e2e_test/source_legacy/cdc_inline/auto_schema_map_mysql.slt +++ b/e2e_test/source_legacy/cdc_inline/auto_schema_map_mysql.slt @@ -32,7 +32,7 @@ mysql --protocol=tcp -u root mytest -e " c_time time, c_datetime datetime, c_timestamp timestamp, - c_enum ENUM('happy','sad','ok'), + c_enum ENUM('happy','sad','ok') DEFAULT 'ok', c_json JSON, PRIMARY KEY (c_boolean,c_Bigint,c_date) );