Skip to content

Commit

Permalink
feat: ScalarValue from String (#8411)
Browse files Browse the repository at this point in the history
* feat: scalar from string

* chore: cr comment
  • Loading branch information
QuenKar authored Dec 5, 2023
1 parent d1554c8 commit 2e5ad7a
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 @@ -3065,6 +3065,12 @@ impl FromStr for ScalarValue {
}
}

impl From<String> for ScalarValue {
fn from(value: String) -> Self {
ScalarValue::Utf8(Some(value))
}
}

impl From<Vec<(&str, ScalarValue)>> for ScalarValue {
fn from(value: Vec<(&str, ScalarValue)>) -> Self {
let (fields, scalars): (SchemaBuilder, Vec<_>) = value
Expand Down Expand Up @@ -4688,6 +4694,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 2e5ad7a

Please sign in to comment.