Skip to content

Commit

Permalink
feat: scalar from string
Browse files Browse the repository at this point in the history
  • Loading branch information
QuenKar committed Dec 2, 2023
1 parent f5d10e5 commit 8458a3b
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions datafusion/common/src/scalar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3022,6 +3022,12 @@ impl FromStr for ScalarValue {
}
}

impl From<String> for ScalarValue {
fn from(value: String) -> Self {
value.as_str().into()
}
}

impl From<Vec<(&str, ScalarValue)>> for ScalarValue {
fn from(value: Vec<(&str, ScalarValue)>) -> Self {
let (fields, scalars): (SchemaBuilder, Vec<_>) = value
Expand Down Expand Up @@ -4645,6 +4651,16 @@ mod tests {
);
}

#[test]
fn test_scalar_value_from_string() {
let scalar = ScalarValue::from("foo");
assert_eq!(scalar, ScalarValue::Utf8(Some("foo".to_string())));
let scalar = ScalarValue::from("foo".to_string());
assert_eq!(scalar, ScalarValue::Utf8(Some("foo".to_string())));
let scalar = ScalarValue::from_str("foo").unwrap();
assert_eq!(scalar, ScalarValue::Utf8(Some("foo".to_string())));
}

#[test]
fn test_scalar_struct() {
let field_a = Arc::new(Field::new("A", DataType::Int32, false));
Expand Down

0 comments on commit 8458a3b

Please sign in to comment.