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

[SPARK-48283][SQL] Modify string comparison for UTF8_BINARY_LCASE #46700

Closed
wants to merge 16 commits into from

Conversation

uros-db
Copy link
Contributor

@uros-db uros-db commented May 22, 2024

What changes were proposed in this pull request?

String comparison and hashing in UTF8_BINARY_LCASE is now context-unaware, and uses ICU root locale rules to convert string to lowercase at code point level, taking into consideration special cases for one-to-many case mapping. For example: comparing "ΘΑΛΑΣΣΙΝΟΣ" and "θαλασσινοσ" under UTF8_BINARY_LCASE now returns true, because Greek final sigma is special-cased in the new comparison implementation.

Why are the changes needed?

  1. UTF8_BINARY_LCASE should use ICU root locale rules (instead of JVM)
  2. comparing strings under UTF8_BINARY_LCASE should be context-insensitive

Does this PR introduce any user-facing change?

Yes, comparing strings under UTF8_BINARY_LCASE will now give different results in two kinds of special cases (Turkish dotted letter "i" and Greek final letter "sigma").

How was this patch tested?

Unit tests in CollationSupportSuite.

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

No.

@github-actions github-actions bot added the SQL label May 22, 2024
@uros-db uros-db changed the title [WIP][SQL] Modify lowerCase, upperCase and titleCase implementations for UTF8_BINARY_LCASE [WIP][SQL] Modify string comparison for UTF8_BINARY_LCASE May 23, 2024
@uros-db uros-db changed the title [WIP][SQL] Modify string comparison for UTF8_BINARY_LCASE [SPARK-48283][SQL] Modify string comparison for UTF8_BINARY_LCASE May 23, 2024
@uros-db uros-db requested a review from mkaravel May 31, 2024 12:20
@uros-db uros-db requested a review from dbatomic June 5, 2024 07:49
Copy link
Contributor

@mkaravel mkaravel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Main question here is whether we want to fix the "conversion" from UTF8String to Java string in this PR or in a follow up PR (see comments in the PR). Either way is fine with me. By "conversion" here I mean:

  • Splitting the UTF8String value into illegal and legal UTF8 byte sequences as per UNICODE (no surrogate semantics).
  • Replacing illegal byte sequences with U+FFFD.

@uros-db
Copy link
Contributor Author

uros-db commented Jun 6, 2024

in conclusion: we'll need to modify the logic for illegal UTF8 byte sequence replacement, to stay consistent with ICU4C

however, we'll do this in a follow-up PR

@uros-db
Copy link
Contributor Author

uros-db commented Jun 6, 2024

@cloud-fan please review

@cloud-fan
Copy link
Contributor

thanks, merging to master!

@cloud-fan cloud-fan closed this in 84fa052 Jun 6, 2024
cloud-fan pushed a commit that referenced this pull request Jun 11, 2024
### What changes were proposed in this pull request?
Renaming `UTF8_BINARY_LCASE` collation to `UTF8_LCASE`.

### Why are the changes needed?
As part of the collation effort in Spark, we've moved away from byte-by-byte logic towards character-by-character logic, so what we used to call `UTF8_BINARY_LCASE` is now more precisely `UTF8_LCASE`. For example, string searching in UTF8_LCASE now works on character-level (rather than on byte-level), which is reflected in this PRs: #46511, #46589, #46682, #46761, #46762. In addition, string comparison also works on character-level now, as per the changes introduced in this PR: #46700.

### Does this PR introduce _any_ user-facing change?
Yes, what was previously named `UTF8_BINARY_LCASE` collation, will from now on be named `UTF8_LCASE`.

### How was this patch tested?
Existing tests.

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

Closes #46924 from uros-db/rename-lcase.

Authored-by: Uros Bojanic <157381213+uros-db@users.noreply.github.com>
Signed-off-by: Wenchen Fan <wenchen@databricks.com>
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.

4 participants