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 989c6346eda [fix](datetime) fix datetime round on BE (#31205)
989c6346eda is described below
commit 989c6346eda2bba3638d79d76c323e4649c80700
Author: zhiqiang <[email protected]>
AuthorDate: Wed Feb 21 17:45:41 2024 +0800
[fix](datetime) fix datetime round on BE (#31205)
with tmp as (
select CONCAT(
YEAR('2024-02-06 03:37:07.157'), '-',
LPAD(MONTH('2024-02-06 03:37:07.157'), 2, '0'), '-',
LPAD(DAY('2024-02-06 03:37:07.157'), 2, '0'), ' ',
LPAD(HOUR('2024-02-06 03:37:07.157'), 2, '0'), ':',
LPAD(MINUTE('2024-02-06 03:37:07.157'), 2, '0'), ':',
LPAD(SECOND('2024-02-06 03:37:07.157'), 2, '0'), '.',
"123456789" )
AS generated_string)
select generated_string, cast(generated_string as DateTime(6))
from tmp
before (incorrect round)
+-------------------------------+-----------------------------------------+
| generated_string | cast(generated_string as DATETIMEV2(6)) |
+-------------------------------+-----------------------------------------+
| 2024-02-06 03:37:07.123456789 | 2024-02-06 03:37:07.123456 |
+-------------------------------+-----------------------------------------+
after (round up, keep consistent with mysql):
+-------------------------------+-----------------------------------------+
| generated_string | cast(generated_string as DATETIMEV2(6)) |
+-------------------------------+-----------------------------------------+
| 2024-02-06 03:37:07.123456789 | 2024-02-06 03:37:07.123457 |
+-------------------------------+-----------------------------------------+
1 row in set (0.03 sec)
same work with #30744 but implemented on BE
---
be/src/vec/runtime/vdatetime_value.cpp | 4 +-
.../data/datatype_p0/datetimev2/test_round.out | 11 ++++
.../datatype_p0/datetimev2/test_round.groovy | 58 ++++++++++++++++++++++
3 files changed, 71 insertions(+), 2 deletions(-)
diff --git a/be/src/vec/runtime/vdatetime_value.cpp
b/be/src/vec/runtime/vdatetime_value.cpp
index 334779f9390..3f0c9ff9de0 100644
--- a/be/src/vec/runtime/vdatetime_value.cpp
+++ b/be/src/vec/runtime/vdatetime_value.cpp
@@ -2041,8 +2041,8 @@ bool DateV2Value<T>::from_date_str_base(const char*
date_str, int len, int scale
temp_val *= int_exp10(std::max(0L, 6 - ms_part));
if constexpr (is_datetime) {
if (scale >= 0) {
- if (scale == 6 && ms_part > 6) {
- if (ptr < end && isdigit(*ptr) && *ptr >= '5') {
+ if (scale == 6 && ms_part >= 6) {
+ if (ptr <= end && isdigit(*ptr) && *ptr >= '5') {
temp_val += 1;
}
} else {
diff --git a/regression-test/data/datatype_p0/datetimev2/test_round.out
b/regression-test/data/datatype_p0/datetimev2/test_round.out
new file mode 100644
index 00000000000..89ca82457c6
--- /dev/null
+++ b/regression-test/data/datatype_p0/datetimev2/test_round.out
@@ -0,0 +1,11 @@
+-- This file is automatically generated. You should know what you did if you
want to edit this
+-- !cast --
+2024-02-06 03:37:07.123456789 2024-02-06T03:37:07.123457
+
+-- !cast --
+1 2024-02-01 12:13:14.123456 2024-02-01T12:13:14.123456
+2 2024-02-01 12:13:14.1234567 2024-02-01T12:13:14.123457
+3 2024-02-01 12:13:14.12345671 2024-02-01T12:13:14.123457
+4 2024-02-01 12:13:14.1234561 2024-02-01T12:13:14.123456
+5 2024-02-01 12:13:14.12345615 2024-02-01T12:13:14.123456
+
diff --git a/regression-test/suites/datatype_p0/datetimev2/test_round.groovy
b/regression-test/suites/datatype_p0/datetimev2/test_round.groovy
new file mode 100644
index 00000000000..01aee4d7a06
--- /dev/null
+++ b/regression-test/suites/datatype_p0/datetimev2/test_round.groovy
@@ -0,0 +1,58 @@
+// 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_time_round") {
+ qt_cast """
+ with tmp as (
+ select CONCAT(
+ YEAR('2024-02-06 03:37:07.157'), '-',
+ LPAD(MONTH('2024-02-06 03:37:07.157'), 2, '0'), '-',
+ LPAD(DAY('2024-02-06 03:37:07.157'), 2, '0'), ' ',
+ LPAD(HOUR('2024-02-06 03:37:07.157'), 2, '0'), ':',
+ LPAD(MINUTE('2024-02-06 03:37:07.157'), 2, '0'), ':',
+ LPAD(SECOND('2024-02-06 03:37:07.157'), 2, '0'), '.',
"123456789")
+ AS generated_string)
+ select generated_string, cast(generated_string as DateTime(6))
from tmp
+ """
+ sql """
+ DROP TABLE IF EXISTS test_time_round;
+ """
+ sql """
+ CREATE TABLE test_time_round (`rowid` int, str varchar)
+ ENGINE=OLAP
+ UNIQUE KEY(`rowid`)
+ COMMENT "OLAP"
+ DISTRIBUTED BY HASH(`rowid`) BUCKETS 3
+ PROPERTIES (
+ "replication_num" = "1",
+ "colocate_with" = "lineitem_orders",
+ "enable_unique_key_merge_on_write" = "true"
+ );
+ """
+ sql """
+ insert into test_time_round values
+ (1, "2024-02-01 12:13:14.123456"),
+ (2, "2024-02-01 12:13:14.1234567"),
+ (3, "2024-02-01 12:13:14.12345671"),
+ (4, "2024-02-01 12:13:14.1234561"),
+ (5, "2024-02-01 12:13:14.12345615")
+ """
+
+ qt_cast """
+ select *, cast (str as Datetime(6)) from test_time_round order by
rowid;
+ """
+}
\ No newline at end of file
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]