morrySnow commented on code in PR #49087:
URL: https://github.com/apache/doris/pull/49087#discussion_r1998176894


##########
fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/executable/StringArithmetic.java:
##########
@@ -79,6 +79,8 @@ public static Expression 
concatVarcharVarchar(StringLikeLiteral first, StringLik
     }
 
     private static String substringImpl(String first, int second, int third) {
+        second = first.offsetByCodePoints(0, second);
+        third = first.offsetByCodePoints(0, third);
         int stringLength = first.length();

Review Comment:
   stringLength should also use CodePoints length? use `first.codePointCount`



##########
fe/fe-core/src/main/java/org/apache/doris/catalog/BuiltinScalarFunctions.java:
##########
@@ -915,8 +913,8 @@ public class BuiltinScalarFunctions implements 
FunctionHelper {
             scalar(StY.class, "st_y"),
             scalar(StartsWith.class, "starts_with"),
             scalar(Strcmp.class, "strcmp"),
-            scalar(StrLeft.class, "strleft"),
-            scalar(StrRight.class, "strright"),
+            scalar(Left.class, "strleft"),
+            scalar(Right.class, "strright"),

Review Comment:
   merge them with "left" and "right" into one line for one function 



##########
fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/executable/StringArithmetic.java:
##########
@@ -291,10 +293,11 @@ public static Expression replace(StringLikeLiteral first, 
StringLikeLiteral seco
     public static Expression left(StringLikeLiteral first, IntegerLiteral 
second) {
         if (second.getValue() <= 0) {
             return castStringLikeLiteral(first, "");
-        } else if (second.getValue() < first.getValue().length()) {
-            return castStringLikeLiteral(first, first.getValue().substring(0, 
second.getValue()));
-        } else {
+        } else if (second.getValue() > first.getValue().length()) {

Review Comment:
   should compare with `first.getValue().codePointCount()`



##########
fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/executable/StringArithmetic.java:
##########
@@ -79,6 +79,8 @@ public static Expression 
concatVarcharVarchar(StringLikeLiteral first, StringLik
     }
 
     private static String substringImpl(String first, int second, int third) {
+        second = first.offsetByCodePoints(0, second);
+        third = first.offsetByCodePoints(0, third);

Review Comment:
   may throw IndexOutOfBoundsException. should check with `first.codePointCount`



-- 
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: commits-unsubscr...@doris.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org
For additional commands, e-mail: commits-h...@doris.apache.org

Reply via email to