diff --git a/src/sql/src/statements.rs b/src/sql/src/statements.rs index eaa6b1480871..a8f38e545d59 100644 --- a/src/sql/src/statements.rs +++ b/src/sql/src/statements.rs @@ -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)), + "1" => Ok(Value::Boolean(true)), + _ => ParseSqlValueSnafu { + msg: format!("Failed to parse number '{}' to boolean column type", $n)}.fail(), + } + } _ => ParseSqlValueSnafu { msg: format!("Fail to parse number {}, invalid column type: {:?}", $n, $data_type @@ -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] @@ -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);