[SPARK-58069][SQL] approx_top_k returns incorrect/garbage sort-key bytes instead of actual values for collated strings#57177
Draft
jiwen624 wants to merge 1 commit into
Draft
[SPARK-58069][SQL] approx_top_k returns incorrect/garbage sort-key bytes instead of actual values for collated strings#57177jiwen624 wants to merge 1 commit into
jiwen624 wants to merge 1 commit into
Conversation
…ad of an actual value for collated strings
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What changes were proposed in this pull request?
For a non-
UTF8_BINARYcollated STRING column,approx_top_k(andapprox_top_k_accumulate/_combine/_estimate) stored the collation sort key in the sketch and returned it verbatim as the item. This makes the sketch storeCollatedStringinstead: it dedupes by the collation key (so collation-equal values still count as one) but retains an actual input value to return, the waymode()does. The serde writes only the original value and recomputes the key on read, so theUTF8_BINARYformat is unchanged.Why are the changes needed?
The returned items were wrong: raw ICU sort-key bytes (invalid UTF-8) for ICU collations, and the lower-cased form for
UTF8_LCASE(a value that may never have appeared). Counts were correct, but the item labels were garbage. Silent wrong result, no error.Before the fix:
Does this PR introduce any user-facing change?
Yes. approx_top_k over a collated string column now returns an actual input value instead of the internal collation key. Sketches persisted by approx_top_k_accumulate over a non-binary collated column before this change are not readable after it (they contained wrong data); the UTF8_BINARY format is unchanged.
How was this patch tested?
Added test cases.
Was this patch authored or co-authored using generative AI tooling?
Yes.