Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add map to ScalarValue::try_from as a list #8488

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the data type needs to match the ScalarValue enum (e.g. we need to add DataType::Map to make this work properly). I'll keep the discussion going at #8262 (comment)

&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