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



##########
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:
       Instead of this, why don't we just have a constant value function 
registry  where all compile time evaluated functions are registered. So this 
check then becomes if the function is part of the constant value function 
registry.




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