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 d86361815ec branch-4.1: [fix](function) Consider microseconds in week
floor and ceil #67961 (#68416)
d86361815ec is described below
commit d86361815ecd6c1f9732c75d195abecd02bdd725
Author: github-actions[bot]
<41898282+github-actions[bot]@users.noreply.github.com>
AuthorDate: Thu Sep 24 09:35:34 2026 +0800
branch-4.1: [fix](function) Consider microseconds in week floor and ceil
#67961 (#68416)
Cherry-picked from #67961
Co-authored-by: Mryange <[email protected]>
---
.../function/function_datetime_floor_ceil.cpp | 14 ++++--
.../test_week_floor_ceil_microsecond.out | 8 ++++
.../test_week_floor_ceil_microsecond.groovy | 55 ++++++++++++++++++++++
3 files changed, 72 insertions(+), 5 deletions(-)
diff --git a/be/src/exprs/function/function_datetime_floor_ceil.cpp
b/be/src/exprs/function/function_datetime_floor_ceil.cpp
index 007a4ed0b18..101c552bb07 100644
--- a/be/src/exprs/function/function_datetime_floor_ceil.cpp
+++ b/be/src/exprs/function/function_datetime_floor_ceil.cpp
@@ -705,12 +705,16 @@ struct DateTimeFloorCeilCore {
calc_origin.to_date_int_val() &
MASK_YEAR_MONTH_FOR_DATETIMEV2;
}
if constexpr (Flag::Unit == WEEK) {
+ constexpr int64_t MICROSECONDS_PER_SECOND = 1'000'000;
+ const auto microseconds_since_week_start = [](const auto&
value) {
+ return (value.daynr() % 7 * 24 * 3600 + value.hour() *
3600 +
+ value.minute() * 60 + value.second()) *
+ MICROSECONDS_PER_SECOND +
+ static_cast<int64_t>(value.microsecond());
+ };
diff = calc_arg.daynr() / 7 - calc_origin.daynr() / 7;
- trivial_part_ts_arg = calc_arg.daynr() % 7 * 24 * 3600 +
calc_arg.hour() * 3600 +
- calc_arg.minute() * 60 +
calc_arg.second();
- trivial_part_ts_res = calc_origin.daynr() % 7 * 24 * 3600 +
- calc_origin.hour() * 3600 +
calc_origin.minute() * 60 +
- calc_origin.second();
+ trivial_part_ts_arg = microseconds_since_week_start(calc_arg);
+ trivial_part_ts_res =
microseconds_since_week_start(calc_origin);
}
if constexpr (Flag::Unit == DAY) {
diff = calc_arg.daynr() - calc_origin.daynr();
diff --git
a/regression-test/data/query_p0/sql_functions/datetime_functions/test_week_floor_ceil_microsecond.out
b/regression-test/data/query_p0/sql_functions/datetime_functions/test_week_floor_ceil_microsecond.out
new file mode 100644
index 00000000000..44563fd0536
--- /dev/null
+++
b/regression-test/data/query_p0/sql_functions/datetime_functions/test_week_floor_ceil_microsecond.out
@@ -0,0 +1,8 @@
+-- This file is automatically generated. You should know what you did if you
want to edit this
+-- !literal_boundary --
+2024-01-01T00:00:00.500 2024-01-15T00:00:00.500
+
+-- !column_boundaries --
+1 2024-01-08T00:00:00.400 2024-01-01T00:00:00.500 2024-01-08T00:00:00.500
+2 2024-01-08T00:00:00.500 2024-01-08T00:00:00.500 2024-01-08T00:00:00.500
+3 2024-01-08T00:00:00.600 2024-01-08T00:00:00.500 2024-01-15T00:00:00.500
diff --git
a/regression-test/suites/query_p0/sql_functions/datetime_functions/test_week_floor_ceil_microsecond.groovy
b/regression-test/suites/query_p0/sql_functions/datetime_functions/test_week_floor_ceil_microsecond.groovy
new file mode 100644
index 00000000000..94716e60657
--- /dev/null
+++
b/regression-test/suites/query_p0/sql_functions/datetime_functions/test_week_floor_ceil_microsecond.groovy
@@ -0,0 +1,55 @@
+// 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_week_floor_ceil_microsecond") {
+ sql """DROP TABLE IF EXISTS test_week_floor_ceil_microsecond"""
+ sql """
+ CREATE TABLE test_week_floor_ceil_microsecond (
+ id INT,
+ input_value DATETIME(6),
+ origin_value DATETIME(6)
+ ) DUPLICATE KEY(id)
+ DISTRIBUTED BY HASH(id) BUCKETS 1
+ PROPERTIES("replication_num" = "1")
+ """
+
+ sql """
+ INSERT INTO test_week_floor_ceil_microsecond VALUES
+ (1, '2024-01-08 00:00:00.400000', '2024-01-01 00:00:00.500000'),
+ (2, '2024-01-08 00:00:00.500000', '2024-01-01 00:00:00.500000'),
+ (3, '2024-01-08 00:00:00.600000', '2024-01-01 00:00:00.500000')
+ """
+
+ qt_literal_boundary """
+ SELECT /*+ SET_VAR(debug_skip_fold_constant = true) */
+ week_floor(CAST('2024-01-08 00:00:00.400000' AS DATETIME(6)),
+ 1,
+ CAST('2024-01-01 00:00:00.500000' AS DATETIME(6))),
+ week_ceil(CAST('2024-01-08 00:00:00.600000' AS DATETIME(6)),
+ 1,
+ CAST('2024-01-01 00:00:00.500000' AS DATETIME(6)))
+ """
+
+ order_qt_column_boundaries """
+ SELECT id,
+ input_value,
+ week_floor(input_value, 1, origin_value),
+ week_ceil(input_value, 1, origin_value)
+ FROM test_week_floor_ceil_microsecond
+ ORDER BY id
+ """
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]