-
Notifications
You must be signed in to change notification settings - Fork 69
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
FIX: Use lazy encoding in UTF-8 encoded string comparison #2021
Open
milaGGL
wants to merge
17
commits into
main
Choose a base branch
from
mila/string-uses-byte-comparison
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 16 commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
96de3e3
add test
milaGGL 24bd892
chore: generate libraries at Mon Jan 6 16:30:40 UTC 2025
cloud-java-bot 9e812fa
Revert "chore: generate libraries at Mon Jan 6 16:30:40 UTC 2025"
milaGGL 149d3e1
chore: generate libraries at Mon Jan 6 16:54:57 UTC 2025
cloud-java-bot dec5d02
add more tests
milaGGL 89ed44c
Merge branch 'main' into mila/string-uses-byte-comparison
milaGGL c876e5a
format
milaGGL b55992d
remove lines commented out
milaGGL ef2ae13
Update ITQueryTest.java
milaGGL 31cf3ff
Merge branch 'main' into mila/string-uses-byte-comparison
milaGGL f17c28a
resolve comment
milaGGL d4f299a
use lazy encoding in utf-8 encoded string comparison
milaGGL 511469b
Merge branch 'main' into mila/string-uses-byte-comparison
milaGGL f86dcfb
chore: generate libraries at Tue Feb 18 21:15:36 UTC 2025
cloud-java-bot 602a356
Update Order.java
milaGGL e8b3f57
Merge branch 'mila/string-uses-byte-comparison' of https://github.com…
milaGGL 4ce70e6
add unit test
milaGGL File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1169,6 +1169,10 @@ public void snapshotListenerSortsUnicodeStringsSameWayAsServer() throws Exceptio | |
.set(col.document("e"), map("value", "P")) | ||
.set(col.document("f"), map("value", "︒")) | ||
.set(col.document("g"), map("value", "🐵")) | ||
.set(col.document("h"), map("value", "你好")) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This integration test coverage is good proof-of-concept. Please add solid unit test coverage too, as the logic is very delicate and exploits low-level properties of utf8 and utf16 encoding that are not well-known, obvious, or straight-forward. |
||
.set(col.document("i"), map("value", "你顥")) | ||
.set(col.document("j"), map("value", "😁")) | ||
.set(col.document("k"), map("value", "😀")) | ||
.commit() | ||
.get(); | ||
|
||
|
@@ -1192,7 +1196,7 @@ public void snapshotListenerSortsUnicodeStringsSameWayAsServer() throws Exceptio | |
latch.await(); | ||
registration.remove(); | ||
|
||
assertEquals(queryOrder, Arrays.asList("b", "a", "c", "f", "e", "d", "g")); | ||
assertEquals(queryOrder, Arrays.asList("b", "a", "h", "i", "c", "f", "e", "d", "g", "k", "j")); | ||
assertEquals(queryOrder, listenerOrder); | ||
} | ||
|
||
|
@@ -1209,6 +1213,10 @@ public void snapshotListenerSortsUnicodeStringsInArraySameWayAsServer() throws E | |
.set(col.document("e"), map("value", Arrays.asList("P"))) | ||
.set(col.document("f"), map("value", Arrays.asList("︒"))) | ||
.set(col.document("g"), map("value", Arrays.asList("🐵"))) | ||
.set(col.document("h"), map("value", Arrays.asList("你好"))) | ||
.set(col.document("i"), map("value", Arrays.asList("你顥"))) | ||
.set(col.document("j"), map("value", Arrays.asList("😁"))) | ||
.set(col.document("k"), map("value", Arrays.asList("😀"))) | ||
.commit() | ||
.get(); | ||
|
||
|
@@ -1232,7 +1240,7 @@ public void snapshotListenerSortsUnicodeStringsInArraySameWayAsServer() throws E | |
latch.await(); | ||
registration.remove(); | ||
|
||
assertEquals(queryOrder, Arrays.asList("b", "a", "c", "f", "e", "d", "g")); | ||
assertEquals(queryOrder, Arrays.asList("b", "a", "h", "i", "c", "f", "e", "d", "g", "k", "j")); | ||
assertEquals(queryOrder, listenerOrder); | ||
} | ||
|
||
|
@@ -1249,6 +1257,10 @@ public void snapshotListenerSortsUnicodeStringsInMapSameWayAsServer() throws Exc | |
.set(col.document("e"), map("value", map("foo", "P"))) | ||
.set(col.document("f"), map("value", map("foo", "︒"))) | ||
.set(col.document("g"), map("value", map("foo", "🐵"))) | ||
.set(col.document("h"), map("value", map("foo", "你好"))) | ||
.set(col.document("i"), map("value", map("foo", "你顥"))) | ||
.set(col.document("j"), map("value", map("foo", "😁"))) | ||
.set(col.document("k"), map("value", map("foo", "😀"))) | ||
.commit() | ||
.get(); | ||
|
||
|
@@ -1272,7 +1284,7 @@ public void snapshotListenerSortsUnicodeStringsInMapSameWayAsServer() throws Exc | |
latch.await(); | ||
registration.remove(); | ||
|
||
assertEquals(queryOrder, Arrays.asList("b", "a", "c", "f", "e", "d", "g")); | ||
assertEquals(queryOrder, Arrays.asList("b", "a", "h", "i", "c", "f", "e", "d", "g", "k", "j")); | ||
assertEquals(queryOrder, listenerOrder); | ||
} | ||
|
||
|
@@ -1289,6 +1301,10 @@ public void snapshotListenerSortsUnicodeStringsInMapKeySameWayAsServer() throws | |
.set(col.document("e"), map("value", map("P", "foo"))) | ||
.set(col.document("f"), map("value", map("︒", "foo"))) | ||
.set(col.document("g"), map("value", map("🐵", "foo"))) | ||
.set(col.document("h"), map("value", map("你好", "foo"))) | ||
.set(col.document("i"), map("value", map("你顥", "foo"))) | ||
.set(col.document("j"), map("value", map("😁", "foo"))) | ||
.set(col.document("k"), map("value", map("😀", "foo"))) | ||
.commit() | ||
.get(); | ||
|
||
|
@@ -1312,7 +1328,7 @@ public void snapshotListenerSortsUnicodeStringsInMapKeySameWayAsServer() throws | |
latch.await(); | ||
registration.remove(); | ||
|
||
assertEquals(queryOrder, Arrays.asList("b", "a", "c", "f", "e", "d", "g")); | ||
assertEquals(queryOrder, Arrays.asList("b", "a", "h", "i", "c", "f", "e", "d", "g", "k", "j")); | ||
assertEquals(queryOrder, listenerOrder); | ||
} | ||
|
||
|
@@ -1329,6 +1345,10 @@ public void snapshotListenerSortsUnicodeStringsInDocumentKeySameWayAsServer() th | |
.set(col.document("P"), map("value", "foo")) | ||
.set(col.document("︒"), map("value", "foo")) | ||
.set(col.document("🐵"), map("value", "foo")) | ||
.set(col.document("你好"), map("value", "你好")) | ||
.set(col.document("你顥"), map("value", "你顥")) | ||
.set(col.document("😁"), map("value", "😁")) | ||
.set(col.document("😀"), map("value", "😀")) | ||
.commit() | ||
.get(); | ||
|
||
|
@@ -1353,7 +1373,9 @@ public void snapshotListenerSortsUnicodeStringsInDocumentKeySameWayAsServer() th | |
registration.remove(); | ||
|
||
assertEquals( | ||
queryOrder, Arrays.asList("Sierpiński", "Łukasiewicz", "岩澤", "︒", "P", "🄟", "🐵")); | ||
queryOrder, | ||
Arrays.asList( | ||
"Sierpiński", "Łukasiewicz", "你好", "你顥", "岩澤", "︒", "P", "🄟", "🐵", "😀", "😁")); | ||
assertEquals(queryOrder, listenerOrder); | ||
} | ||
} |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this be
left.length() - i
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why? do u mean encode all the remaining strings? 🤔
But we have confirmed that we encountered the characters that differ, which could be up to 2 index, considering surrogate pairs. If we are already promised that we can find the difference within 2 indexes, is there still a need to encode all remaining? for example, "ab👍cdefghjklm..." vs "ab👎ghjkiuytrd....".
I think substrings 2 indexes is already being very generous
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ahh you're right. I incorrectly thought
left.length()
was the number of chars in the substring. My bad. Nevermind this comment 🤦There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: @milaGGL I would improve the following comment to be more descriptive (along the lines of what you said above):
changing
// UTF-8 encoded byte comparison, substring 2 indexes to cover surrogate pairs
to