Skip to content

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

Copy link
Contributor Author

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?

Copy link
Contributor

@cloud-fan cloud-fan left a 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

@cloud-fan cloud-fan changed the title [SPARK-52354] Add type coercion to UnionLoop [SPARK-52354][SQL] Add type coercion to UnionLoop Jun 23, 2025
@cloud-fan
Copy link
Contributor

@Pajaraja can you resolve merge conflicts?

@cloud-fan
Copy link
Contributor

thanks, merging to master!

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