Conversation
martin-g
reviewed
Nov 11, 2025
| #### Struct Type Casting | ||
|
|
||
| - **Struct to Struct**: Structs can be cast to other struct types if all field types are compatible. | ||
| - Requires the same number of fields in source and target structs |
Member
There was a problem hiding this comment.
This is not quite correct!
- - the comparison uses
Iterator.zip() - https://github.com/scala/scala/blob/v2.13.6/src/library/scala/collection/Iterator.scala#L794-L799 - but zip() does not mandate equal sizes. It just iterates over the underlying iterators until one of them has no more items. If the first struct (from) has more items than the second (to) then some of from's items will be discarded.
Contributor
There was a problem hiding this comment.
Thanks @martin-g appreciate if you can provide an example. so it would be more clear for the user and we can also track this in the issue as future work
| - Recursively checks that the array element type supports casting to string | ||
| - Example: `CAST(array(1, 2, 3) AS STRING)` → `"[1, 2, 3]"` | ||
|
|
||
| - **Array to Array**: Arrays can be cast to other array types if the element types are compatible. |
Member
There was a problem hiding this comment.
There are no tests for this.
cast ArrayType to StringType seems to be the only cast ArrayType to ... test in the suite
| - Example: `CAST(array(1, 2, 3) AS ARRAY<BIGINT>)` → `array(1L, 2L, 3L)` | ||
| - The compatibility level (Compatible/Incompatible/Unsupported) is determined by the element type cast | ||
|
|
||
| - **Special case**: Arrays with `NullType` elements (empty arrays) can be cast to any array type |
Member
There was a problem hiding this comment.
Is it correct to say empty arrays here ?
Contributor
There was a problem hiding this comment.
Agree with @martin-g
array(null) and array() are not quite the same
comphead
approved these changes
Nov 11, 2025
comphead
left a comment
Contributor
There was a problem hiding this comment.
This is supergreat @andygrove
The nice follow up would be adding examples what is not supported
Member
Author
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 #2743
Rationale for this change
What changes are included in this PR?
How are these changes tested?