Skip to content

Commit

Permalink
Add map to ScalarValue::try_from as a list
Browse files Browse the repository at this point in the history
  • Loading branch information
razeghi71 committed Dec 11, 2023
1 parent d091b55 commit b7e9431
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions datafusion/common/src/scalar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2872,6 +2872,14 @@ impl TryFrom<&DataType> for ScalarValue {
))),
1,
)),
DataType::Map(field, _) => ScalarValue::List(new_null_array(
&DataType::List(Arc::new(Field::new(
"entries",
field.data_type().clone(),
true,
))),
1,
)),
DataType::Struct(fields) => ScalarValue::Struct(None, fields.clone()),
DataType::Null => ScalarValue::Null,
_ => {
Expand Down Expand Up @@ -4330,6 +4338,19 @@ mod tests {
assert_eq!(scalar, ScalarValue::Utf8(Some("foo".to_string())));
}

#[test]
fn test_scalar_map() {
let key = Field::new("key", DataType::Int64, false);
let value = Field::new("value", DataType::Int64, true);
let map_field =
Field::new("entries", DataType::Struct(vec![key, value].into()), false);

let scalar =
ScalarValue::try_from(DataType::Map(map_field.into(), false)).unwrap();

assert!(matches!(scalar, ScalarValue::List(_)));
}

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

0 comments on commit b7e9431

Please sign in to comment.