-
Notifications
You must be signed in to change notification settings - Fork 2k
fix: avoid extraneous casts for equivalent nested types #20945
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
Open
feichai0017
wants to merge
7
commits into
apache:main
Choose a base branch
from
feichai0017:fix/extraneous-casts-nested-types
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+479
−2
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
b05d5e9
fix: avoid casts for equivalent nested types
feichai0017 4af3b3e
fix: narrow nested type matching
feichai0017 9bec12c
style: simplify nested type matching
feichai0017 dc8bfe6
Merge branch 'main' into fix/extraneous-casts-nested-types
feichai0017 1c5a339
fix: support list view nested type matching
feichai0017 538e515
fix: relax nested type matching
feichai0017 8b2c60e
Merge branch 'main' into fix/extraneous-casts-nested-types
feichai0017 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
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.
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.
Seems like we aren't handling Map, Struct, or ListView -- is there a reason for that? In fact, the original bug report uses Map.
I wonder if we can simplify this to use
equals_datatypefrom Arrow, as suggested by the bug reporter?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.
Thanks for mention.
The original reproducer does go through a
Map, but the actual mismatch at the coercion point is on the extracted map value (List<Struct<...>>), not on theMaptype itself. That’s why I kept the fast-path relaxation narrow.I did try a broader
equals_datatypeapproach first, but it was too permissive in this path and regressed existing cases where runtime kernels still require exact type identity, especially aroundStruct. I agreeListView/LargeListViewshould be handled consistently withList/LargeList, and I’ve updated the matcher for that.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.
Ah, got it.
Just to help me understand, can you point at an SLT test (e.g., involving structs) that would regress if we used
equals_datatype? Or if such an SLT test doesn't already exist, it would probably be a good idea to add one as a sanity check.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.
Yes, I locally verified that a broader
equals_datatype-style matcher regresses existing SLTs.In particular:
/datafusion/datafusion/sqllogictest/test_files/struct.sltselect [{a: 1, b: 2}, {b: 3, a: 4}];/datafusion/datafusion/sqllogictest/test_files/spark/array/array.sltSELECT array(arrow_cast(array(1,2), 'LargeList(Int64)'), array(3));With the broader matching, both end up failing in array construction (
MutableArrayData) because those paths still require exact runtime type identity. That was the main reason I kept this matcher narrower thanequals_datatype, especially aroundStruct.I agree it would be useful to make that boundary explicit, so I can also add a focused sanity-check regression test in this PR.
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.
Thank you! That makes sense: the key point is that some Arrow kernels depend on struct field ordering, but the "field name" of a list has no influence on the representation of the data. Can we add a brief comment to
data_type_matchesto explain the rationale for the kinda-structural-equality we are implementing?It seems like
Maphas the same behavior as theListvariants: the "field name" does not impact the representation of the data. Should we handle that as well, for completeness?