Repository navigation
[SPARK-62441][SQL] Collate string literals with collated inputs in listagg, array_insert, array_prepend, map_concat, map_contains_key and element_at - #61196
Open
SEPURI-SAI-KRISHNA wants to merge 3 commits into
Conversation
…stagg, array_insert, array_prepend, map_concat, map_contains_key and element_at
This branch has not been deployed
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?
CollationTypeCoercioncollates the string inputs of a fixed list of expressions to a single type, so that a string literal takes the collation of a collated input, as inarray_append(arr, 'x')orconcat_ws(',', s, 'x').ListAgg,ArrayInsert,ArrayPrepend,MapConcat,MapContainsKeyandElementAtare not in it, while their type checks require the same type.This PR adds them:
ArrayInsert,ArrayPrependandMapConcatjoin the existing list, likeArrayAppendandArrayPosition.ListAggcollates only its value and delimiter. TheWITHIN GROUPorder expressions are not inputs of the result, so they keep their own types.ElementAtandMapContainsKeyon a map cast a string literal key to the key type of the map when their collations differ, asGetMapValue(m['K']) already does. Likem['K' COLLATE UNICODE], a key of another explicit collation still fails.Why are the changes needed?
With a collated input, these functions fail to resolve when another argument is a plain string literal:
The same calls work for
array_append,array_position,array_contains,concat,concat_wsandm['K']. Reproduced on 4.0.3 and on master.Does this PR introduce any user-facing change?
Yes. The queries above now resolve, and their results take the collation of the collated input. For example,
listagg(s, ',')returns aSTRING COLLATE UTF8_LCASE, andmap_contains_key(m, 'K')andelement_at(m, 'K')find the key'k'underUTF8_LCASE, asm['K']does. Previously, they failed with the errors above. The rule changes only expressions with a collated string input whose string inputs had different collations, which failed the type checks before.How was this patch tested?
New test in
CollationTypePrecedenceSuite, run with the fixed-point and the single-pass analyzer, which fails without the change:listaggandstring_aggwith a delimiter, withWITHIN GROUPandDISTINCT,array_insert,array_prepend(also with an explicit collation that wins),map_concat,map_contains_key,element_atandtry_element_at, and a map key of another explicit collation that still fails.Ran the
*Collation*suites ofsql/coreandsql/catalyst,TypeCoercionSuite,AnsiTypeCoercionSuite, and the collation golden files ofSQLQueryTestSuite, all passing.#61038 also targets SPARK-62441 with a similar change. This PR additionally runs the test under the single-pass analyzer and covers
DISTINCTand a map key of another explicit collation.Was this patch authored or co-authored using generative AI tooling?
Generated-by: Claude Code (Claude Opus 5.5)