Skip to content
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

[WIP][SPARK-51428][SQL] Reassign Aliases for collated expression trees deterministically #50192

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

vladimirg-db
Copy link
Contributor

@vladimirg-db vladimirg-db commented Mar 6, 2025

What changes were proposed in this pull request?

Reassign Aliases for collated expression trees deterministically at the end of Analysis.

Why are the changes needed?

Consider the following collated queries and their schemas:
1.

SELECT 'a' COLLATE UTF8_LCASE < 'A'
->
(collate(a, UTF8_LCASE) < 'A' collate UTF8_LCASE)
SELECT CONCAT_WS('a', col1, col1) FROM VALUES ('a' COLLATE UTF8_LCASE)
->
concat_ws(a, col1, col1)

The 1. case has an explicit alias where 'A' literal is marked as collated, which is correct. However, in the second case, 'a' literal is not marked as collated in the output implicit alias, despite the fact that it is indeed collated by CollationTypeCoercion. The 2. output schema has to be concat_ws('a' collate UTF8_LCASE, col1, col1).

This happens because in 1. case ResolveAliases runs after the AnsiCombinedTypeCoercionRule, and in 2. case the order is the opposite, so alias is assigned before the actual data type is collated. ResolveAliases relies on the aliased expression subtree being resolved. In the context of type coercion it's checkInputDataTypes. But this predicate doesn't really know about collations. Ideally we would fix all the checkInputDataTypes, but that would be quite involved.

Does this PR introduce any user-facing change?

Yes, implicit aliases of collated expression trees now change. This is a breaking change.

How was this patch tested?

Golden files were regenerated

Was this patch authored or co-authored using generative AI tooling?

No.

@github-actions github-actions bot added the SQL label Mar 6, 2025
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.

1 participant