functions: Add dict support for get field#21115
Open
brancz wants to merge 1 commit intoapache:mainfrom
Open
Conversation
f836dd1 to
92d660d
Compare
martin-g
reviewed
Mar 25, 2026
Comment on lines
+403
to
+405
| datafusion_common::DataFusionError::Execution( | ||
| "Field name must be a non-empty string".to_string(), | ||
| ) |
Member
There was a problem hiding this comment.
Suggested change
| datafusion_common::DataFusionError::Execution( | |
| "Field name must be a non-empty string".to_string(), | |
| ) | |
| exec_err!("Field name must be a non-empty string") |
Comment on lines
+224
to
+226
| datafusion_common::DataFusionError::Execution(format!( | ||
| "Field {field_name} not found in dictionary struct" | ||
| )) |
Member
There was a problem hiding this comment.
Suggested change
| datafusion_common::DataFusionError::Execution(format!( | |
| "Field {field_name} not found in dictionary struct" | |
| )) | |
| exec_err!("Field {field_name} not found in dictionary struct") |
Comment on lines
+216
to
+219
| datafusion_common::DataFusionError::Internal(format!( | ||
| "Failed to downcast dictionary with key type {}", | ||
| key_type | ||
| )) |
Member
There was a problem hiding this comment.
Suggested change
| datafusion_common::DataFusionError::Internal(format!( | |
| "Failed to downcast dictionary with key type {}", | |
| key_type | |
| )) | |
| internal_err!("Failed to downcast dictionary with key type {key_type}") |
| ($key_ty:ty) => {{ | ||
| let dict = array | ||
| .as_any() | ||
| .downcast_ref::<arrow::array::DictionaryArray<$key_ty>>() |
Member
There was a problem hiding this comment.
nit: use arrow::array::DictionaryArray and
Suggested change
| .downcast_ref::<arrow::array::DictionaryArray<$key_ty>>() | |
| .downcast_ref::<DictionaryArray<$key_ty>>() |
| )) | ||
| })?; | ||
| // Rebuild dictionary: same keys, extracted field as values. | ||
| let new_dict = arrow::array::DictionaryArray::<$key_ty>::try_new( |
Member
There was a problem hiding this comment.
Suggested change
| let new_dict = arrow::array::DictionaryArray::<$key_ty>::try_new( | |
| let new_dict = DictionaryArray::<$key_ty>::try_new( |
| } | ||
|
|
||
| match key_type.as_ref() { | ||
| DataType::Int8 => extract_dict_field!(arrow::datatypes::Int8Type), |
Member
There was a problem hiding this comment.
Suggested change
| DataType::Int8 => extract_dict_field!(arrow::datatypes::Int8Type), | |
| DataType::Int8 => extract_dict_field!(Int8Type), |
and import them with use arrow::datatypes::...
| Box::new(child_field.data_type().clone()), | ||
| ); | ||
| current_field = | ||
| Arc::new(Field::new(child_field.name(), dict_type, nullable)); |
Member
There was a problem hiding this comment.
Wouldn't it be better to clone the child_field as the Map/Struct arms do ?
This would preserve any metadata of the field.
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Which issue does this PR close?
Closes #21113
What changes are included in this PR?
Support structs in
get_field.Are these changes tested?
Yes, see tests, and I also replaced this in our code base and it had the effect we wanted.
Are there any user-facing changes?
No just added support for existing APIs.
@alamb