-
Notifications
You must be signed in to change notification settings - Fork 29k
[SPARK-52354][SQL] Add type coercion to UnionLoop #51063
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
[SPARK-52354][SQL] Add type coercion to UnionLoop #51063
Conversation
| case s: UnionLoop | ||
| if s.childrenResolved && s.anchor.output.length == s.recursion.output.length | ||
| && !s.resolved => | ||
| val incompatibleAttributes = s.anchor.output.zip(s.recursion.output).filter { |
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.
I think it should be simpler
val casts = s.recursion.output.zip(s.anchor.output.map(_.dataType)).map {
case (attr, dt) => implicitCast(attr, dt).getOrElse(attr)
}
s.copy(recursion = Project(casts, s.recursion))
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.
I changed it to something like this. However, this will always cast the recursion type to the anchor type, even if the recursion type is larger (for example if the anchor type is INT, and in the recursion it's cast to BIGINT, we will cast it back to INT). Should this be the expected behavior?
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/TypeCoercionBase.scala
Show resolved
Hide resolved
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/TypeCoercionBase.scala
Outdated
Show resolved
Hide resolved
cloud-fan
left a comment
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.
LGTM, please fix merge conflicts
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/TypeCoercionBase.scala
Show resolved
Hide resolved
|
@Pajaraja can you resolve merge conflicts? |
|
thanks, merging to master! |
What changes were proposed in this pull request?
Add a new rule to WidenSetOperationTypes to work for UnionLoop.
Why are the changes needed?
To have UNION ALL in recursive CTEs behave in the same way regarding type coercion as UNION ALL outside the context of rCTEs.
Does this PR introduce any user-facing change?
No.
How was this patch tested?
New Golden file tests.
Was this patch authored or co-authored using generative AI tooling?
No.