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 6bf7b361b41 branch-4.1: [fix](be) Fix TIMESTAMPTZ nullable type
equality #66722 (#66945)
6bf7b361b41 is described below
commit 6bf7b361b41e7e86bea4feff5e918fb0d0cc7fd3
Author: github-actions[bot]
<41898282+github-actions[bot]@users.noreply.github.com>
AuthorDate: Thu Aug 20 09:08:33 2026 +0800
branch-4.1: [fix](be) Fix TIMESTAMPTZ nullable type equality #66722 (#66945)
Cherry-picked from #66722
Co-authored-by: Mryange <[email protected]>
---
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 b386402cb49..80b6bd791a4 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]