-
Notifications
You must be signed in to change notification settings - Fork 1.8k
fix: Ignore nullability of list elements when consuming Substrait #10874
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -354,7 +354,7 @@ pub fn longest_consecutive_prefix<T: Borrow<usize>>( | |
| pub fn array_into_list_array(arr: ArrayRef) -> ListArray { | ||
| let offsets = OffsetBuffer::from_lengths([arr.len()]); | ||
| ListArray::new( | ||
| Arc::new(Field::new("item", arr.data_type().to_owned(), true)), | ||
| Arc::new(Field::new_list_field(arr.data_type().to_owned(), true)), | ||
| offsets, | ||
| arr, | ||
| None, | ||
|
|
@@ -366,7 +366,7 @@ pub fn array_into_list_array(arr: ArrayRef) -> ListArray { | |
| pub fn array_into_large_list_array(arr: ArrayRef) -> LargeListArray { | ||
| let offsets = OffsetBuffer::from_lengths([arr.len()]); | ||
| LargeListArray::new( | ||
| Arc::new(Field::new("item", arr.data_type().to_owned(), true)), | ||
| Arc::new(Field::new_list_field(arr.data_type().to_owned(), true)), | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||
| offsets, | ||
| arr, | ||
| None, | ||
|
|
@@ -379,7 +379,7 @@ pub fn array_into_fixed_size_list_array( | |
| ) -> FixedSizeListArray { | ||
| let list_size = list_size as i32; | ||
| FixedSizeListArray::new( | ||
| Arc::new(Field::new("item", arr.data_type().to_owned(), true)), | ||
| Arc::new(Field::new_list_field(arr.data_type().to_owned(), true)), | ||
| list_size, | ||
| arr, | ||
| None, | ||
|
|
@@ -420,7 +420,7 @@ pub fn arrays_into_list_array( | |
| let data_type = arr[0].data_type().to_owned(); | ||
| let values = arr.iter().map(|x| x.as_ref()).collect::<Vec<_>>(); | ||
| Ok(ListArray::new( | ||
| Arc::new(Field::new("item", data_type, true)), | ||
| Arc::new(Field::new_list_field(data_type, true)), | ||
| OffsetBuffer::from_lengths(lens), | ||
| arrow::compute::concat(values.as_slice())?, | ||
| None, | ||
|
|
@@ -435,7 +435,7 @@ pub fn arrays_into_list_array( | |
| /// use datafusion_common::utils::base_type; | ||
| /// use std::sync::Arc; | ||
| /// | ||
| /// let data_type = DataType::List(Arc::new(Field::new("item", DataType::Int32, true))); | ||
| /// let data_type = DataType::List(Arc::new(Field::new_list_field(DataType::Int32, true))); | ||
| /// assert_eq!(base_type(&data_type), DataType::Int32); | ||
| /// | ||
| /// let data_type = DataType::Int32; | ||
|
|
@@ -458,10 +458,10 @@ pub fn base_type(data_type: &DataType) -> DataType { | |
| /// use datafusion_common::utils::coerced_type_with_base_type_only; | ||
| /// use std::sync::Arc; | ||
| /// | ||
| /// let data_type = DataType::List(Arc::new(Field::new("item", DataType::Int32, true))); | ||
| /// let data_type = DataType::List(Arc::new(Field::new_list_field(DataType::Int32, true))); | ||
| /// let base_type = DataType::Float64; | ||
| /// let coerced_type = coerced_type_with_base_type_only(&data_type, &base_type); | ||
| /// assert_eq!(coerced_type, DataType::List(Arc::new(Field::new("item", DataType::Float64, true)))); | ||
| /// assert_eq!(coerced_type, DataType::List(Arc::new(Field::new_list_field(DataType::Float64, true)))); | ||
| pub fn coerced_type_with_base_type_only( | ||
| data_type: &DataType, | ||
| base_type: &DataType, | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1272,7 +1272,9 @@ fn from_substrait_type( | |
| })?; | ||
| let field = Arc::new(Field::new_list_field( | ||
| from_substrait_type(inner_type, dfs_names, name_idx)?, | ||
| is_substrait_type_nullable(inner_type)?, | ||
| // We ignore Substrait's nullability here to match to_substrait_literal | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||
| // which always creates nullable lists | ||
| true, | ||
| )); | ||
| match list.type_variation_reference { | ||
| DEFAULT_CONTAINER_TYPE_VARIATION_REF => Ok(DataType::List(field)), | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2309,14 +2309,12 @@ mod test { | |
| round_trip_type(DataType::Decimal128(10, 2))?; | ||
| round_trip_type(DataType::Decimal256(30, 2))?; | ||
|
|
||
| for nullable in [true, false] { | ||
| round_trip_type(DataType::List( | ||
| Field::new_list_field(DataType::Int32, nullable).into(), | ||
| ))?; | ||
| round_trip_type(DataType::LargeList( | ||
| Field::new_list_field(DataType::Int32, nullable).into(), | ||
| ))?; | ||
| } | ||
| round_trip_type(DataType::List( | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we also add a test here showing that the List becomes nullable after roundtrip? That might additionally document that this is an intended behavior rather than a bug. I do see you have added a comment which I think is probably enought
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think we need to test the null coercion specifically, since that's not necessarily the ultimate desired behavior, just what makes sense at this time. But I added a test case to confirm that we can now read plans with non-nullable lists: a25abd8 |
||
| Field::new_list_field(DataType::Int32, true).into(), | ||
| ))?; | ||
| round_trip_type(DataType::LargeList( | ||
| Field::new_list_field(DataType::Int32, true).into(), | ||
| ))?; | ||
|
|
||
| round_trip_type(DataType::Struct( | ||
| vec![ | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,71 @@ | ||
| { | ||
| "extensionUris": [], | ||
| "extensions": [], | ||
| "relations": [ | ||
| { | ||
| "root": { | ||
| "input": { | ||
| "read": { | ||
| "common": { | ||
| "direct": { | ||
| } | ||
| }, | ||
| "baseSchema": { | ||
| "names": [ | ||
| "col" | ||
| ], | ||
| "struct": { | ||
| "types": [ | ||
| { | ||
| "list": { | ||
| "type": { | ||
| "i32": { | ||
| "typeVariationReference": 0, | ||
| "nullability": "NULLABILITY_REQUIRED" | ||
| } | ||
| }, | ||
| "typeVariationReference": 0, | ||
| "nullability": "NULLABILITY_REQUIRED" | ||
| } | ||
| } | ||
| ], | ||
| "typeVariationReference": 0, | ||
| "nullability": "NULLABILITY_REQUIRED" | ||
| } | ||
| }, | ||
| "virtualTable": { | ||
| "values": [ | ||
| { | ||
| "fields": [ | ||
| { | ||
| "list": { | ||
| "values": [ | ||
| { | ||
| "i32": 1, | ||
| "nullable": false, | ||
| "typeVariationReference": 0 | ||
| }, | ||
| { | ||
| "i32": 2, | ||
| "nullable": false, | ||
| "typeVariationReference": 0 | ||
| } | ||
| ] | ||
| }, | ||
| "nullable": false, | ||
| "typeVariationReference": 0 | ||
| } | ||
| ] | ||
| } | ||
| ] | ||
| } | ||
| } | ||
| }, | ||
| "names": [ | ||
| "col" | ||
| ] | ||
| } | ||
| } | ||
| ], | ||
| "expectedTypeUrls": [] | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is no-op change, just seems nicer to use the new_list_field given it exists (it sets the name as "item" anyways)