-
Notifications
You must be signed in to change notification settings - Fork 1.8k
feat: support FixedSizeList Type Coercion
#9108
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
Merged
Merged
Changes from all commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
56e4ddf
support FixedSizeList Type Coercion
Weijun-H c10b8b2
add allow null type coercion parameter
Weijun-H 92d5e9e
support null column in FixedSizeList
Weijun-H b61cbef
Add test
Weijun-H 3220da5
Add tests for cardinality with fixed size lists
Weijun-H b565290
chore
Weijun-H 58b7d09
fix ci
Weijun-H 3d5c899
add comment
Weijun-H eeed955
Fix array_element function signature
Weijun-H 342d379
Remove unused imports and simplify code
Weijun-H d1f8744
Fix array function signatures and behavior
Weijun-H 4de5ee2
fix conflict
Weijun-H 13801be
fix conflict
Weijun-H 4b21267
add tests for FixedSizeList
Weijun-H 1d9f35e
remove unreacheable null check
Weijun-H cb37528
simplify the code
Weijun-H a7f121e
remove null checking
Weijun-H 0a338b6
reformat output
Weijun-H 9d9527e
simplify code
Weijun-H 9201a36
add tests for array_dims
Weijun-H ad73b17
Refactor type coercion functions in datafusion/expr module
Weijun-H File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -80,6 +80,36 @@ fn get_valid_types( | |
| signature: &TypeSignature, | ||
| current_types: &[DataType], | ||
| ) -> Result<Vec<Vec<DataType>>> { | ||
| fn array_element_and_optional_index( | ||
| current_types: &[DataType], | ||
| ) -> Result<Vec<Vec<DataType>>> { | ||
| // make sure there's 2 or 3 arguments | ||
| if !(current_types.len() == 2 || current_types.len() == 3) { | ||
| return Ok(vec![vec![]]); | ||
| } | ||
|
|
||
| let first_two_types = ¤t_types[0..2]; | ||
| let mut valid_types = array_append_or_prepend_valid_types(first_two_types, true)?; | ||
|
|
||
| // Early return if there are only 2 arguments | ||
| if current_types.len() == 2 { | ||
| return Ok(valid_types); | ||
| } | ||
|
|
||
| let valid_types_with_index = valid_types | ||
| .iter() | ||
| .map(|t| { | ||
| let mut t = t.clone(); | ||
| t.push(DataType::Int64); | ||
| t | ||
| }) | ||
| .collect::<Vec<_>>(); | ||
|
|
||
| valid_types.extend(valid_types_with_index); | ||
|
|
||
| Ok(valid_types) | ||
| } | ||
|
|
||
| fn array_append_or_prepend_valid_types( | ||
|
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. I see -- so one part of this PR is extracting this function into ArrayFunctionSignature ? |
||
| current_types: &[DataType], | ||
| is_append: bool, | ||
|
|
@@ -111,71 +141,37 @@ fn get_valid_types( | |
| ) | ||
| })?; | ||
|
|
||
| let array_type = datafusion_common::utils::coerced_type_with_base_type_only( | ||
| let new_array_type = datafusion_common::utils::coerced_type_with_base_type_only( | ||
| array_type, | ||
| &new_base_type, | ||
| ); | ||
|
|
||
| match array_type { | ||
| match new_array_type { | ||
| DataType::List(ref field) | ||
| | DataType::LargeList(ref field) | ||
| | DataType::FixedSizeList(ref field, _) => { | ||
| let elem_type = field.data_type(); | ||
| let new_elem_type = field.data_type(); | ||
| if is_append { | ||
| Ok(vec![vec![array_type.clone(), elem_type.clone()]]) | ||
| Ok(vec![vec![new_array_type.clone(), new_elem_type.clone()]]) | ||
| } else { | ||
| Ok(vec![vec![elem_type.to_owned(), array_type.clone()]]) | ||
| Ok(vec![vec![new_elem_type.to_owned(), new_array_type.clone()]]) | ||
| } | ||
| } | ||
| _ => Ok(vec![vec![]]), | ||
| } | ||
| } | ||
| fn array_element_and_optional_index( | ||
| current_types: &[DataType], | ||
| ) -> Result<Vec<Vec<DataType>>> { | ||
| // make sure there's 2 or 3 arguments | ||
| if !(current_types.len() == 2 || current_types.len() == 3) { | ||
| return Ok(vec![vec![]]); | ||
| } | ||
|
|
||
| let first_two_types = ¤t_types[0..2]; | ||
| let mut valid_types = array_append_or_prepend_valid_types(first_two_types, true)?; | ||
|
|
||
| // Early return if there are only 2 arguments | ||
| if current_types.len() == 2 { | ||
| return Ok(valid_types); | ||
| } | ||
|
|
||
| let valid_types_with_index = valid_types | ||
| .iter() | ||
| .map(|t| { | ||
| let mut t = t.clone(); | ||
| t.push(DataType::Int64); | ||
| t | ||
| }) | ||
| .collect::<Vec<_>>(); | ||
|
|
||
| valid_types.extend(valid_types_with_index); | ||
|
|
||
| Ok(valid_types) | ||
| } | ||
| fn array_and_index(current_types: &[DataType]) -> Result<Vec<Vec<DataType>>> { | ||
| if current_types.len() != 2 { | ||
| return Ok(vec![vec![]]); | ||
| } | ||
|
|
||
| let array_type = ¤t_types[0]; | ||
|
|
||
| fn array(array_type: &DataType) -> Option<DataType> { | ||
| match array_type { | ||
| DataType::List(_) | ||
| | DataType::LargeList(_) | ||
| | DataType::FixedSizeList(_, _) => { | ||
| let array_type = coerced_fixed_size_list_to_list(array_type); | ||
| Ok(vec![vec![array_type, DataType::Int64]]) | ||
| Some(array_type) | ||
| } | ||
| _ => Ok(vec![vec![]]), | ||
| _ => None, | ||
| } | ||
| } | ||
|
|
||
| let valid_types = match signature { | ||
| TypeSignature::Variadic(valid_types) => valid_types | ||
| .iter() | ||
|
|
@@ -211,19 +207,32 @@ fn get_valid_types( | |
| TypeSignature::ArraySignature(ref function_signature) => match function_signature | ||
| { | ||
| ArrayFunctionSignature::ArrayAndElement => { | ||
| return array_append_or_prepend_valid_types(current_types, true) | ||
| array_append_or_prepend_valid_types(current_types, true)? | ||
| } | ||
| ArrayFunctionSignature::ArrayAndElementAndOptionalIndex => { | ||
| return array_element_and_optional_index(current_types) | ||
| ArrayFunctionSignature::ElementAndArray => { | ||
| array_append_or_prepend_valid_types(current_types, false)? | ||
| } | ||
| ArrayFunctionSignature::ArrayAndIndex => { | ||
| return array_and_index(current_types) | ||
| if current_types.len() != 2 { | ||
| return Ok(vec![vec![]]); | ||
| } | ||
| array(¤t_types[0]).map_or_else( | ||
| || vec![vec![]], | ||
| |array_type| vec![vec![array_type, DataType::Int64]], | ||
| ) | ||
| } | ||
| ArrayFunctionSignature::ElementAndArray => { | ||
| return array_append_or_prepend_valid_types(current_types, false) | ||
| ArrayFunctionSignature::ArrayAndElementAndOptionalIndex => { | ||
| array_element_and_optional_index(current_types)? | ||
| } | ||
| }, | ||
| ArrayFunctionSignature::Array => { | ||
| if current_types.len() != 1 { | ||
| return Ok(vec![vec![]]); | ||
| } | ||
|
|
||
| array(¤t_types[0]) | ||
| .map_or_else(|| vec![vec![]], |array_type| vec![vec![array_type]]) | ||
| } | ||
| }, | ||
| TypeSignature::Any(number) => { | ||
| if current_types.len() != *number { | ||
| return plan_err!( | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.