Skip to content

Commit 2e5ad7a

Browse files
authored
feat: ScalarValue from String (#8411)
* feat: scalar from string * chore: cr comment
1 parent d1554c8 commit 2e5ad7a

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

datafusion/common/src/scalar.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3065,6 +3065,12 @@ impl FromStr for ScalarValue {
30653065
}
30663066
}
30673067

3068+
impl From<String> for ScalarValue {
3069+
fn from(value: String) -> Self {
3070+
ScalarValue::Utf8(Some(value))
3071+
}
3072+
}
3073+
30683074
impl From<Vec<(&str, ScalarValue)>> for ScalarValue {
30693075
fn from(value: Vec<(&str, ScalarValue)>) -> Self {
30703076
let (fields, scalars): (SchemaBuilder, Vec<_>) = value
@@ -4688,6 +4694,16 @@ mod tests {
46884694
);
46894695
}
46904696

4697+
#[test]
4698+
fn test_scalar_value_from_string() {
4699+
let scalar = ScalarValue::from("foo");
4700+
assert_eq!(scalar, ScalarValue::Utf8(Some("foo".to_string())));
4701+
let scalar = ScalarValue::from("foo".to_string());
4702+
assert_eq!(scalar, ScalarValue::Utf8(Some("foo".to_string())));
4703+
let scalar = ScalarValue::from_str("foo").unwrap();
4704+
assert_eq!(scalar, ScalarValue::Utf8(Some("foo".to_string())));
4705+
}
4706+
46914707
#[test]
46924708
fn test_scalar_struct() {
46934709
let field_a = Arc::new(Field::new("A", DataType::Int32, false));

0 commit comments

Comments
 (0)