Description
Title
Expose and generalize cast_column
to enable struct → struct casting in more contexts
Is your feature request related to a problem or challenge?
Currently, struct-to-struct casting is supported only in a limited scope within a specific module (e.g., #16371 NestedSchemaAdapter
). This means that even though the feature exists, most DataFusion users can’t leverage it directly. This restriction also causes issues in scenarios like planning queries involving mixed or nullable struct fields, as seen in issues like #14396.
Describe the solution you'd like
We should consider generalizing the #16371 introduced cast_column
function and using it in place of the current arrow::compute::cast
throughout DataFusion wherever applicable. This would make struct casting more widely available and resolve current limitations in query planning and type inference.
Describe alternatives you've considered
An alternative would be to manually implement struct casting logic in multiple places as needed. However, this would lead to code duplication and inconsistencies. By centralizing around a general-purpose cast_column
function, we gain clarity, consistency, and maintainability.
Additional context
- Comment from @alamb suggests reusing
cast_column
to improve usability and resolve related issues like #14757 and #14396. - Current errors occur when trying to perform operations with structs having slightly different fields or nullability, which could be resolved with better casting logic.
- Examples:
select {'a': 1};
-- works fine
select {'a': 1} = {'a': 2, 'b': NULL};
-- fails: Cannot infer common argument type for comparison operation