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


##########
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:
   Redundant now?



##########
flink-table/flink-table-planner/src/test/java/org/apache/flink/table/planner/functions/CoalesceFunctionITCase.java:
##########
@@ -272,7 +272,23 @@ null, new BigDecimal("1.23"), new BigDecimal("9876543.21"))
                                 coalesce($("f0"), $("f1"), $("f2")),
                                 "COALESCE(f0, f1, f2)",
                                 Duration.ofSeconds(10),
-                                INTERVAL(SECOND(3)).notNull()));
+                                INTERVAL(SECOND(3)).notNull()),
+
+                // nullable field, NOT NULL literal last
+                TestSetSpec.forFunction(
+                                BuiltInFunctionDefinitions.COALESCE, 
"VARCHAR(20) and CHAR literal")
+                        .onFieldsWithData(null, "Bob")
+                        .andDataTypes(VARCHAR(20).nullable(), 
VARCHAR(20).nullable())
+                        .testResult(
+                                coalesce($("f0"), "_"),
+                                "COALESCE(f0, '_')",
+                                "_",
+                                VARCHAR(20).notNull())
+                        .testResult(
+                                coalesce($("f1"), "_"),
+                                "COALESCE(f1, '_')",
+                                "Bob",
+                                VARCHAR(20).notNull()));

Review Comment:
   Why add these tests?



##########
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:
   Could we reuse the ASCII prefix verified by the first scan?



-- 
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