Skip to content
Merged
Changes from 1 commit
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
Next Next commit
Fix try_from_array data type for NULL value in ListArray
  • Loading branch information
viirya committed Oct 29, 2023
commit 6cc8944e4d0f5d4daca21868efdb92d3b80a7eb1
26 changes: 24 additions & 2 deletions datafusion/common/src/scalar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2944,8 +2944,14 @@ impl TryFrom<&DataType> for ScalarValue {
index_type.clone(),
Box::new(value_type.as_ref().try_into()?),
),
DataType::List(_) => ScalarValue::List(new_null_array(&DataType::Null, 0)),

DataType::List(field) => ScalarValue::List(new_null_array(
&DataType::List(Arc::new(Field::new(
"item",
field.data_type().clone(),
true,
))),
1,
)),
DataType::Struct(fields) => ScalarValue::Struct(None, fields.clone()),
DataType::Null => ScalarValue::Null,
_ => {
Expand Down Expand Up @@ -3885,6 +3891,22 @@ mod tests {
);
}

#[test]
fn scalar_try_from_array_list_array_null() {
let list = ListArray::from_iter_primitive::<Int32Type, _, _>(vec![
Some(vec![Some(1), Some(2)]),
None,
]);

let non_null_list_scalar = ScalarValue::try_from_array(&list, 0).unwrap();
Copy link
Member Author

@viirya viirya Oct 29, 2023

Choose a reason for hiding this comment

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

Previously, for a NULL value from ListArray, the generated ScalarValue::List value's datatype is DataType::Null. That's is not correct.

let null_list_scalar = ScalarValue::try_from_array(&list, 1).unwrap();

assert_eq!(
non_null_list_scalar.data_type(),
null_list_scalar.data_type()
);
}

#[test]
fn scalar_try_from_dict_datatype() {
let data_type =
Expand Down