kishoreg commented on a change in pull request #5406:
URL: https://github.com/apache/incubator-pinot/pull/5406#discussion_r427597340



##########
File path: 
pinot-common/src/main/java/org/apache/pinot/sql/parsers/CalciteSqlParser.java
##########
@@ -615,7 +620,44 @@ private static Expression toExpression(SqlNode node) {
             funcExpr.getFunctionCall().addToOperands(toExpression(child));
           }
         }
+
+        if (FunctionRegistry.containsFunctionByName(funcName) && 
isCompileTimeEvaluationPossible(funcExpr)) {
+          int functionOperandsLength = funcSqlNode.getOperands().length;
+          FunctionInfo functionInfo = 
FunctionRegistry.getFunctionByName(funcName);
+          Object[] arguments = new Object[functionOperandsLength];
+          for (int i = 0; i < functionOperandsLength; i++) {
+            SqlLiteral argSqlNode = (SqlLiteral) funcSqlNode.getOperands()[i];
+            arguments[i] = argSqlNode.toValue();
+          }
+          try {
+            FunctionInvoker invoker = new FunctionInvoker(functionInfo);
+            funcExpr = 
RequestUtils.getLiteralExpression(invoker.process(arguments).toString());
+          } catch (Exception e) {
+            throw new SqlCompilationException("Unsupported Scalar function - " 
+ funcName);
+          }
+        }
         return funcExpr;
     }
   }
+
+  /**
+   * Utility method to check if the function can be evaluated during the query 
compilation phae
+   * @param funcExpr
+   * @return true if all arguments are literals
+   */
+  private static boolean isCompileTimeEvaluationPossible(Expression funcExpr) {

Review comment:
       +1




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