This is an automated email from the ASF dual-hosted git repository.
HappenLee pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/doris.git
The following commit(s) were added to refs/heads/master by this push:
new a21b5f2f49f [fix](be) Fix TIMESTAMPTZ nullable type equality (#66722)
a21b5f2f49f is described below
commit a21b5f2f49f54670fc2db357d39cff8761958fe2
Author: Mryange <[email protected]>
AuthorDate: Wed Aug 19 16:00:50 2026 +0800
[fix](be) Fix TIMESTAMPTZ nullable type equality (#66722)
A TIMESTAMPTZ data type was considered equal to its nullable variant
because the equality check only compared the primitive type and scale.
During constant folding of a STRUCT expression, this caused a type
mismatch when a `STRUCT<TIMESTAMPTZ>` constant was assigned to a
`STRUCT<Nullable(TIMESTAMPTZ)>` expression. The equality check now also
requires the concrete data type to match, preventing the invalid
equivalence while preserving scale-sensitive comparisons. Regression
coverage verifies inserting a constant TIMESTAMPTZ value into a STRUCT
column and reading the normalized UTC value.
### Release note
None
### Check List (For Author)
- Test <!-- At least one of them must be included. -->
- [ ] Regression test
- [ ] Unit Test
- [ ] Manual test (add detailed scripts or steps below)
- [ ] No need to test or manual test. Explain why:
- [ ] This is a refactor/code format and no logic has been changed.
- [ ] Previous test can cover this change.
- [ ] No code files have been changed.
- [ ] Other reason <!-- Add your reason? -->
- Behavior changed:
- [ ] No.
- [ ] Yes. <!-- Explain the behavior change -->
- Does this need documentation?
- [ ] No.
- [ ] Yes. <!-- Add document PR link here. eg:
https://github.com/apache/doris-website/pull/1214 -->
### Check List (For Reviewer who merge this PR)
- [ ] Confirm the release note
- [ ] Confirm test cases
- [ ] Confirm document
- [ ] Add branch pick label <!-- Add branch pick label that this PR
should merge into -->
---
be/src/core/data_type/data_type_timestamptz.h | 4 +-
.../core/data_type/data_type_timestamptz_test.cpp | 20 +++++++++-
.../timestamptz/test_timestamptz_struct_insert.out | 4 ++
.../test_timestamptz_struct_insert.groovy | 45 ++++++++++++++++++++++
4 files changed, 70 insertions(+), 3 deletions(-)
diff --git a/be/src/core/data_type/data_type_timestamptz.h
b/be/src/core/data_type/data_type_timestamptz.h
index bd508489295..89b405e87b5 100644
--- a/be/src/core/data_type/data_type_timestamptz.h
+++ b/be/src/core/data_type/data_type_timestamptz.h
@@ -39,8 +39,8 @@ public:
DataTypeTimeStampTz() = default;
DataTypeTimeStampTz(UInt32 scale) : _scale(scale) {}
bool equals(const IDataType& rhs) const override {
- return rhs.get_primitive_type() == PrimitiveType::TYPE_TIMESTAMPTZ &&
- _scale == rhs.get_scale();
+ return typeid(rhs) == typeid(*this) &&
+ _scale == static_cast<const DataTypeTimeStampTz&>(rhs)._scale;
}
bool equals_ignore_precision(const IDataType& rhs) const override {
return rhs.get_primitive_type() == PrimitiveType::TYPE_TIMESTAMPTZ;
diff --git a/be/test/core/data_type/data_type_timestamptz_test.cpp
b/be/test/core/data_type/data_type_timestamptz_test.cpp
index d2dad93e1f4..6812d2adf56 100644
--- a/be/test/core/data_type/data_type_timestamptz_test.cpp
+++ b/be/test/core/data_type/data_type_timestamptz_test.cpp
@@ -29,7 +29,9 @@
#include "core/block/block.h"
#include "core/data_type/common_data_type_serder_test.h"
#include "core/data_type/common_data_type_test.h"
+#include "core/data_type/data_type_nullable.h"
#include "core/data_type/data_type_string.h"
+#include "core/data_type/data_type_struct.h"
#include "core/data_type/data_type_varbinary.h"
#include "core/data_type_serde/data_type_serde.h"
#include "core/types.h"
@@ -64,6 +66,22 @@ TEST_F(DataTypeTimeStampTzTest, test_normal) {
EXPECT_TRUE(type->equals_ignore_precision(*other_type));
}
+TEST_F(DataTypeTimeStampTzTest, test_equals_respects_nullable) {
+ auto timestamptz_3 = std::make_shared<DataTypeTimeStampTz>(3);
+ auto timestamptz_6 = std::make_shared<DataTypeTimeStampTz>(6);
+ auto nullable_timestamptz_6 = make_nullable(timestamptz_6);
+
+ EXPECT_FALSE(timestamptz_3->equals(*timestamptz_6));
+ EXPECT_FALSE(timestamptz_6->equals(*nullable_timestamptz_6));
+ EXPECT_FALSE(nullable_timestamptz_6->equals(*timestamptz_6));
+
+ auto struct_timestamptz = std::make_shared<DataTypeStruct>(DataTypes
{timestamptz_6});
+ auto struct_nullable_timestamptz =
+ std::make_shared<DataTypeStruct>(DataTypes
{nullable_timestamptz_6});
+ EXPECT_FALSE(struct_timestamptz->equals(*struct_nullable_timestamptz));
+ EXPECT_FALSE(struct_nullable_timestamptz->equals(*struct_timestamptz));
+}
+
TEST_F(DataTypeTimeStampTzTest, test_serder) {
cctz::time_zone time_zone = cctz::fixed_time_zone(std::chrono::hours(8));
TimezoneUtils::load_offsets_to_cache();
@@ -186,4 +204,4 @@ TEST_F(DataTypeTimeStampTzTest, test_sort) {
EXPECT_EQ(result_column->get_element(2), make_timestamptz(2055, 1, 1, 4,
0, 0, 0));
}
-} // namespace doris
\ No newline at end of file
+} // namespace doris
diff --git
a/regression-test/data/datatype_p0/timestamptz/test_timestamptz_struct_insert.out
b/regression-test/data/datatype_p0/timestamptz/test_timestamptz_struct_insert.out
new file mode 100644
index 00000000000..d3733cbe2d3
--- /dev/null
+++
b/regression-test/data/datatype_p0/timestamptz/test_timestamptz_struct_insert.out
@@ -0,0 +1,4 @@
+-- This file is automatically generated. You should know what you did if you
want to edit this
+-- !select --
+1 2024-03-31 00:15:00.000000+00:00
+
diff --git
a/regression-test/suites/datatype_p0/timestamptz/test_timestamptz_struct_insert.groovy
b/regression-test/suites/datatype_p0/timestamptz/test_timestamptz_struct_insert.groovy
new file mode 100644
index 00000000000..2f9f5d27e5d
--- /dev/null
+++
b/regression-test/suites/datatype_p0/timestamptz/test_timestamptz_struct_insert.groovy
@@ -0,0 +1,45 @@
+// 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_struct_insert") {
+ sql "DROP TABLE IF EXISTS test_timestamptz_struct_insert"
+ sql """
+ CREATE TABLE test_timestamptz_struct_insert (
+ id INT,
+ st STRUCT<a:TIMESTAMPTZ(6)>
+ )
+ DUPLICATE KEY(id)
+ DISTRIBUTED BY HASH(id) BUCKETS 1
+ PROPERTIES ("replication_num" = "1")
+ """
+
+ sql "SET enable_nereids_planner = true"
+ sql "SET time_zone = '+00:00'"
+
+ sql """
+ INSERT INTO test_timestamptz_struct_insert
+ VALUES (
+ 1,
+ NAMED_STRUCT(
+ 'a',
+ CAST('2024-03-30 20:45:00 -03:30' AS TIMESTAMPTZ(6))
+ )
+ )
+ """
+
+ order_qt_select "SELECT id, st.a FROM test_timestamptz_struct_insert ORDER
BY id"
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]