From 8e695437047d3b76c540bd1478360ee6d6971315 Mon Sep 17 00:00:00 2001 From: Yohan Wal <59358312+CookiePieWw@users.noreply.github.com> Date: Mon, 8 Jul 2024 20:09:30 +0800 Subject: [PATCH] feat: support inserting into binary value through string (#4197) feat: support inserting binary by string --- src/datatypes/src/data_type.rs | 2 ++ src/sql/src/statements.rs | 9 +++++++++ 2 files changed, 11 insertions(+) diff --git a/src/datatypes/src/data_type.rs b/src/datatypes/src/data_type.rs index f74a94c7a14f..262110dbf53b 100644 --- a/src/datatypes/src/data_type.rs +++ b/src/datatypes/src/data_type.rs @@ -161,6 +161,7 @@ impl ConcreteDataType { | ConcreteDataType::Interval(_) | ConcreteDataType::Duration(_) | ConcreteDataType::Decimal128(_) + | ConcreteDataType::Binary(_) ) } @@ -717,6 +718,7 @@ mod tests { assert!(!ConcreteDataType::int32_datatype().is_stringifiable()); assert!(!ConcreteDataType::float32_datatype().is_stringifiable()); assert!(ConcreteDataType::string_datatype().is_stringifiable()); + assert!(ConcreteDataType::binary_datatype().is_stringifiable()); assert!(ConcreteDataType::date_datatype().is_stringifiable()); assert!(ConcreteDataType::datetime_datatype().is_stringifiable()); assert!(ConcreteDataType::timestamp_second_datatype().is_stringifiable()); diff --git a/src/sql/src/statements.rs b/src/sql/src/statements.rs index de35b71a90a8..4d27453cefd1 100644 --- a/src/sql/src/statements.rs +++ b/src/sql/src/statements.rs @@ -120,6 +120,7 @@ fn parse_string_to_value( .fail() } } + ConcreteDataType::Binary(_) => Ok(Value::Binary(s.as_bytes().into())), _ => { unreachable!() } @@ -710,6 +711,14 @@ mod tests { sql_value_to_value("a", &ConcreteDataType::binary_datatype(), &sql_val, None).unwrap(); assert_eq!(Value::Binary(Bytes::from(b"Hello world!".as_slice())), v); + let sql_val = SqlValue::DoubleQuotedString("MorningMyFriends".to_string()); + let v = + sql_value_to_value("a", &ConcreteDataType::binary_datatype(), &sql_val, None).unwrap(); + assert_eq!( + Value::Binary(Bytes::from(b"MorningMyFriends".as_slice())), + v + ); + let sql_val = SqlValue::HexStringLiteral("9AF".to_string()); let v = sql_value_to_value("a", &ConcreteDataType::binary_datatype(), &sql_val, None); assert!(v.is_err());