Skip to content

Commit

Permalink
feat: support inserting into binary value through string (#4197)
Browse files Browse the repository at this point in the history
feat: support inserting binary by string
  • Loading branch information
CookiePieWw authored Jul 8, 2024
1 parent e5730a3 commit 8e69543
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/datatypes/src/data_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ impl ConcreteDataType {
| ConcreteDataType::Interval(_)
| ConcreteDataType::Duration(_)
| ConcreteDataType::Decimal128(_)
| ConcreteDataType::Binary(_)
)
}

Expand Down Expand Up @@ -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());
Expand Down
9 changes: 9 additions & 0 deletions src/sql/src/statements.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ fn parse_string_to_value(
.fail()
}
}
ConcreteDataType::Binary(_) => Ok(Value::Binary(s.as_bytes().into())),
_ => {
unreachable!()
}
Expand Down Expand Up @@ -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());
Expand Down

0 comments on commit 8e69543

Please sign in to comment.