Jackie-Jiang commented on code in PR #17428:
URL: https://github.com/apache/pinot/pull/17428#discussion_r2673823281


##########
pinot-common/src/main/java/org/apache/pinot/common/function/scalar/StringFunctions.java:
##########
@@ -551,17 +555,234 @@ public static String[] suffixesWithSuffix(String input, 
int maxlength, @Nullable
    */
   @ScalarFunction
   public static String splitPart(String input, String delimiter, int index) {
-    String[] splitString = StringUtils.splitByWholeSeparator(input, delimiter);
-    if (index >= 0 && index < splitString.length) {
-      return splitString[index];
-    } else if (index < 0 && index >= -splitString.length) {
-      return splitString[splitString.length + index];
-    } else {
-      return "null";
-    }
+      if (input == null || delimiter == null) {

Review Comment:
   We don't need to handle `null` as the scalar function framework is able to 
handle them



##########
pinot-common/src/main/java/org/apache/pinot/common/function/scalar/StringFunctions.java:
##########
@@ -551,17 +555,234 @@ public static String[] suffixesWithSuffix(String input, 
int maxlength, @Nullable
    */
   @ScalarFunction
   public static String splitPart(String input, String delimiter, int index) {
-    String[] splitString = StringUtils.splitByWholeSeparator(input, delimiter);
-    if (index >= 0 && index < splitString.length) {
-      return splitString[index];
-    } else if (index < 0 && index >= -splitString.length) {
-      return splitString[splitString.length + index];
-    } else {
-      return "null";
-    }
+      if (input == null || delimiter == null) {

Review Comment:
   Please follow [Pinot 
Style](https://docs.pinot.apache.org/developers/developers-and-contributors/code-setup#set-up-ide)



##########
pinot-common/src/main/java/org/apache/pinot/common/function/scalar/StringFunctions.java:
##########
@@ -551,17 +555,234 @@ public static String[] suffixesWithSuffix(String input, 
int maxlength, @Nullable
    */
   @ScalarFunction
   public static String splitPart(String input, String delimiter, int index) {
-    String[] splitString = StringUtils.splitByWholeSeparator(input, delimiter);
-    if (index >= 0 && index < splitString.length) {
-      return splitString[index];
-    } else if (index < 0 && index >= -splitString.length) {
-      return splitString[splitString.length + index];
-    } else {
-      return "null";
-    }
+      if (input == null || delimiter == null) {
+          return "null";
+      }
+
+      int delimiterLength = delimiter.length();
+      if (delimiterLength == 0) {
+          return input;
+      }
+
+      String[] splitString;
+      if (index >= 0) {
+          int limit = index + 2;
+          splitString = splitBySeparatorTillLimitForward(input, delimiter, 
limit);

Review Comment:
   Is it possible to directly find the index instead of returning an array then 
look up the index? Same for the backward search



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


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to