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: treat "0" and "1" as valid boolean values. #3370

Merged
Changes from 1 commit
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
19 changes: 16 additions & 3 deletions src/sql/src/statements.rs
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,15 @@ macro_rules! parse_number_to_value {
}.fail()
}
}

// It's valid for MySQL JDBC to send "0" and "1" for boolean types, so adapt to that.
ConcreteDataType::Boolean(_) => {
match $n {
"0" => Ok(Value::Boolean(false)),
tisonkun marked this conversation as resolved.
Show resolved Hide resolved
"1" => Ok(Value::Boolean(true)),
_ => ParseSqlValueSnafu {
msg: format!("Failed to parse number '{}' to boolean column type!", $n)}.fail(),
MichaelScofield marked this conversation as resolved.
Show resolved Hide resolved
}
}
_ => ParseSqlValueSnafu {
msg: format!("Fail to parse number {}, invalid column type: {:?}",
$n, $data_type
Expand Down Expand Up @@ -646,6 +654,12 @@ mod tests {

let v = sql_number_to_value(&ConcreteDataType::string_datatype(), "999");
assert!(v.is_err(), "parse value error is: {v:?}");

let v = sql_number_to_value(&ConcreteDataType::boolean_datatype(), "0").unwrap();
assert_eq!(v, Value::Boolean(false));
let v = sql_number_to_value(&ConcreteDataType::boolean_datatype(), "1").unwrap();
assert_eq!(v, Value::Boolean(true));
assert!(sql_number_to_value(&ConcreteDataType::boolean_datatype(), "2").is_err());
}

#[test]
Expand All @@ -671,8 +685,7 @@ mod tests {
let sql_val = SqlValue::Number("3.0".to_string(), false);
let v = sql_value_to_value("a", &ConcreteDataType::boolean_datatype(), &sql_val, None);
assert!(v.is_err());
assert!(format!("{v:?}")
.contains("Fail to parse number 3.0, invalid column type: Boolean(BooleanType)"));
assert!(format!("{v:?}").contains("Failed to parse number '3.0' to boolean column type!"));

let sql_val = SqlValue::Boolean(true);
let v = sql_value_to_value("a", &ConcreteDataType::float64_datatype(), &sql_val, None);
Expand Down