Skip to content

Commit

Permalink
fix(mysql-cdc): fix mysql enum type default value (#19192)
Browse files Browse the repository at this point in the history
  • Loading branch information
StrikeW authored Nov 2, 2024
1 parent d9ee9b4 commit 3a8d5a8
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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)
);
Expand Down
24 changes: 22 additions & 2 deletions src/connector/src/source/cdc/external/mysql.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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))),
Expand All @@ -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
Expand Down

0 comments on commit 3a8d5a8

Please sign in to comment.