cgivre commented on a change in pull request #2227:
URL: https://github.com/apache/drill/pull/2227#discussion_r637473489



##########
File path: 
exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/StringFunctions.java
##########
@@ -434,6 +434,64 @@ public void eval() {
 
   }
 
+  @FunctionTemplate(name = "split_part", scope = FunctionScope.SIMPLE, nulls = 
NullHandling.NULL_IF_NULL,
+    outputWidthCalculatorType = 
OutputWidthCalculatorType.CUSTOM_FIXED_WIDTH_DEFAULT)
+  public static class SplitPartStartEnd implements DrillSimpleFunc {
+    @Param
+    VarCharHolder in;
+    @Param
+    VarCharHolder delimiter;
+    @Param
+    IntHolder start;
+    @Param
+    IntHolder end;
+
+    @Workspace
+    com.google.common.base.Splitter splitter;
+
+    @Workspace
+    com.google.common.base.Joiner joiner;
+
+    @Inject
+    DrillBuf buffer;
+
+    @Output
+    VarCharHolder out;
+
+    @Override
+    public void setup() {
+      if (start.value < 1) {

Review comment:
       > Hi cgivre, thanks for your review. I don't understand your question: 
"What happens if the start and end values are dynamic?". In my option, 
SplitPartStartEnd is choosen as the function only when all four parameters are 
provided, so what does dynamic mean here?
   
   Hi Leon, 
   What I was asking here is that you do all the validation checking in the 
`setup()` function which is executed once.   If a user executes the following 
query:
   
   ```sql
   SELECT split_part(<text>, <delim>, <expression>, <expression>)
   ```
   Those expressions will only be validated on the first row.  This is fine if 
they are constants, but if they are say, values from other columns, or 
something that is computed on the fly, the I don't think the function will do 
what you are expecting it to do.  I'd suggest moving all that logic to the 
`eval()` method.
   
   




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

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to