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



##########
File path: 
pinot-common/src/main/java/org/apache/pinot/sql/parsers/CalciteSqlParser.java
##########
@@ -615,7 +618,47 @@ private static Expression toExpression(SqlNode node) {
             funcExpr.getFunctionCall().addToOperands(toExpression(child));
           }
         }
+
+        if (FunctionDefinitionRegistry.isScalarFunc(funcName) && 
isCompileTimeEvaluationPossible(funcExpr)) {
+
+          ScalarFunctionType scalarFunctionType = 
ScalarFunctionType.getScalarFunctionType(funcName);
+          switch (scalarFunctionType) {
+            case NOW:
+              funcExpr = 
RequestUtils.getLiteralExpression(System.currentTimeMillis());
+              break;
+            case FORMAT_DATETIME:
+              //DATETIME_FORMAT ('2020-01-01', 'yyyy-MM-dd')
+              String input = 
funcExpr.getFunctionCall().getOperands().get(0).getLiteral().getStringValue();
+              String format = 
funcExpr.getFunctionCall().getOperands().get(1).getLiteral().getStringValue();
+              long output = 
DateTimeFormat.forPattern(format).parseMillis(input);
+              funcExpr = RequestUtils.getLiteralExpression(output);

Review comment:
       Most of the functions are already available in FunctionRegistry and 
FunctionInvoker added by @npawar. Unfortunately, those functions are in 
pinot-core, we can move the scalar functions into pinot-common in another PR 
and remove custom implementation for now and datetime format 




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