AlbericByte commented on code in PR #15586:
URL: https://github.com/apache/druid/pull/15586#discussion_r1432057331


##########
processing/src/main/java/org/apache/druid/query/expression/TimestampExtractExprMacro.java:
##########
@@ -73,38 +75,39 @@ public Expr apply(final List<Expr> args)
       throw validationFailed("unit arg must be literal");
     }
 
-    if (args.size() > 2) {
-      validationHelperCheckArgIsLiteral(args.get(2), "timezone");
+    Optional<DateTimeZone> timeZone = Optional.empty();
+    if (args.size() > 2 && args.get(2).isLiteral()) {
+      timeZone = Optional.of(ExprUtils.toTimeZone(args.get(2)));
     }
 
-    final Expr arg = args.get(0);
     final Unit unit = Unit.valueOf(StringUtils.toUpperCase((String) 
args.get(1).getLiteralValue()));
-    final DateTimeZone timeZone;
 
-    if (args.size() > 2) {
-      timeZone = ExprUtils.toTimeZone(args.get(2));
-    } else {
-      timeZone = DateTimeZone.UTC;
-    }
-
-    final ISOChronology chronology = ISOChronology.getInstance(timeZone);
+    final Optional<ISOChronology> chronologyOptional = timeZone.map(value -> 
ISOChronology.getInstance(value));
 
-    class TimestampExtractExpr extends 
ExprMacroTable.BaseScalarUnivariateMacroFunctionExpr
+    class TimestampExtractExpr extends 
ExprMacroTable.BaseScalarMacroFunctionExpr
     {
-      private TimestampExtractExpr(Expr arg)
+      private TimestampExtractExpr(List<Expr> args)
       {
-        super(FN_NAME, arg);
+        super(FN_NAME, args);
       }
 
       @Nonnull
       @Override
       public ExprEval eval(final ObjectBinding bindings)
       {
-        Object val = arg.eval(bindings).value();
+        Object val = args.get(0).eval(bindings).value();
         if (val == null) {
           // Return null if the argument if null.
           return ExprEval.of(null);
         }
+        final ISOChronology chronology = chronologyOptional.orElseGet(() -> {
+          Optional<String> timeZoneOptional = args.size() > 2

Review Comment:
   the test error "Error while executing SQL "SELECT * FROM 
INFORMATION_SCHEMA.COLUMNS": Remote driver error: Unauthorized" should be 
irrelevant to my modification.



-- 
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: [email protected]

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


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to