Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(mysql-cdc): fix mysql enum type default value #19192

Merged
merged 2 commits into from
Nov 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading