snuyanzin commented on code in PR #30065:
URL: https://github.com/apache/flink/pull/30065#discussion_r4681138760


##########
flink-table/flink-table-common/src/main/java/org/apache/flink/table/data/binary/BinaryStringData.java:
##########
@@ -311,8 +312,20 @@ private int compareMultiSegments(BinaryStringData other) {
 
     /** Returns the number of UTF-8 code points in the string. */
     public int numChars() {
+        if (binarySection == null) {
+            // the count of the UTF-8 bytes without encoding them: a lone 
surrogate is encoded as
+            // '?', so it is one character, like a surrogate pair. Once there 
are bytes, they are
+            // counted, since a string decoded from invalid UTF-8 can have a 
different count
+            return javaObject.codePointCount(0, javaObject.length());
+        }
         ensureMaterialized();
         if (inFirstSegment()) {
+            final byte[] array = binarySection.segments[0].getHeapMemory();
+            if (array != null
+                    && SwarUtils.isAscii(array, binarySection.offset, 
binarySection.sizeInBytes)) {

Review Comment:
   yep, makes sense, added



##########
flink-table/flink-table-common/src/main/java/org/apache/flink/table/data/binary/BinaryStringData.java:
##########
@@ -311,8 +312,20 @@ private int compareMultiSegments(BinaryStringData other) {
 
     /** Returns the number of UTF-8 code points in the string. */
     public int numChars() {
+        if (binarySection == null) {
+            // the count of the UTF-8 bytes without encoding them: a lone 
surrogate is encoded as
+            // '?', so it is one character, like a surrogate pair. Once there 
are bytes, they are
+            // counted, since a string decoded from invalid UTF-8 can have a 
different count
+            return javaObject.codePointCount(0, javaObject.length());
+        }
         ensureMaterialized();

Review Comment:
   correct, dropped, thanks



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to