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


##########
pinot-common/src/main/java/org/apache/pinot/common/function/scalar/StringFunctions.java:
##########
@@ -597,6 +596,39 @@ public static String splitPart(String input, String 
delimiter, int index) {
     }
   }
 
+  /**
+   * @param input the input String to be split into parts.
+   * @param delimiter the specified delimiter to split the input string.
+   * @param index the specified index for the splitted parts to be returned.
+   * @param max the max count of parts that the input string can be splitted 
into.
+   * @return splits string on the delimiter with the limit count and returns 
String at specified index from the split.
+   */
+  @ScalarFunction
+  public static String splitPart(String input, String delimiter, int index, 
int max) {

Review Comment:
   I feel putting `max` in front of `index` is more intuitive



##########
pinot-common/src/main/java/org/apache/pinot/common/function/scalar/StringFunctions.java:
##########
@@ -597,6 +596,39 @@ public static String splitPart(String input, String 
delimiter, int index) {
     }
   }
 
+  /**
+   * @param input the input String to be split into parts.
+   * @param delimiter the specified delimiter to split the input string.
+   * @param index the specified index for the splitted parts to be returned.
+   * @param max the max count of parts that the input string can be splitted 
into.
+   * @return splits string on the delimiter with the limit count and returns 
String at specified index from the split.
+   */
+  @ScalarFunction
+  public static String splitPart(String input, String delimiter, int index, 
int max) {
+    String[] splitString = StringUtils.splitByWholeSeparator(input, delimiter, 
max);
+    if (index < splitString.length) {
+      return splitString[index];
+    } else {
+      return "null";
+    }
+  }
+
+  /**
+   * @param input the input String to be split into parts.
+   * @param delimiter the specified delimiter to split the input string.
+   * @param index the specified index for the splitted parts to be returned.
+   * @return splits string on the delimiter with the limit count and returns 
String at specified index from the split.
+   */
+  @ScalarFunction
+  public static String splitPartFromEnd(String input, String delimiter, int 
index) {

Review Comment:
   Seems we are already not following the PostgreSQL semantic where `position` 
starts from 1. So I'd suggest allowing negative value for `index` which 
indicates the index from end. When it is negative, we can simply pick the one 
from `length + index`



-- 
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...@pinot.apache.org

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


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

Reply via email to