github-actions[bot] commented on code in PR #64366:
URL: https://github.com/apache/doris/pull/64366#discussion_r3394218612


##########
fe/fe-core/src/main/java/org/apache/doris/nereids/StatementContext.java:
##########
@@ -345,15 +348,26 @@ public StatementContext(int initialId) {
     }
 

Review Comment:
   This captures `statementStartTime` as a `LocalDateTime` in the current 
session time zone before query-level `SET_VAR` hints are applied. 
`SET_VAR(time_zone=...)` is applied later from `LogicalPlanBuilder.withHints()` 
/ `EliminateLogicalSelectHint`, so with a session in `+08:00`, `select /*+ 
SET_VAR(time_zone='+00:00', enable_fold_nondeterministic_fn=true) */ now()` 
will fold the `+08:00` wall-clock timestamp even though the statement is 
supposed to run in `+00:00`. Because `LocalDateTime` carries no zone or 
instant, the value cannot be corrected when the hint changes the effective time 
zone. Please store the statement start as an instant or epoch timestamp and 
convert with the effective session time zone after `SET_VAR` has been applied, 
or refresh this timestamp after applying `time_zone` hints.



##########
fe/fe-core/src/main/java/org/apache/doris/nereids/rules/expression/rules/FoldConstantRuleOnFE.java:
##########
@@ -547,6 +549,19 @@ public Expression visitTryCast(TryCast cast, 
ExpressionRewriteContext context) {
         }
     }
 
+    @Override
+    public Expression visitNow(Now now, ExpressionRewriteContext context) {
+        now = rewriteChildren(now, context);
+        Optional<Expression> checkedExpr = preProcess(now);
+        if (checkedExpr.isPresent()) {
+            return checkedExpr.get();
+        }
+        int precision = now.arity() == 0 ? 0
+                : ((IntegerLiteral) now.child(0)).getValue();

Review Comment:
   This FE-folded literal is still disconnected from the timestamp that BE uses 
for runtime `now`/`current_timestamp` calls. Nonliteral precision is supported 
today (`now(kint)` exists in the regression suite), and `preProcess(now)` 
returns those calls unchanged because not all arguments are literals. In a 
statement like `select now(), now(kint) from fn_test where kint is not null`, 
`now()` is folded from `StatementContext.statementStartTime`, while `now(kint)` 
is evaluated by BE from `TQueryGlobals` populated later with a fresh 
`LocalDateTime.now()` / `System.currentTimeMillis()`. If planning crosses a 
second or microsecond boundary, one execution can still observe different `now` 
values. Please derive the BE query globals from the same statement timestamp, 
or keep these functions on one evaluation path so all `now` variants share one 
instant.



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