This is an automated email from the ASF dual-hosted git repository.
yiguolei pushed a commit to branch branch-4.1
in repository https://gitbox.apache.org/repos/asf/doris.git
The following commit(s) were added to refs/heads/branch-4.1 by this push:
new a4ea51fdb8b branch-4.1: [fix](user variable) Preserve TIMESTAMPTZ user
variable type #66833 (#67128)
a4ea51fdb8b is described below
commit a4ea51fdb8b67b9d97f47ce4c93291f728b3dcba
Author: github-actions[bot]
<41898282+github-actions[bot]@users.noreply.github.com>
AuthorDate: Fri Aug 28 20:55:43 2026 +0800
branch-4.1: [fix](user variable) Preserve TIMESTAMPTZ user variable type
#66833 (#67128)
Cherry-picked from #66833
Co-authored-by: Mryange <[email protected]>
---
.../main/java/org/apache/doris/qe/ConnectContext.java | 3 +++
.../rules/analysis/UserVariableAnalysisTest.java | 17 +++++++++++++++++
.../timestamptz/test_timestamptz_dst_fold.out | 7 +++++++
.../timestamptz/test_timestamptz_dst_fold.groovy | 11 +++++++++++
4 files changed, 38 insertions(+)
diff --git a/fe/fe-core/src/main/java/org/apache/doris/qe/ConnectContext.java
b/fe/fe-core/src/main/java/org/apache/doris/qe/ConnectContext.java
index 332ed53640a..1ad07cae935 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/qe/ConnectContext.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/qe/ConnectContext.java
@@ -18,6 +18,7 @@
package org.apache.doris.qe;
import org.apache.doris.analysis.BoolLiteral;
+import org.apache.doris.analysis.DateLiteral;
import org.apache.doris.analysis.DecimalLiteral;
import org.apache.doris.analysis.FloatLiteral;
import org.apache.doris.analysis.IntLiteral;
@@ -674,6 +675,8 @@ public class ConnectContext {
return Literal.of(((FloatLiteral) literalExpr).getValue());
} else if (literalExpr instanceof DecimalLiteral) {
return Literal.of(((DecimalLiteral) literalExpr).getValue());
+ } else if (literalExpr instanceof DateLiteral) {
+ return Literal.fromLegacyLiteral(literalExpr,
literalExpr.getType());
} else if (literalExpr instanceof StringLiteral) {
return Literal.of(((StringLiteral) literalExpr).getValue());
} else if (literalExpr instanceof NullLiteral) {
diff --git
a/fe/fe-core/src/test/java/org/apache/doris/nereids/rules/analysis/UserVariableAnalysisTest.java
b/fe/fe-core/src/test/java/org/apache/doris/nereids/rules/analysis/UserVariableAnalysisTest.java
index e7ea8b491ea..2dd8ca07be5 100644
---
a/fe/fe-core/src/test/java/org/apache/doris/nereids/rules/analysis/UserVariableAnalysisTest.java
+++
b/fe/fe-core/src/test/java/org/apache/doris/nereids/rules/analysis/UserVariableAnalysisTest.java
@@ -17,12 +17,17 @@
package org.apache.doris.nereids.rules.analysis;
+import org.apache.doris.analysis.DateLiteral;
import org.apache.doris.analysis.IntLiteral;
import org.apache.doris.analysis.LargeIntLiteral;
+import org.apache.doris.catalog.ScalarType;
+import org.apache.doris.nereids.trees.expressions.literal.Literal;
+import org.apache.doris.nereids.trees.expressions.literal.TimestampTzLiteral;
import org.apache.doris.nereids.types.BigIntType;
import org.apache.doris.nereids.types.IntegerType;
import org.apache.doris.nereids.types.LargeIntType;
import org.apache.doris.nereids.types.SmallIntType;
+import org.apache.doris.nereids.types.TimeStampTzType;
import org.apache.doris.nereids.types.TinyIntType;
import org.apache.doris.nereids.util.MemoTestUtils;
import org.apache.doris.qe.ConnectContext;
@@ -53,4 +58,16 @@ public class UserVariableAnalysisTest {
Assertions.assertEquals(BigIntType.INSTANCE,
ConnectContext.get().getLiteralForUserVar("d").getDataType());
Assertions.assertEquals(LargeIntType.INSTANCE,
ConnectContext.get().getLiteralForUserVar("e").getDataType());
}
+
+ @Test
+ public void testUserVarTimestampTzType() {
+ ConnectContext ctx = MemoTestUtils.createConnectContext();
+ ctx.setUserVar("ts", new DateLiteral(
+ 2024, 11, 3, 5, 5, 0, 123456,
ScalarType.createTimeStampTzType(6)));
+
+ Literal literal = ctx.getLiteralForUserVar("ts");
+ Assertions.assertInstanceOf(TimestampTzLiteral.class, literal);
+ Assertions.assertEquals(TimeStampTzType.of(6), literal.getDataType());
+ Assertions.assertEquals("2024-11-03 05:05:00.123456+00:00",
literal.getStringValue());
+ }
}
diff --git
a/regression-test/data/datatype_p0/timestamptz/test_timestamptz_dst_fold.out
b/regression-test/data/datatype_p0/timestamptz/test_timestamptz_dst_fold.out
index a2dba24a802..ab8c18ca9cb 100644
--- a/regression-test/data/datatype_p0/timestamptz/test_timestamptz_dst_fold.out
+++ b/regression-test/data/datatype_p0/timestamptz/test_timestamptz_dst_fold.out
@@ -1,4 +1,11 @@
-- This file is automatically generated. You should know what you did if you
want to edit this
+-- !user_var_render --
+2024-11-03 01:05:00.000000-04:00
+
+-- !user_var_comparison --
+1 pre_fold_utc
+3 pre_explicit
+
-- !sql --
1 pre_fold_utc 2024-11-03 01:05:00.000000-04:00
2 post_fold_utc 2024-11-03 01:05:00.000000-05:00
diff --git
a/regression-test/suites/datatype_p0/timestamptz/test_timestamptz_dst_fold.groovy
b/regression-test/suites/datatype_p0/timestamptz/test_timestamptz_dst_fold.groovy
index a090b6f0957..161bfb84682 100644
---
a/regression-test/suites/datatype_p0/timestamptz/test_timestamptz_dst_fold.groovy
+++
b/regression-test/suites/datatype_p0/timestamptz/test_timestamptz_dst_fold.groovy
@@ -41,6 +41,17 @@ suite("test_timestamptz_dst_fold") {
(4, 'post_explicit', CAST('2024-11-03 01:05:00 -05:00' AS
TIMESTAMPTZ(6)));
"""
+ sql "SET time_zone = '+00:00';"
+ sql "SET @dst_fold_ts = CAST('2024-11-03 05:05:00 +00:00' AS
TIMESTAMPTZ(6));"
+ sql "SET time_zone = 'America/New_York';"
+ qt_user_var_render "SELECT CAST(@dst_fold_ts AS VARCHAR(64));"
+ order_qt_user_var_comparison """
+ SELECT id, label
+ FROM tz_dst_fold_events
+ WHERE ts = @dst_fold_ts
+ ORDER BY id;
+ """
+
sql "SET debug_skip_fold_constant = true;"
qt_sql """
SELECT id, label, CAST(ts AS VARCHAR(64)) AS rendered
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]