This is an automated email from the ASF dual-hosted git repository.
yiguolei 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 3cfdfa526fd [fix](be) Fix TIMESTAMPTZ values in COALESCE (#66689)
3cfdfa526fd is described below
commit 3cfdfa526fd0a08221aaf8a2ffb6102ab91f7c74
Author: Mryange <[email protected]>
AuthorDate: Mon Aug 24 14:16:32 2026 +0800
[fix](be) Fix TIMESTAMPTZ values in COALESCE (#66689)
COALESCE returned incorrect values for mixed NULL and non-NULL
TIMESTAMPTZ columns because its branchless accumulation buffer was
initialized with a non-zero date default. This change zero-initializes
the buffer and adds a regression case.
### 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/exprs/vcondition_expr.cpp | 9 ++--
.../timestamptz/test_timestamptz_coalesce.out | 5 +++
.../timestamptz/test_timestamptz_coalesce.groovy | 51 ++++++++++++++++++++++
3 files changed, 59 insertions(+), 6 deletions(-)
diff --git a/be/src/exprs/vcondition_expr.cpp b/be/src/exprs/vcondition_expr.cpp
index 0f9d8e6a7bd..e56524a8edc 100644
--- a/be/src/exprs/vcondition_expr.cpp
+++ b/be/src/exprs/vcondition_expr.cpp
@@ -551,12 +551,9 @@ void insert_result_data(MutableColumnPtr& result_column,
ColumnPtr& argument_col
const UInt8* __restrict null_map_data, UInt8*
__restrict filled_flag,
const size_t input_rows_count) {
if (result_column->size() == 0 && input_rows_count) {
- result_column->resize(input_rows_count);
- auto* __restrict result_raw_data =
-
assert_cast<ColumnType*>(result_column.get())->get_data().data();
- for (int i = 0; i < input_rows_count; i++) {
- result_raw_data[i] = {};
- }
+ // The branchless accumulation below requires an all-zero buffer. Do
not value-initialize
+ // date-like types here because their default values may have non-zero
packed bits.
+
assert_cast<ColumnType*>(result_column.get())->get_data().resize_fill(input_rows_count);
}
auto* __restrict result_raw_data =
assert_cast<ColumnType*>(result_column.get())->get_data().data();
diff --git
a/regression-test/data/datatype_p0/timestamptz/test_timestamptz_coalesce.out
b/regression-test/data/datatype_p0/timestamptz/test_timestamptz_coalesce.out
new file mode 100644
index 00000000000..935cebcf673
--- /dev/null
+++ b/regression-test/data/datatype_p0/timestamptz/test_timestamptz_coalesce.out
@@ -0,0 +1,5 @@
+-- This file is automatically generated. You should know what you did if you
want to edit this
+-- !coalesce_nullable_timestamptz --
+1 2024-01-01 08:00:00+08:00 2024-01-01 08:00:00+08:00
+2 \N 2024-01-01 08:00:00+08:00
+
diff --git
a/regression-test/suites/datatype_p0/timestamptz/test_timestamptz_coalesce.groovy
b/regression-test/suites/datatype_p0/timestamptz/test_timestamptz_coalesce.groovy
new file mode 100644
index 00000000000..49dfadcad41
--- /dev/null
+++
b/regression-test/suites/datatype_p0/timestamptz/test_timestamptz_coalesce.groovy
@@ -0,0 +1,51 @@
+// 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_coalesce", "datatype_p0") {
+ sql "SET time_zone = 'Asia/Shanghai'"
+ sql "SET enable_strict_cast = false"
+ sql "SET short_circuit_evaluation = false"
+
+ sql "DROP TABLE IF EXISTS timestamptz_coalesce_check"
+ sql """
+ CREATE TABLE timestamptz_coalesce_check (
+ row_id INT,
+ ts_value TIMESTAMPTZ NULL
+ )
+ DUPLICATE KEY(row_id)
+ DISTRIBUTED BY HASH(row_id) BUCKETS 1
+ PROPERTIES("replication_num" = "1")
+ """
+
+ sql """
+ INSERT INTO timestamptz_coalesce_check VALUES
+ (1, '2024-01-01 00:00:00+00:00'),
+ (2, NULL)
+ """
+
+ order_qt_coalesce_nullable_timestamptz """
+ SELECT
+ row_id,
+ ts_value,
+ COALESCE(
+ ts_value,
+ CAST('2024-01-01 00:00:00+00:00' AS TIMESTAMPTZ)
+ ) AS result_value
+ FROM timestamptz_coalesce_check
+ ORDER BY row_id
+ """
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]