[ 
https://issues.apache.org/jira/browse/DRILL-8094?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17467120#comment-17467120
 ] 

ASF GitHub Bot commented on DRILL-8094:
---------------------------------------

Leon-WTF commented on a change in pull request #2416:
URL: https://github.com/apache/drill/pull/2416#discussion_r776938643



##########
File path: 
exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/StringFunctions.java
##########
@@ -416,16 +417,25 @@ public void setup() {
 
     @Override
     public void eval() {
-      if (index.value < 1) {
+      if (index.value == 0) {
         throw org.apache.drill.common.exceptions.UserException.functionError()
-          .message("Index in split_part must be positive, value provided was "
-            + index.value).build();
+          .message("Index in split_part can not be zero").build();
       }
       String inputString = org.apache.drill.exec.expr.fn.impl.
         StringFunctionHelpers.getStringFromVarCharHolder(in);
-      int arrayIndex = index.value - 1;
-      String result =
-              (String) 
com.google.common.collect.Iterables.get(splitter.split(inputString), 
arrayIndex, "");
+      String result = "";
+      if (index.value < 0) {
+        java.util.List<String> splits = splitter.splitToList(inputString);
+        int size = splits.size();
+        int arrayIndex = size + index.value;
+        if (arrayIndex >= 0) {

Review comment:
       > What happens when arrayIndex < 0 here? An informative error would be 
better than uninitialised result data
   
   I think arrayIndex < 0 is not an error, it will return the empty string, see 
the case below in UT.
       testBuilder()
         .sqlQuery("select split_part('a,b,c', ',', -4) res1 from (values(1))")
         .ordered()
         .baselineColumns("res1")
         .baselineValues("")
         .go();
   Same as:
       testBuilder()
           .sqlQuery("select split_part('a,b,c', ',', 4) res1 from (values(1))")
           .ordered()
           .baselineColumns("res1")
           .baselineValues("")
           .go();




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


> Support reverse truncation for split_part udf
> ---------------------------------------------
>
>                 Key: DRILL-8094
>                 URL: https://issues.apache.org/jira/browse/DRILL-8094
>             Project: Apache Drill
>          Issue Type: Improvement
>            Reporter: wtf
>            Priority: Minor
>
> suport split_part('a,b,c,d', ',' , -2, -1) = 'c,d' and split_part('a,b,c,d', 
> ',' , -3) = 'b'



--
This message was sent by Atlassian Jira
(v8.20.1#820001)

Reply via email to