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


##########
pinot-common/src/main/java/org/apache/pinot/sql/parsers/rewriter/CompileTimeFunctionsInvoker.java:
##########
@@ -61,38 +64,40 @@ protected static Expression 
invokeCompileTimeFunctionExpression(@Nullable Expres
     List<Expression> operands = function.getOperands();
     int numOperands = operands.size();
     boolean compilable = true;
+    ColumnDataType[] argumentTypes = new ColumnDataType[numOperands];
+    Object[] arguments = new Object[numOperands];
     for (int i = 0; i < numOperands; i++) {
       Expression operand = 
invokeCompileTimeFunctionExpression(operands.get(i));
-      if (operand.getLiteral() == null) {
+      operands.set(i, operand);
+      Literal literal = operand.getLiteral();
+      if (compilable && literal != null) {
+        RequestUtils.getLiteralTypeAndValue(literal, argumentTypes, arguments, 
i);
+      } else {
         compilable = false;
       }
-      operands.set(i, operand);
     }
-    if (compilable) {
-      String canonicalName = 
FunctionRegistry.canonicalize(function.getOperator());
-      FunctionInfo functionInfo = 
FunctionRegistry.lookupFunctionInfo(canonicalName, numOperands);
-      if (functionInfo != null) {
-        Object[] arguments = new Object[numOperands];
-        for (int i = 0; i < numOperands; i++) {
-          arguments[i] = 
RequestUtils.getLiteralValue(function.getOperands().get(i).getLiteral());
-        }
-        try {
-          FunctionInvoker invoker = new FunctionInvoker(functionInfo);
-          Object result;
-          if (invoker.getMethod().isVarArgs()) {
-            result = invoker.invoke(new Object[] {arguments});
-          } else {
-            invoker.convertTypes(arguments);
-            result = invoker.invoke(arguments);
-          }
-          return RequestUtils.getLiteralExpression(result);
-        } catch (Exception e) {
-          throw new SqlCompilationException(
-              "Caught exception while invoking method: " + 
functionInfo.getMethod() + " with arguments: "
-                  + Arrays.toString(arguments), e);
-        }
+    if (!compilable) {
+      return expression;
+    }
+    String canonicalName = 
FunctionRegistry.canonicalize(function.getOperator());
+    FunctionInfo functionInfo = 
FunctionRegistry.lookupFunctionInfo(canonicalName, argumentTypes);

Review Comment:
   The scalar function should take care of all possible combinations of 
argument types, similar to the backward compatible logic in 
`PolymorphicComparisonScalarFunction` when argument type is different



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