Skip to content

[SPARK-58928][SQL] Fix collation-aware grouping in WindowGroupLimitExec - #58195

Open
vinodkc wants to merge 1 commit into
apache:masterfrom
vinodkc:fix-window-group-limit-collation
Open

[SPARK-58928][SQL] Fix collation-aware grouping in WindowGroupLimitExec#58195
vinodkc wants to merge 1 commit into
apache:masterfrom
vinodkc:fix-window-group-limit-collation

Conversation

@vinodkc

@vinodkc vinodkc commented Aug 21, 2026

Copy link
Copy Markdown
Contributor

What changes were proposed in this pull request?

WindowGroupLimitExec (injected by the InferWindowGroupLimit rule for rank-filter queries like WHERE rank <= N) detected partition boundaries with a raw binary UnsafeRow comparison (nextGroup == currentGroup).

This PR makes that comparison collation-aware: it keeps the fast binary equals when all PARTITION BY keys are binary-stable, and falls back to InterpretedOrdering-based comparison when any key is not (e.g. a collated STRING), mirroring the existing pattern in WindowEvaluatorFactory.groupEqualityCheck.

Why are the changes needed?

Byte-for-byte comparison is wrong for collated strings: under UTF8_LCASE, 'foo' and 'FOO' are equal but have different bytes, so the operator splits a single collation partition into several. The final result stays correct (the downstream WindowExec recomputes the ranking), but the limit no longer collapses collated partitions, so it forwards far more rows than needed and the optimization stops helping.

Does this PR introduce any user-facing change?

No. Results are unchanged; this only restores the intended row-pruning for collated partition keys.

How was this patch tested?

Added tests in CollationSuite

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

Yes, Generated-by: Claude Code

@vinodkc vinodkc changed the title [SPARK-58928][SQL] WindowGroupLimitExec uses binary equality for collated PARTITION BY keys [SPARK-58928][SQL] Fix collation-aware grouping in WindowGroupLimitExec Aug 21, 2026
@uros-b
uros-b requested a review from cloud-fan August 21, 2026 07:36
@uros-b

uros-b commented Aug 21, 2026

Copy link
Copy Markdown
Member

Thank you @vinodkc! cc @cloud-fan to PTAL

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants