[SPARK-47418][SQL] Add hand-crafted implementations for lowercase unicode-aware contains, startsWith and endsWith and optimize UTF8_BINARY_LCASE #46181
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?
Added hand-crafted implementations of unicode-aware lower-case
contains
,startsWith
,endsWith
to optimize UTF8_BINARY_LCASE for ASCII-only strings.Why are the changes needed?
UTF8String.toLowerCase()
, which is used for the aforementioned collation-aware functions, has an optimization for full-ascii strings, but still always allocates a new object. In this PR I introduced loop-based implementations, which fall-back totoLowerCase()
in case they meet a non-asci character.Does this PR introduce any user-facing change?
No, these functions should behave exactly as:
lhs.containsInLowerCase(rhs)
==lhs.toLowerCase().contains(rhs.toLowerCase())
lhs.startsWithInLowerCase(rhs)
==lhs.toLowerCase().startsWith(rhs.toLowerCase())
lhs.endsWithInLowerCase(rhs)
==lhs.toLowerCase().endsWith(rhs.toLowerCase())
How was this patch tested?
Added new test cases to
org.apache.spark.unsafe.types.CollationSupportSuite
andorg.apache.spark.unsafe.types.UTF8StringSuite
, including several unicode lowercase specific. Also I've runCollationBenchmark
on GHA for JDK 17 and JDK 21 and have updated the data.Was this patch authored or co-authored using generative AI tooling?
No