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 3a21b272ef0 [fix](fe) Backport TIMESTAMPTZ output bounds to branch-4.1
(#71188)
3a21b272ef0 is described below
commit 3a21b272ef004a84d0e43dc05b462aae2fc6c8b2
Author: Gabriel <[email protected]>
AuthorDate: Tue Dec 1 18:13:00 2026 +0800
[fix](fe) Backport TIMESTAMPTZ output bounds to branch-4.1 (#71188)
### What problem does this PR solve?
Issue Number: None
Related PR: apache/doris#70335
Backport apache/doris#70335 to `branch-4.1`. FE constant TIMESTAMPTZ
output must reject session-local years outside 0–9999, preserve
historical offset seconds, and keep valid UTC instants writable. Cloud
EXPLAIN must check FE execution eligibility without formatting SELECT
results.
The requested master merge order is apache/doris#70079,
apache/doris#70154, then apache/doris#70335. The first two changes are
already present in this target through apache/doris#70319; this PR
contains only the missing #70335.
The backport uses the release branch's legacy DateLiteral/FormatOptions
formatter and retains its three-argument SQL cache API. Scalar and
nested stream-load values remain canonical UTC; timezone conversion also
rejects negative-year defaults.
### Testing
- Targeted FE unit tests: 48 total, 46 passed, 2 existing disabled tests
skipped; zero failures/errors. This includes cloud planning without a
compute group, actual SELECT errors, parser/display boundaries,
historical offsets, nested UTC storage, FE eligibility and backend
fallbacks.
- FE Checkstyle passed with zero violations.
- Before the fix, the seven timestamp output tests reproduced six
assertion failures and zero errors; the same tests all pass after the
fix.
The upstream SQL regression suite and its generated expected output are
included unchanged. Live FE/BE SQL regression was not run locally for
this backport.
### Release note
TIMESTAMPTZ constant-query output rejects out-of-range session-local
years and preserves historical offset seconds. Valid UTC boundary values
remain writable, negative-year defaults are rejected, and cloud EXPLAIN
remains available for values whose display would overflow.
### Check List (For Author)
- [x] Unit tests
- [x] Regression tests included
- Behavior changed: Yes, as described above.
- Documentation required: No; this enforces the existing timestamp range
and timezone contract.
---
.../org/apache/doris/analysis/DateLiteral.java | 27 +--
.../main/java/org/apache/doris/analysis/Expr.java | 2 +-
.../org/apache/doris/analysis/StructLiteral.java | 1 +
.../org/apache/doris/nereids/NereidsPlanner.java | 8 +-
.../nereids/trees/plans/ComputeResultSet.java | 3 +
.../plans/physical/PhysicalBlackholeSink.java | 6 +
.../plans/physical/PhysicalEmptyRelation.java | 5 +
.../plans/physical/PhysicalOneRowRelation.java | 47 ++---
.../trees/plans/physical/PhysicalResultSink.java | 6 +
.../trees/plans/physical/PhysicalSqlCache.java | 5 +
.../doris/analysis/TimestampTzQueryOutputTest.java | 189 +++++++++++++++++++++
.../doris/nereids/NereidsPlannerFeResultTest.java | 96 +++++++++++
.../nereids/trees/plans/ComputeResultSetTest.java | 141 +++++++++++++++
.../doris/foundation/format/FormatOptions.java | 14 ++
.../test_timestamptz_fe_output_boundary.out | 35 ++++
.../test_timestamptz_fe_output_boundary.groovy | 135 +++++++++++++++
16 files changed, 682 insertions(+), 38 deletions(-)
diff --git
a/fe/fe-core/src/main/java/org/apache/doris/analysis/DateLiteral.java
b/fe/fe-core/src/main/java/org/apache/doris/analysis/DateLiteral.java
index 6a01c637bbc..8799f7aacf0 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/analysis/DateLiteral.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/analysis/DateLiteral.java
@@ -691,18 +691,23 @@ public class DateLiteral extends LiteralExpr {
@Override
public String getStringValueForQuery(FormatOptions options) {
- if (!type.isTimeStampTz()) {
+ if (!type.isTimeStampTz() || (options != null &&
options.isForStreamLoad())) {
+ // Storage input stays in UTC even when the session-local display
year is out of range.
return getStringValue();
}
- try {
- String offset =
DateUtils.getTimeZone().getRules().getOffset(java.time.Instant.now()).toString();
- DateLiteral dateLiteral = new DateLiteral(getStringValue(),
- ScalarType.createDatetimeV2Type(((ScalarType)
type).getScalarScale()));
- return dateLiteral.getStringValue() + offset;
- } catch (Exception e) {
- LOG.warn("generate timestamptz({})'s string value for query
failed. ", getStringValue(), e);
- return getStringValue();
+ ZonedDateTime localTime = LocalDateTime.of((int) year, (int) month,
(int) day,
+ (int) hour, (int) minute, (int) second, (int) microsecond *
1000)
+
.atZone(java.time.ZoneOffset.UTC).withZoneSameInstant(DateUtils.getTimeZone());
+ int localYear = localTime.getYear();
+ // Match BE output before the fixed-width formatter can corrupt an
out-of-range year.
+ if (localYear < 0 || localYear > 9999) {
+ throw new org.apache.doris.nereids.exceptions.AnalysisException(
+ "TIMESTAMPTZ local year is outside [0, 9999]: year=" +
localYear
+ + ", timezone=" + localTime.getZone());
}
+ DateLiteral localLiteral = new DateLiteral(localTime.toLocalDateTime(),
+ ScalarType.createDatetimeV2Type(((ScalarType)
type).getScalarScale()));
+ return localLiteral.getStringValue() + localTime.getOffset();
}
@Override
@@ -1539,7 +1544,9 @@ public class DateLiteral extends LiteralExpr {
}
private boolean checkRange() {
- return year > MAX_DATETIME.year || month > MAX_DATETIME.month || day >
MAX_DATETIME.day
+ // A time zone conversion can cross year zero even when parsed fields
are nonnegative.
+ return year < MIN_DATETIME.year || year > MAX_DATETIME.year
+ || month > MAX_DATETIME.month || day > MAX_DATETIME.day
|| hour > MAX_DATETIME.hour || minute > MAX_DATETIME.minute ||
second > MAX_DATETIME.second
|| microsecond > MAX_MICROSECOND;
}
diff --git a/fe/fe-core/src/main/java/org/apache/doris/analysis/Expr.java
b/fe/fe-core/src/main/java/org/apache/doris/analysis/Expr.java
index 253d45fa743..e837f0b42ed 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/analysis/Expr.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/analysis/Expr.java
@@ -1015,7 +1015,7 @@ public abstract class Expr extends TreeNode<Expr>
implements Cloneable, ExprStat
* for StructLiteral, the value should not contain sub column's name.
*/
public String getStringValueForStreamLoad(FormatOptions options) {
- return getStringValueForQuery(options);
+ return getStringValueForQuery(options.forStreamLoad());
}
public final TExpr normalize(Normalizer normalizer) {
diff --git
a/fe/fe-core/src/main/java/org/apache/doris/analysis/StructLiteral.java
b/fe/fe-core/src/main/java/org/apache/doris/analysis/StructLiteral.java
index 065c38d8a58..809cadd63b8 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/analysis/StructLiteral.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/analysis/StructLiteral.java
@@ -133,6 +133,7 @@ public class StructLiteral extends LiteralExpr {
@Override
public String getStringValueForStreamLoad(FormatOptions options) {
+ options = options.forStreamLoad();
List<String> list = new ArrayList<>(children.size());
// same with be default field index start with 1
for (int i = 0; i < children.size(); i++) {
diff --git
a/fe/fe-core/src/main/java/org/apache/doris/nereids/NereidsPlanner.java
b/fe/fe-core/src/main/java/org/apache/doris/nereids/NereidsPlanner.java
index cbbb918fa34..a990a7f9400 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/nereids/NereidsPlanner.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/NereidsPlanner.java
@@ -735,15 +735,11 @@ public class NereidsPlanner extends Planner {
}
boolean notNeedBackend = false;
- // if the query can compute without backend, we can skip check cluster
privileges
+ // EXPLAIN also reaches this probe: checking FE eligibility must not
serialize SELECT results.
if (Config.isCloudMode()
&& cascadesContext.getConnectContext().supportHandleByFe()
&& physicalPlan instanceof ComputeResultSet) {
- Optional<ResultSet> resultSet = ((ComputeResultSet)
physicalPlan).computeResultInFe(
- cascadesContext, Optional.empty(),
physicalPlan.getOutput());
- if (resultSet.isPresent()) {
- notNeedBackend = true;
- }
+ notNeedBackend = ((ComputeResultSet)
physicalPlan).canComputeResultInFe(physicalPlan.getOutput());
}
boolean useLoadBackendSelection =
physicalPlan.anyMatch(PhysicalOlapTableSink.class::isInstance);
diff --git
a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/ComputeResultSet.java
b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/ComputeResultSet.java
index f86e143ca7b..8c9a38a199e 100644
---
a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/ComputeResultSet.java
+++
b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/ComputeResultSet.java
@@ -53,6 +53,9 @@ import java.util.Optional;
* </pre>
*/
public interface ComputeResultSet {
+ /** Check FE execution eligibility without materializing or formatting the
requested values. */
+ boolean canComputeResultInFe(List<Slot> outputSlots);
+
Optional<ResultSet> computeResultInFe(CascadesContext cascadesContext,
Optional<SqlCacheContext> sqlCacheContext,
List<Slot> outputSlots);
}
diff --git
a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/physical/PhysicalBlackholeSink.java
b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/physical/PhysicalBlackholeSink.java
index 53666ccab14..25066df772d 100644
---
a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/physical/PhysicalBlackholeSink.java
+++
b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/physical/PhysicalBlackholeSink.java
@@ -131,6 +131,12 @@ public class PhysicalBlackholeSink<CHILD_TYPE extends
Plan> extends PhysicalSink
null, physicalProperties, statistics, child());
}
+ @Override
+ public boolean canComputeResultInFe(List<Slot> outputSlots) {
+ CHILD_TYPE child = child();
+ return child instanceof ComputeResultSet && ((ComputeResultSet)
child).canComputeResultInFe(outputSlots);
+ }
+
@Override
public Optional<ResultSet> computeResultInFe(
CascadesContext cascadesContext, Optional<SqlCacheContext>
sqlCacheContext, List<Slot> outputSlots) {
diff --git
a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/physical/PhysicalEmptyRelation.java
b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/physical/PhysicalEmptyRelation.java
index b1b5ea2beee..717b1143521 100644
---
a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/physical/PhysicalEmptyRelation.java
+++
b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/physical/PhysicalEmptyRelation.java
@@ -116,6 +116,11 @@ public class PhysicalEmptyRelation extends PhysicalRelation
logicalPropertiesSupplier.get(), physicalProperties,
statistics);
}
+ @Override
+ public boolean canComputeResultInFe(List<Slot> outputSlots) {
+ return true;
+ }
+
@Override
public Optional<ResultSet> computeResultInFe(CascadesContext
cascadesContext,
Optional<SqlCacheContext> sqlCacheContext, List<Slot> outputSlots)
{
diff --git
a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/physical/PhysicalOneRowRelation.java
b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/physical/PhysicalOneRowRelation.java
index f61c5584625..2aef551faa7 100644
---
a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/physical/PhysicalOneRowRelation.java
+++
b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/physical/PhysicalOneRowRelation.java
@@ -158,6 +158,26 @@ public class PhysicalOneRowRelation extends
PhysicalRelation implements OneRowRe
logicalPropertiesSupplier.get(), physicalProperties,
statistics);
}
+ @Override
+ public boolean canComputeResultInFe(List<Slot> outputSlots) {
+ for (Slot outputSlot : outputSlots) {
+ for (int i = 0; i < projects.size(); i++) {
+ Slot output = getOutput().get(i);
+ if (outputSlot.getExprId().equals(output.getExprId())
+ && !canComputeLiteralInFe(projects.get(i), output)) {
+ return false;
+ }
+ }
+ }
+ return true;
+ }
+
+ private static boolean canComputeLiteralInFe(NamedExpression item, Slot
output) {
+ // FE result cells are UTF-8 Strings; a VARBINARY round trip can
change the raw bytes.
+ // Leave these outputs to BE until ResultSet supports byte[] cells.
+ return item.child(0) instanceof Literal &&
!output.getDataType().toCatalogDataType().isVarbinaryType();
+ }
+
@Override
public Optional<ResultSet> computeResultInFe(
CascadesContext cascadesContext, Optional<SqlCacheContext>
sqlCacheContext, List<Slot> outputSlots) {
@@ -166,32 +186,17 @@ public class PhysicalOneRowRelation extends
PhysicalRelation implements OneRowRe
for (Slot outputSlot : outputSlots) {
for (int i = 0; i < projects.size(); i++) {
NamedExpression item = projects.get(i);
- NamedExpression output = getOutput().get(i);
+ Slot output = getOutput().get(i);
if (!outputSlot.getExprId().equals(output.getExprId())) {
continue;
}
- Expression expr = item.child(0);
- if (expr instanceof Literal) {
- LiteralExpr legacyExpr = ((Literal)
expr).toLegacyLiteral();
- columns.add(new Column(output.getName(),
output.getDataType().toCatalogDataType()));
- if
(output.getDataType().toCatalogDataType().isVarbinaryType()) {
- // The FE (computeResultInFe) can currently only build
a ResultSet<List<List<String>>>.
- // If we materialize a VARBINARY literal via
legacyExpr.getStringValueForQuery():
- // 1) We first wrap the raw bytes in a Java String.
- // 2) Later StmtExecutor.sendTextResultRow
re-encodes that String as UTF-8 when
- // writing the MySQL wire protocol. This may
expand bytes (e.g. 0xAB becomes
- // two bytes 0xC2 0xAB), so the client observes a
different value than the BE path.
- // The BE execution path is correct because it sends
the raw bytes already serialized
- // for the MySQL protocol without a lossy String
round-trip.
- // Todo: Refactor ResultSet (supports per-cell byte[])
- // so we can VARBINARY safely and remove this early
return.
- return Optional.empty();
- }
- data.add(legacyExpr.getStringValueForQuery(
-
cascadesContext.getStatementContext().getFormatOptions()));
- } else {
+ if (!canComputeLiteralInFe(item, output)) {
return Optional.empty();
}
+ LiteralExpr legacyExpr = ((Literal)
item.child(0)).toLegacyLiteral();
+ columns.add(new Column(output.getName(),
output.getDataType().toCatalogDataType()));
+ data.add(legacyExpr.getStringValueForQuery(
+
cascadesContext.getStatementContext().getFormatOptions()));
}
}
diff --git
a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/physical/PhysicalResultSink.java
b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/physical/PhysicalResultSink.java
index 46df134c0cd..6e26108b9ea 100644
---
a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/physical/PhysicalResultSink.java
+++
b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/physical/PhysicalResultSink.java
@@ -128,6 +128,12 @@ public class PhysicalResultSink<CHILD_TYPE extends Plan>
extends PhysicalSink<CH
null, physicalProperties, statistics, child());
}
+ @Override
+ public boolean canComputeResultInFe(List<Slot> outputSlots) {
+ CHILD_TYPE child = child();
+ return child instanceof ComputeResultSet && ((ComputeResultSet)
child).canComputeResultInFe(outputSlots);
+ }
+
@Override
public Optional<ResultSet> computeResultInFe(
CascadesContext cascadesContext, Optional<SqlCacheContext>
sqlCacheContext, List<Slot> outputSlots) {
diff --git
a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/physical/PhysicalSqlCache.java
b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/physical/PhysicalSqlCache.java
index afba3add8d7..acfcc0520dc 100644
---
a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/physical/PhysicalSqlCache.java
+++
b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/physical/PhysicalSqlCache.java
@@ -167,6 +167,11 @@ public class PhysicalSqlCache extends PhysicalLeaf
return planBody;
}
+ @Override
+ public boolean canComputeResultInFe(List<Slot> outputSlots) {
+ return resultSet.isPresent();
+ }
+
@Override
public Optional<ResultSet> computeResultInFe(
CascadesContext cascadesContext, Optional<SqlCacheContext>
sqlCacheContext, List<Slot> outputSlots) {
diff --git
a/fe/fe-core/src/test/java/org/apache/doris/analysis/TimestampTzQueryOutputTest.java
b/fe/fe-core/src/test/java/org/apache/doris/analysis/TimestampTzQueryOutputTest.java
new file mode 100644
index 00000000000..be545b9d704
--- /dev/null
+++
b/fe/fe-core/src/test/java/org/apache/doris/analysis/TimestampTzQueryOutputTest.java
@@ -0,0 +1,189 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+package org.apache.doris.analysis;
+
+import org.apache.doris.catalog.ArrayType;
+import org.apache.doris.catalog.MapType;
+import org.apache.doris.catalog.ScalarType;
+import org.apache.doris.catalog.Type;
+import org.apache.doris.foundation.format.FormatOptions;
+import org.apache.doris.nereids.exceptions.AnalysisException;
+import org.apache.doris.qe.ConnectContext;
+
+import com.google.common.collect.ImmutableList;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+
+import java.util.Collections;
+
+public class TimestampTzQueryOutputTest {
+ @Test
+ public void testDateLiteralTimeStampTzHistoricalOffsetStreamLoad() throws
Exception {
+ // Query output preserves historical offsets; storage input remains
canonical UTC.
+ ConnectContext context = new ConnectContext();
+ context.setThreadLocalInfo();
+ try {
+ context.getSessionVariable().setTimeZone("Asia/Shanghai");
+ // Pre-standard-offset instant: 1900-01-01 00:00:00 UTC.
+ DateLiteral d = new DateLiteral("1900-01-01 00:00:00+00:00",
+ ScalarType.createTimeStampTzType(0));
+ // Stream-load path must emit UTC format.
+ Assertions.assertEquals("1900-01-01 00:00:00+00:00",
+ d.getStringValueForStreamLoad(FormatOptions.getDefault()));
+ Assertions.assertEquals("1900-01-01 08:05:43+08:05:43",
+ d.getStringValueForQuery(FormatOptions.getDefault()));
+ } finally {
+ ConnectContext.remove();
+ }
+ }
+
+ @Test
+ public void testTimeStampTzQueryRejectsLocalYearOverflow() throws
Exception {
+ ConnectContext context = new ConnectContext();
+ context.setThreadLocalInfo();
+ try {
+ for (int scale : new int[] {0, 3, 6}) {
+ String fraction = scale == 0 ? "" : "." + String.join("",
Collections.nCopies(scale, "9"));
+ for (boolean upper : new boolean[] {false, true}) {
+ String zone = upper ? "+08:00" : "-08:00";
+ context.getSessionVariable().setTimeZone(zone);
+ DateLiteral literal = new DateLiteral(upper
+ ? "9999-12-31 23:59:59" + fraction +
"+00:00"
+ : "0000-01-01 00:00:00+00:00",
+ ScalarType.createTimeStampTzType(scale));
+ for (boolean nested : new boolean[] {false, true}) {
+ FormatOptions options = FormatOptions.getDefault();
+ AnalysisException error =
Assertions.assertThrows(AnalysisException.class,
+ () -> {
+ if (nested) {
+
literal.getStringValueInComplexTypeForQuery(options);
+ } else {
+
literal.getStringValueForQuery(options);
+ }
+ });
+ Assertions.assertTrue(error.getMessage().contains(
+ "TIMESTAMPTZ local year is outside [0, 9999]:
year=" + (upper ? 10000 : -1)));
+ }
+ }
+ }
+ } finally {
+ ConnectContext.remove();
+ }
+ }
+
+ @Test
+ public void testTimeStampTzStreamLoadKeepsUtcBounds() throws Exception {
+ ConnectContext context = new ConnectContext();
+ context.setThreadLocalInfo();
+ try {
+ for (String zone : new String[] {"+08:00", "-08:00"}) {
+ context.getSessionVariable().setTimeZone(zone);
+ for (String text : new String[] {"0000-01-01
00:00:00.000000+00:00",
+ "9999-12-31 23:59:59.999999+00:00"}) {
+ DateLiteral literal = new DateLiteral(text,
ScalarType.createTimeStampTzType(6));
+ Assertions.assertEquals(text,
literal.getStringValueForStreamLoad(FormatOptions.getDefault()));
+ }
+ }
+ } finally {
+ ConnectContext.remove();
+ }
+ }
+
+ @Test
+ public void testTimeStampTzQueryLocalBounds() throws Exception {
+ ConnectContext context = new ConnectContext();
+ context.setThreadLocalInfo();
+ try {
+ context.getSessionVariable().setTimeZone("+08:00");
+ DateLiteral maximum = new DateLiteral("9999-12-31
15:59:59.999999+00:00",
+ ScalarType.createTimeStampTzType(6));
+ Assertions.assertEquals("9999-12-31 23:59:59.999999+08:00",
+
maximum.getStringValueForQuery(FormatOptions.getDefault()));
+ context.getSessionVariable().setTimeZone("-08:00");
+ DateLiteral minimum = new DateLiteral("0000-01-01 08:00:00+00:00",
+ ScalarType.createTimeStampTzType(6));
+ Assertions.assertEquals("0000-01-01 00:00:00.000000-08:00",
+
minimum.getStringValueForQuery(FormatOptions.getDefault()));
+ } finally {
+ ConnectContext.remove();
+ }
+ }
+
+ @Test
+ public void testNullQueryOptionsPreserveDisplayValidation() throws
Exception {
+ ConnectContext context = new ConnectContext();
+ context.setThreadLocalInfo();
+ try {
+ context.getSessionVariable().setTimeZone("Asia/Shanghai");
+ DateLiteral historical = new DateLiteral("1900-01-01
00:00:00+00:00",
+ ScalarType.createTimeStampTzType(0));
+ Assertions.assertEquals("1900-01-01 08:05:43+08:05:43",
historical.getStringValueForQuery(null));
+ for (String[] boundary : new String[][] {
+ {"+08:00", "9999-12-31 23:59:59+00:00"},
+ {"-08:00", "0000-01-01 00:00:00+00:00"}}) {
+ context.getSessionVariable().setTimeZone(boundary[0]);
+ DateLiteral literal = new DateLiteral(boundary[1],
+ ScalarType.createTimeStampTzType(0));
+ Assertions.assertThrows(AnalysisException.class, () ->
literal.getStringValueForQuery(null));
+ }
+ } finally {
+ ConnectContext.remove();
+ }
+ }
+
+ @Test
+ public void testNestedStoragePreservesUtcAndQueryOptions() throws
Exception {
+ ConnectContext context = new ConnectContext();
+ context.setThreadLocalInfo();
+ try {
+ context.getSessionVariable().setTimeZone("+08:00");
+ String text = "9999-12-31 23:59:59.999999+00:00";
+ DateLiteral literal = new DateLiteral(text,
ScalarType.createTimeStampTzType(6));
+ ArrayLiteral array = new ArrayLiteral(new
ArrayType(literal.getType()), literal);
+ for (LiteralExpr container : ImmutableList.of(array,
+ new MapLiteral(new MapType(Type.INT, literal.getType()),
+ ImmutableList.of(new IntLiteral(1)),
ImmutableList.of(literal)),
+ new StructLiteral(literal), new StructLiteral(array))) {
+ FormatOptions options = FormatOptions.getDefault();
+
Assertions.assertTrue(container.getStringValueForStreamLoad(options).contains(text));
+ Assertions.assertThrows(AnalysisException.class, () ->
container.getStringValueForQuery(options));
+ }
+ } finally {
+ ConnectContext.remove();
+ }
+ }
+
+ @Test
+ public void testTimezoneConversionRejectsNegativeYear() throws Exception {
+ ConnectContext context = new ConnectContext();
+ context.setThreadLocalInfo();
+ try {
+ context.getSessionVariable().setTimeZone("-08:00");
+
Assertions.assertThrows(org.apache.doris.common.AnalysisException.class, () ->
new DateLiteral(
+ "0000-01-01 00:00:00+00:00",
ScalarType.createDatetimeV2Type(6)));
+
Assertions.assertThrows(org.apache.doris.common.AnalysisException.class, () ->
new DateLiteral(
+ "0000-01-01 00:00:00+08:00",
ScalarType.createTimeStampTzType(6)));
+ Assertions.assertEquals("0000-01-01 00:00:00.000000", new
DateLiteral(
+ "0000-01-01 08:00:00+00:00",
ScalarType.createDatetimeV2Type(6)).getStringValue());
+ Assertions.assertEquals("0000-01-01 00:00:00.000000+00:00", new
DateLiteral(
+ "0000-01-01 08:00:00+08:00",
ScalarType.createTimeStampTzType(6)).getStringValue());
+ } finally {
+ ConnectContext.remove();
+ }
+ }
+}
diff --git
a/fe/fe-core/src/test/java/org/apache/doris/nereids/NereidsPlannerFeResultTest.java
b/fe/fe-core/src/test/java/org/apache/doris/nereids/NereidsPlannerFeResultTest.java
new file mode 100644
index 00000000000..cf70f6faa58
--- /dev/null
+++
b/fe/fe-core/src/test/java/org/apache/doris/nereids/NereidsPlannerFeResultTest.java
@@ -0,0 +1,96 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+package org.apache.doris.nereids;
+
+import org.apache.doris.analysis.ExplainOptions;
+import org.apache.doris.cloud.qe.ComputeGroupException;
+import org.apache.doris.common.Config;
+import org.apache.doris.mysql.MysqlCommand;
+import org.apache.doris.nereids.exceptions.AnalysisException;
+import org.apache.doris.nereids.glue.LogicalPlanAdapter;
+import org.apache.doris.nereids.parser.NereidsParser;
+import
org.apache.doris.nereids.trees.plans.commands.ExplainCommand.ExplainLevel;
+import org.apache.doris.qe.ConnectContext;
+import org.apache.doris.utframe.TestWithFeService;
+
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+import org.mockito.Mockito;
+
+class NereidsPlannerFeResultTest extends TestWithFeService {
+ @Test
+ void testCloudExplainDoesNotFormatTimestampResults() throws Exception {
+ String originalCloudId = Config.cloud_unique_id;
+ String originalZone =
connectContext.getSessionVariable().getTimeZone();
+ boolean originalFold =
connectContext.getSessionVariable().isEnableFoldConstantByBe();
+ MysqlCommand originalCommand = connectContext.getCommand();
+ ConnectContext originalContext = connectContext;
+ connectContext = Mockito.spy(originalContext);
+ Mockito.doThrow(new ComputeGroupException("No compute group",
+
ComputeGroupException.FailedTypeEnum.SYSTEM_NOT_HAVE_COMPUTE_GROUP))
+ .when(connectContext).getCloudCluster(false);
+ Mockito.doThrow(new AssertionError("A constant FE plan must not
require a compute group"))
+ .when(connectContext).getComputeGroup();
+ connectContext.setThreadLocalInfo();
+ try {
+ Config.cloud_unique_id = "fe_result_planning_test";
+ connectContext.setCommand(MysqlCommand.COM_QUERY);
+
connectContext.getSessionVariable().setEnableFoldConstantByBe(false);
+ for (String[] boundary : new String[][] {
+ {"+08:00", "9999-12-31 23:59:59+00:00"},
+ {"-08:00", "0000-01-01 00:00:00+00:00"}}) {
+ connectContext.getSessionVariable().setTimeZone(boundary[0]);
+ String timestamp = "cast('" + boundary[1] + "' as
timestamptz(0))";
+ for (String value : new String[] {timestamp, "array(" +
timestamp + ", null)"}) {
+ for (ExplainLevel level : new ExplainLevel[] {
+ ExplainLevel.ALL_PLAN,
ExplainLevel.DISTRIBUTED_PLAN}) {
+ String sql = "select " + value;
+ try (StatementContext statementContext =
createStatementCtx(sql)) {
+ NereidsPlanner planner = new
NereidsPlanner(statementContext);
+ LogicalPlanAdapter statement = new
LogicalPlanAdapter(
+ new NereidsParser().parseSingle(sql),
statementContext);
+ ExplainOptions options = new ExplainOptions(level,
false);
+ statement.setIsExplain(options);
+ // EXPLAIN must not serialize a value that only
SELECT needs to display.
+ Assertions.assertDoesNotThrow(() ->
planner.plan(statement), level + ": " + sql);
+
Assertions.assertFalse(planner.getExplainString(options).isEmpty());
+ }
+ }
+ String sql = "select " + value;
+ try (StatementContext statementContext =
createStatementCtx(sql)) {
+ NereidsPlanner planner = new
NereidsPlanner(statementContext);
+ LogicalPlanAdapter statement = new LogicalPlanAdapter(
+ new NereidsParser().parseSingle(sql),
statementContext);
+ planner.plan(statement);
+ AnalysisException error =
Assertions.assertThrows(AnalysisException.class,
+ () -> planner.handleQueryInFe(statement));
+ Assertions.assertTrue(error.getMessage().contains(
+ "TIMESTAMPTZ local year is outside [0,
9999]"));
+ }
+ }
+ }
+ } finally {
+ Config.cloud_unique_id = originalCloudId;
+ connectContext.getSessionVariable().setTimeZone(originalZone);
+
connectContext.getSessionVariable().setEnableFoldConstantByBe(originalFold);
+ connectContext.setCommand(originalCommand);
+ connectContext = originalContext;
+ connectContext.setThreadLocalInfo();
+ }
+ }
+}
diff --git
a/fe/fe-core/src/test/java/org/apache/doris/nereids/trees/plans/ComputeResultSetTest.java
b/fe/fe-core/src/test/java/org/apache/doris/nereids/trees/plans/ComputeResultSetTest.java
new file mode 100644
index 00000000000..631fb110e7f
--- /dev/null
+++
b/fe/fe-core/src/test/java/org/apache/doris/nereids/trees/plans/ComputeResultSetTest.java
@@ -0,0 +1,141 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+package org.apache.doris.nereids.trees.plans;
+
+import org.apache.doris.nereids.CascadesContext;
+import org.apache.doris.nereids.StatementContext;
+import org.apache.doris.nereids.properties.DataTrait;
+import org.apache.doris.nereids.properties.LogicalProperties;
+import org.apache.doris.nereids.trees.expressions.Add;
+import org.apache.doris.nereids.trees.expressions.Alias;
+import org.apache.doris.nereids.trees.expressions.NamedExpression;
+import org.apache.doris.nereids.trees.expressions.literal.IntegerLiteral;
+import org.apache.doris.nereids.trees.expressions.literal.TimestampTzLiteral;
+import org.apache.doris.nereids.trees.expressions.literal.VarBinaryLiteral;
+import org.apache.doris.nereids.trees.plans.physical.PhysicalBlackholeSink;
+import org.apache.doris.nereids.trees.plans.physical.PhysicalEmptyRelation;
+import org.apache.doris.nereids.trees.plans.physical.PhysicalOneRowRelation;
+import org.apache.doris.nereids.trees.plans.physical.PhysicalPlan;
+import org.apache.doris.nereids.trees.plans.physical.PhysicalProject;
+import org.apache.doris.nereids.trees.plans.physical.PhysicalResultSink;
+import org.apache.doris.nereids.trees.plans.physical.PhysicalSqlCache;
+import org.apache.doris.qe.CommonResultSet;
+import org.apache.doris.qe.ConnectContext;
+import org.apache.doris.qe.OriginStatement;
+import org.apache.doris.qe.ResultSet;
+import org.apache.doris.thrift.TUniqueId;
+
+import com.google.common.collect.ImmutableList;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+import org.mockito.Mockito;
+
+import java.util.List;
+import java.util.Optional;
+import java.util.stream.Collectors;
+
+class ComputeResultSetTest {
+ @Test
+ void testLiteralEligibilityDoesNotFormatTimestamps() {
+ PhysicalOneRowRelation relation = oneRow(ImmutableList.of(
+ new Alias(new TimestampTzLiteral(9999, 12, 31, 23, 59, 59),
"ts")));
+
Assertions.assertTrue(relation.canComputeResultInFe(relation.getOutput()));
+ }
+
+ @Test
+ void testOneRowEligibilityPreservesBackendFallbacks() {
+ for (NamedExpression output : ImmutableList.of(new Alias(new
VarBinaryLiteral("FF"), "binary_value"),
+ new Alias(new Add(new IntegerLiteral(1), new
IntegerLiteral(2)), "unfolded"))) {
+ PhysicalOneRowRelation relation = oneRow(ImmutableList.of(output));
+
Assertions.assertFalse(relation.canComputeResultInFe(relation.getOutput()));
+ Assertions.assertFalse(relation.computeResultInFe(null,
Optional.empty(), relation.getOutput()).isPresent());
+ }
+ }
+
+ @Test
+ void testOneRowEligibilityChecksOnlyRequestedOutputs() {
+ NamedExpression selected = new Alias(new IntegerLiteral(1),
"selected");
+ PhysicalOneRowRelation relation = oneRow(ImmutableList.of(selected,
+ new Alias(new VarBinaryLiteral("FF"), "unused_binary"),
+ new Alias(new Add(new IntegerLiteral(1), new
IntegerLiteral(2)), "unused_unfolded")));
+
Assertions.assertFalse(relation.canComputeResultInFe(relation.getOutput()));
+
Assertions.assertTrue(relation.canComputeResultInFe(ImmutableList.of(selected.toSlot())));
+ CascadesContext context = contextWithoutSqlCache();
+ Assertions.assertEquals(ImmutableList.of(ImmutableList.of("1")),
relation.computeResultInFe(
+ context, Optional.empty(),
ImmutableList.of(selected.toSlot())).get().getResultRows());
+ }
+
+ @Test
+ void testSinkEligibilityDelegatesToChild() {
+ for (NamedExpression output : ImmutableList.of(new Alias(new
IntegerLiteral(1), "number_value"),
+ new Alias(new VarBinaryLiteral("FF"), "binary_value"))) {
+ PhysicalOneRowRelation relation = oneRow(ImmutableList.of(output));
+ PhysicalResultSink<PhysicalOneRowRelation> sink = new
PhysicalResultSink<>(
+ relation.getProjects(), Optional.empty(),
relation.getLogicalProperties(), relation);
+ PhysicalBlackholeSink<PhysicalOneRowRelation> blackhole = new
PhysicalBlackholeSink<>(
+ relation.getProjects(), Optional.empty(),
relation.getLogicalProperties(), relation);
+ boolean eligible =
relation.canComputeResultInFe(relation.getOutput());
+ Assertions.assertEquals(eligible,
sink.canComputeResultInFe(relation.getOutput()));
+ Assertions.assertEquals(eligible,
blackhole.canComputeResultInFe(relation.getOutput()));
+ }
+ LogicalProperties properties = properties(ImmutableList.of());
+ PhysicalPlan child = new PhysicalProject<>(ImmutableList.of(),
properties, oneRow(ImmutableList.of()));
+ Assertions.assertFalse(new PhysicalResultSink<>(ImmutableList.of(),
Optional.empty(), properties, child)
+ .canComputeResultInFe(ImmutableList.of()));
+ Assertions.assertFalse(new PhysicalBlackholeSink<>(ImmutableList.of(),
Optional.empty(), properties, child)
+ .canComputeResultInFe(ImmutableList.of()));
+ }
+
+ @Test
+ void testEmptyRelationDoesNotNeedToFormatOutputs() {
+ List<NamedExpression> projects = ImmutableList.of(new Alias(new
VarBinaryLiteral("FF"), "binary_value"));
+ PhysicalEmptyRelation relation = new PhysicalEmptyRelation(new
RelationId(1), projects, properties(projects));
+
Assertions.assertTrue(relation.canComputeResultInFe(relation.getOutput()));
+ Assertions.assertTrue(relation.computeResultInFe(
+ contextWithoutSqlCache(), Optional.empty(),
relation.getOutput()).isPresent());
+ }
+
+ @Test
+ void testSqlCacheEligibilityRequiresFeResult() {
+ ResultSet resultSet = new CommonResultSet(new
CommonResultSet.CommonResultSetMetaData(ImmutableList.of()),
ImmutableList.of());
+ for (Optional<ResultSet> result :
ImmutableList.of(Optional.of(resultSet), Optional.<ResultSet>empty())) {
+ PhysicalSqlCache cache = new PhysicalSqlCache(new TUniqueId(),
ImmutableList.of(), ImmutableList.of(), ImmutableList.of(),
+ result, ImmutableList.of(), "", "");
+ Assertions.assertEquals(result.isPresent(),
cache.canComputeResultInFe(ImmutableList.of()));
+ Assertions.assertEquals(result, cache.computeResultInFe(null,
Optional.empty(), ImmutableList.of()));
+ }
+ }
+
+ private static CascadesContext contextWithoutSqlCache() {
+ ConnectContext connection = new ConnectContext();
+ connection.getSessionVariable().setEnableSqlCache(false);
+ StatementContext statement = new StatementContext(connection, new
OriginStatement("select 1", 0));
+ CascadesContext context = Mockito.mock(CascadesContext.class);
+ Mockito.when(context.getStatementContext()).thenReturn(statement);
+ return context;
+ }
+
+ private static PhysicalOneRowRelation oneRow(List<NamedExpression>
projects) {
+ return new PhysicalOneRowRelation(new RelationId(1), projects,
properties(projects));
+ }
+
+ private static LogicalProperties properties(List<NamedExpression>
projects) {
+ return new LogicalProperties(() ->
projects.stream().map(NamedExpression::toSlot).collect(Collectors.toList()),
+ () -> DataTrait.EMPTY_TRAIT);
+ }
+}
diff --git
a/fe/fe-foundation/src/main/java/org/apache/doris/foundation/format/FormatOptions.java
b/fe/fe-foundation/src/main/java/org/apache/doris/foundation/format/FormatOptions.java
index a77f6c02c8c..513cb1297ef 100644
---
a/fe/fe-foundation/src/main/java/org/apache/doris/foundation/format/FormatOptions.java
+++
b/fe/fe-foundation/src/main/java/org/apache/doris/foundation/format/FormatOptions.java
@@ -37,6 +37,7 @@ public class FormatOptions {
private boolean isBoolValueNum;
// Indicate the nested level of column. It is used to control some
behavior of serde
public int level = 0;
+ private boolean forStreamLoad;
private FormatOptions(String nestedStringWrapper, String mapKeyDelim,
String nullFormat, String collectionDelim,
boolean isBoolValueNum) {
@@ -67,6 +68,19 @@ public class FormatOptions {
return isBoolValueNum;
}
+ public boolean isForStreamLoad() {
+ return forStreamLoad;
+ }
+
+ public FormatOptions forStreamLoad() {
+ // Keep storage formatting local to this call and propagate it through
nested literals.
+ FormatOptions options = new FormatOptions(nestedStringWrapper,
mapKeyDelim, nullFormat,
+ collectionDelim, isBoolValueNum);
+ options.level = level;
+ options.forStreamLoad = true;
+ return options;
+ }
+
public static FormatOptions getDefault() {
return new FormatOptions("\"", ":", "null", ", ", true);
}
diff --git
a/regression-test/data/datatype_p0/timestamptz/test_timestamptz_fe_output_boundary.out
b/regression-test/data/datatype_p0/timestamptz/test_timestamptz_fe_output_boundary.out
new file mode 100644
index 00000000000..f74d9f61a9b
--- /dev/null
+++
b/regression-test/data/datatype_p0/timestamptz/test_timestamptz_fe_output_boundary.out
@@ -0,0 +1,35 @@
+-- This file is automatically generated. You should know what you did if you
want to edit this
+-- !ctas_count --
+2
+
+-- !ctas_utc --
+1 0000-01-01 00:00:00.000000+00:00 9999-12-31 23:59:59.999999+00:00
+2 0000-01-01 00:00:00.000000+00:00 9999-12-31 23:59:59.999999+00:00
+
+-- !masked_null --
+\N
+
+-- !local_upper_edge --
+9999-12-31 23:59:59.999999+08:00
+
+-- !local_lower_edge --
+0000-01-01 00:00:00.000000-08:00
+
+-- !historical_constant --
+1900-01-01 08:05:43.123456+08:05:43
+
+-- !historical_materialized --
+1900-01-01 08:05:43.123456+08:05:43
+
+-- !historical_array --
+["1900-01-01 08:05:43.123456+08:05:43", null]
+
+-- !historical_struct --
+{"ts":"1900-01-01 08:05:43.123456+08:05:43"}
+
+-- !historical_negative_constant --
+1879-12-31 19:03:58.123456-04:56:02
+
+-- !historical_negative_materialized --
+1879-12-31 19:03:58.123456-04:56:02
+
diff --git
a/regression-test/suites/datatype_p0/timestamptz/test_timestamptz_fe_output_boundary.groovy
b/regression-test/suites/datatype_p0/timestamptz/test_timestamptz_fe_output_boundary.groovy
new file mode 100644
index 00000000000..1ddd49b5ff9
--- /dev/null
+++
b/regression-test/suites/datatype_p0/timestamptz/test_timestamptz_fe_output_boundary.groovy
@@ -0,0 +1,135 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+suite("test_timestamptz_fe_output_boundary") {
+ def originalZone = sql("select @@time_zone")[0][0]
+ def originalStrict = sql("select @@enable_strict_cast")[0][0]
+ def originalFold = sql("select @@enable_fold_constant_by_be")[0][0]
+ try {
+ for (def strict : [false, true]) {
+ sql "set enable_strict_cast = ${strict}"
+ for (def fold : [false, true]) {
+ sql "set enable_fold_constant_by_be = ${fold}"
+ for (def scale : [0, 3, 6]) {
+ def fraction = scale == 0 ? "" : "." + "9" * scale
+ for (def entry : [["+08:00", "9999-12-31
23:59:59${fraction}+00:00"],
+ ["-08:00", "0000-01-01
00:00:00+00:00"]]) {
+ sql "set time_zone = '${entry[0]}'"
+ def timestamp = "cast('${entry[1]}' as
timestamptz(${scale}))"
+ for (def value : [timestamp, "array(${timestamp},
null)",
+ "map(1, ${timestamp})",
"named_struct('ts', ${timestamp})"]) {
+ // Constant and materialized values must obey the
same local display range.
+ test {
+ sql "select ${value}"
+ exception "TIMESTAMPTZ local year is outside
[0, 9999]"
+ }
+ test {
+ sql "select ${value} from numbers('number' =
'1')"
+ exception "TIMESTAMPTZ local year is outside
[0, 9999]"
+ }
+ }
+ }
+ }
+ }
+ }
+
+ sql "set enable_fold_constant_by_be = false"
+ for (def entry : [["+08:00", "9999-12-31 23:59:59.999999+00:00"],
+ ["-08:00", "0000-01-01 00:00:00+00:00"]]) {
+ sql "set time_zone = '${entry[0]}'"
+ def timestamp = "cast('${entry[1]}' as timestamptz(6))"
+ for (def value : [timestamp, "array(${timestamp}, null)",
+ "map(1, ${timestamp})", "named_struct('ts',
${timestamp})"]) {
+ // Planning must not apply the local display range checks
required by SELECT.
+ for (def level : ["plan", "all plan"]) {
+ explain {
+ sql "${level} select ${value}"
+ contains "PhysicalOneRowRelation"
+ }
+ }
+ explain {
+ sql "distributed plan select ${value}"
+ contains "UNION"
+ }
+ }
+ }
+
+ sql "set time_zone = '-08:00'"
+ sql "drop table if exists test_timestamptz_negative_default"
+ test {
+ sql """create table test_timestamptz_negative_default (
+ id int, ts timestamptz(6) default '0000-01-01 00:00:00+08:00')
+ distributed by hash(id) buckets 1 properties
("replication_num" = "1")"""
+ exception "Datetime value is out of range"
+ }
+ sql "drop table if exists test_datetime_negative_default"
+ test {
+ sql """create table test_datetime_negative_default (
+ id int, ts datetime(6) default '0000-01-01 00:00:00+00:00')
+ distributed by hash(id) buckets 1 properties
("replication_num" = "1")"""
+ exception "Datetime value is out of range"
+ }
+
+ sql "set time_zone = '+08:00'"
+ sql "drop table if exists test_timestamptz_fe_boundary_ctas"
+ sql """
+ create table test_timestamptz_fe_boundary_ctas
+ properties ("replication_num" = "1") as
+ select 1 as id,
+ cast('0000-01-01 00:00:00+00:00' as timestamptz(6)) as
min_ts,
+ cast('9999-12-31 23:59:59.999999+00:00' as timestamptz(6))
as max_ts
+ """
+ // A valid UTC instant remains writable even when its session-local
display overflows.
+ sql """insert into test_timestamptz_fe_boundary_ctas values
+ (2, '0000-01-01 00:00:00+00:00', '9999-12-31
23:59:59.999999+00:00')"""
+ qt_ctas_count "select count(*) from test_timestamptz_fe_boundary_ctas"
+ test {
+ sql "select max_ts from test_timestamptz_fe_boundary_ctas"
+ exception "TIMESTAMPTZ local year is outside [0, 9999]"
+ }
+ sql "set time_zone = '-08:00'"
+ test {
+ sql "select min_ts from test_timestamptz_fe_boundary_ctas"
+ exception "TIMESTAMPTZ local year is outside [0, 9999]"
+ }
+ sql "set time_zone = 'UTC'"
+ qt_ctas_utc "select * from test_timestamptz_fe_boundary_ctas order by
id"
+
+ sql "set time_zone = '+08:00'"
+ qt_masked_null """select if(false,
+ cast('9999-12-31 23:59:59.999999+00:00' as timestamptz(6)),
null)"""
+ qt_local_upper_edge """select cast('9999-12-31 15:59:59.999999+00:00'
as timestamptz(6))"""
+ sql "set time_zone = '-08:00'"
+ qt_local_lower_edge """select cast('0000-01-01 08:00:00+00:00' as
timestamptz(6))"""
+
+ sql "set time_zone = 'Asia/Shanghai'"
+ qt_historical_constant """select cast('1900-01-01
00:00:00.123456+00:00' as timestamptz(6))"""
+ qt_historical_materialized """select cast('1900-01-01
00:00:00.123456+00:00' as timestamptz(6))
+ from numbers('number' = '1')"""
+ qt_historical_array """select array(cast('1900-01-01
00:00:00.123456+00:00' as timestamptz(6)), null)"""
+ qt_historical_struct """select named_struct('ts',
+ cast('1900-01-01 00:00:00.123456+00:00' as timestamptz(6)))"""
+ sql "set time_zone = 'America/New_York'"
+ qt_historical_negative_constant """select cast('1880-01-01
00:00:00.123456+00:00' as timestamptz(6))"""
+ qt_historical_negative_materialized """select cast('1880-01-01
00:00:00.123456+00:00' as timestamptz(6))
+ from numbers('number' = '1')"""
+ } finally {
+ sql "set time_zone = '${originalZone}'"
+ sql "set enable_strict_cast = ${originalStrict}"
+ sql "set enable_fold_constant_by_be = ${originalFold}"
+ }
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]