Skip to content

[SPARK-52354] 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

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

Pajaraja
Copy link
Contributor

@Pajaraja Pajaraja commented Jun 2, 2025

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.

@github-actions github-actions bot added the SQL label Jun 2, 2025
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 {
Copy link
Contributor

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))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants