Apache DataFusion SQL Query Engine
feat: ScalarValue from String (#8411)
Wei2e5ad7a3cb3b
diff --git a/datafusion/common/src/scalar.rs b/datafusion/common/src/scalar.rsindex ef0edbd9e0..177fe00a6a 100644--- a/datafusion/common/src/scalar.rs+++ b/datafusion/common/src/scalar.rs@@ -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@@ -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));