Skip to content

Commit

Permalink
Fix try_from_array data type for NULL value in ListArray
Browse files Browse the repository at this point in the history
  • Loading branch information
viirya committed Oct 29, 2023
1 parent 9ee055a commit 6cc8944
Showing 1 changed file with 24 additions and 2 deletions.
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();
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

0 comments on commit 6cc8944

Please sign in to comment.