github-actions[bot] commented on code in PR #66795:
URL: https://github.com/apache/doris/pull/66795#discussion_r4677343179
##########
fe/fe-core/src/main/java/org/apache/doris/nereids/rules/analysis/SessionVarGuardRewriter.java:
##########
@@ -49,12 +94,64 @@
* If you need to add a guard to the plan tree, use rewritePlanTree()
* */
public class SessionVarGuardRewriter extends ExpressionRewrite {
+ // Guard family masks: which session-variable dependency family must be
guarded in a cache.
+ // The mask is computed from the actual difference between the query
session and the object creation
+ // session, so a time-zone-only difference never disables rewrite of
expressions that depend on other
+ // variables (e.g. integer SUM over a decimal256 setting) and vice versa.
+ public static final int GUARD_NONE = 0;
+ public static final int GUARD_TIME_ZONE = 1;
+ public static final int GUARD_OTHER = 2;
+
+ /**
+ * The current-time functions whose value is the wall clock read in the
session time zone. They are
+ * non-deterministic as well, but the reason a stored (materialized)
expression cannot use them is the
+ * zone: the legacy tree folds them as planning-time constants, so the
materialized value keeps the
+ * session zone of whoever evaluated it first.
+ */
+ private static final Set<String> SESSION_ZONE_CLOCK_FUNCTIONS =
ImmutableSet.of(
+ "current_date", "curdate", "current_time", "curtime", "now",
"current_timestamp",
+ "localtime", "localtimestamp", "sysdate");
+
+ // These functions convert epoch seconds to session-local calendar values.
+ private static final Set<String> SESSION_ZONE_EPOCH_FUNCTIONS =
ImmutableSet.of(
+ "from_unixtime", "hour_from_unixtime");
Review Comment:
[P1] Include local-calendar UNIX_TIMESTAMP conversions in the zone fence
UNIX_TIMESTAMP over DATE/DATETIME (or an offset-free string) also depends on
the session zone, but it is absent from this shared set and has no TIMESTAMPTZ
descendant or NeedSessionVarGuard marker. Both new classifiers therefore accept
it. For example, BIGINT GENERATED ALWAYS AS (unix_timestamp(dt)) passes CREATE
TABLE, yet dt = '2024-01-01 00:00:00' materializes 1704067200 in UTC and
1704038400 in +08:00: BE reads RuntimeState.timezone_obj(), so the persisted FE
variables do not preserve one value.
The async path likewise leaves Project(unix_timestamp(dt) AS epoch) ->
Scan(t) unguarded for a time-zone-only mask, allowing rewriteExpression to
substitute Project(mv_scan.epoch) -> Scan(mv) in the other zone. Classify the
local-calendar-to-epoch overloads in both paths and cover cross-zone
stored-column loads and async rewrites. This is the inverse conversion missing
independently of the already-reported epoch-to-calendar functions.
--
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]