This is an automated email from the ASF dual-hosted git repository.
yiguolei pushed a commit to branch branch-4.0
in repository https://gitbox.apache.org/repos/asf/doris.git
The following commit(s) were added to refs/heads/branch-4.0 by this push:
new f96267492a0 branch-4.0: [fix](time) fix time_to_sec error caused by
gabage value of null value #58410 (#58431)
f96267492a0 is described below
commit f96267492a0dc18425d009f99e03487c5264f78b
Author: github-actions[bot]
<41898282+github-actions[bot]@users.noreply.github.com>
AuthorDate: Thu Nov 27 14:19:03 2025 +0800
branch-4.0: [fix](time) fix time_to_sec error caused by gabage value of
null value #58410 (#58431)
Cherry-picked from #58410
Co-authored-by: TengJianPing <[email protected]>
---
.../function_date_or_datetime_computation.h | 5 +-
.../data/function_p0/time/test_time_function.out | 4 +
.../data/function_p0/time/test_time_to_sec.csv | 17 ++++
.../function_p0/time/test_time_function.groovy | 110 +++++++++++++++++++++
4 files changed, 134 insertions(+), 2 deletions(-)
diff --git a/be/src/vec/functions/function_date_or_datetime_computation.h
b/be/src/vec/functions/function_date_or_datetime_computation.h
index ef4077fad76..2eb8e9f74fc 100644
--- a/be/src/vec/functions/function_date_or_datetime_computation.h
+++ b/be/src/vec/functions/function_date_or_datetime_computation.h
@@ -999,8 +999,9 @@ struct TimeToSecImpl {
auto& res_data = res_col->get_data();
for (int i = 0; i < input_rows_count; ++i) {
- res_data[i] =
cast_set<int>(static_cast<int64_t>(column_data.get_element(i)) /
- (TimeValue::ONE_SECOND_MICROSECONDS));
+ res_data[i] =
+ cast_set<int, int64_t,
false>(static_cast<int64_t>(column_data.get_element(i)) /
+
(TimeValue::ONE_SECOND_MICROSECONDS));
}
block.replace_by_position(result, std::move(res_col));
diff --git a/regression-test/data/function_p0/time/test_time_function.out
b/regression-test/data/function_p0/time/test_time_function.out
new file mode 100644
index 00000000000..c7cdcc8058c
--- /dev/null
+++ b/regression-test/data/function_p0/time/test_time_function.out
@@ -0,0 +1,4 @@
+-- This file is automatically generated. You should know what you did if you
want to edit this
+-- !sql --
+1004
+
diff --git a/regression-test/data/function_p0/time/test_time_to_sec.csv
b/regression-test/data/function_p0/time/test_time_to_sec.csv
new file mode 100644
index 00000000000..088b1b30e37
--- /dev/null
+++ b/regression-test/data/function_p0/time/test_time_to_sec.csv
@@ -0,0 +1,17 @@
+"key00",12.3,8.42,17.86,-11.52,,"FURNITURE","CLAMP ON
LAMPS","one","e",1,-3,5,8,1,1,0,1,"2004-04-15","2004-04-01","1977-04-20","1986-03-20","1899-12-30
21:07:32","19:36:22","2004-07-09 10:17:35",\N,"a"
+"key01",-12.3,6.71,16.73,-9.31,10.85,"FURNITURE","CLOCKS","two","e",,-6,-4,13,0,1,0,,"1972-07-04","2004-04-02","1995-09-03",,"1900-01-01
13:48:48","02:05:25","2004-07-26 12:30:34",\N,"b"
+"key02",15.7,9.78,,-12.17,-13.47,"OFFICE SUPPLIES","AIR
PURIFIERS","three","e",,,5,2,,1,0,,"1975-11-12","2004-04-03","1997-09-19","1997-02-02","1900-01-01
18:21:08","09:33:31","2004-08-02 07:59:23",\N,"c"
+"key03",-15.7,7.43,8.51,-7.25,-6.05,"OFFICE SUPPLIES","BINDER
ACCESSORIES",\N,"e",,-4,-5,5,1,0,0,,"2004-06-04","2004-04-04","1980-07-26",,"1900-01-01
18:51:48","22:50:16","2004-07-05 13:14:20",\N,"d"
+"key04",3.5,9.05,6.46,12.93,8.32,"OFFICE SUPPLIES","BINDER
CLIPS","five",\N,7,,3,9,0,0,1,1,"2004-06-19","2004-04-05","1997-05-30","1996-03-07","1900-01-01
15:01:19",\N,"2004-07-28 23:30:22",\N,"e"
+"key05",-3.5,9.38,8.98,-19.96,10.71,"OFFICE SUPPLIES","BINDING
MACHINES","six",\N,3,,2,7,,0,1,0,,"2004-04-06","1980-11-07","1979-04-01","1900-01-01
08:59:39","19:57:33","2004-07-22 00:30:23",\N,"f"
+"key06",0,16.42,11.69,10.93,,"OFFICE SUPPLIES","BINDING
SUPPLIES",\N,"e",8,,9,18,1,,0,,,"2004-04-07","1977-02-08",,"1900-01-01
07:37:48",\N,"2004-07-28 06:54:50",\N,"g"
+"key07",,11.38,17.25,3.64,-10.24,"OFFICE SUPPLIES","BUSINESS
ENVELOPES","eight","e",,2,0,3,0,,1,0,,"2004-04-08","1974-05-03",,"1900-01-01
19:45:54","19:48:23","2004-07-12 17:30:16",\N,"h"
+"key08",10,9.47,,-13.38,4.77,"TECHNOLOGY","ANSWERING
MACHINES","nine",\N,,3,-6,17,,,0,0,,"2004-04-09","1976-09-09","1983-05-22","1900-01-01
09:00:59","22:20:14","2004-07-04 22:49:28",\N,"i"
+"key09",,12.4,11.5,-10.56,,"TECHNOLOGY","BUSINESS
COPIERS","ten","e",8,3,-9,2,,1,0,,,"2004-04-10","1998-08-12",,"1900-01-01
20:36:00",\N,"2004-07-23 21:13:37",\N,"j"
+"key10",,10.32,6.8,-4.79,19.39,"TECHNOLOGY","CD-R
MEDIA","eleven","e",4,,-3,11,1,1,0,,,"2004-04-11","1974-03-17","1999-08-20","1900-01-01
01:31:32","00:05:57","2004-07-14 08:16:44",\N,"k"
+"key11",,2.47,3.79,-10.81,3.82,"TECHNOLOGY","CONFERENCE
PHONES","twelve",\N,10,-8,-4,2,0,1,1,,,"2004-04-12","1994-04-20",,"1899-12-30
22:15:40","04:40:49","2004-07-25 15:22:26",\N,"l"
+"key12",,12.05,,-6.62,3.38,"TECHNOLOGY","CORDED
KEYBOARDS",\N,\N,,,0,11,,0,1,1,,"2004-04-13","2001-02-04",,"1900-01-01
13:53:46","04:48:07","2004-07-17 14:01:56",\N,"m"
+"key13",,10.37,13.04,-18.43,,"TECHNOLOGY","CORDLESS
KEYBOARDS","fourteen",\N,4,,4,18,,0,1,1,,"2004-04-14","1988-01-05","1996-05-13","1900-01-01
04:57:51",\N,"2004-07-19 22:21:31",\N,"n"
+"key14",,7.1,,6.84,-14.21,"TECHNOLOGY","DOT MATRIX
PRINTERS","fifteen","e",11,,-8,18,1,0,1,,,"2004-04-15","1972-07-12","1986-11-08","1899-12-30
22:42:43","18:58:41","2004-07-31 11:57:52",\N,"o"
+"key15",,16.81,10.98,-10.98,6.75,"TECHNOLOGY","DVD","sixteen","e",4,,-9,11,0,,0,1,,"2004-04-16","1995-06-04",,"1899-12-30
22:24:08",\N,"2004-07-14 07:43:00",\N,"p"
+"key16",,7.12,7.87,-2.6,,"TECHNOLOGY","ERICSSON",\N,\N,8,-9,6,0,,,0,,,"2004-04-17","2002-04-27","1992-01-18","1900-01-01
11:58:29","12:33:57","2004-07-28 12:34:28",\N,"q"
\ No newline at end of file
diff --git a/regression-test/suites/function_p0/time/test_time_function.groovy
b/regression-test/suites/function_p0/time/test_time_function.groovy
new file mode 100644
index 00000000000..672463d2c81
--- /dev/null
+++ b/regression-test/suites/function_p0/time/test_time_function.groovy
@@ -0,0 +1,110 @@
+// 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_function") {
+ sql """
+ drop table if exists test_time_function;
+ """
+ sql """
+ CREATE TABLE test_time_function
+(
+ `key` VARCHAR(255),
+ `num0` DOUBLE ,
+ `num1` DOUBLE ,
+ `num2` DOUBLE ,
+ `num3` DOUBLE ,
+ `num4` DOUBLE ,
+ `str0` VARCHAR(255),
+ `str1` VARCHAR(255),
+ `str2` VARCHAR(255),
+ `str3` VARCHAR(255),
+ `int0` INTEGER,
+ `int1` INTEGER,
+ `int2` INTEGER,
+ `int3` INTEGER,
+ `bool0` BOOLEAN,
+ `bool1` BOOLEAN,
+ `bool2` BOOLEAN,
+ `bool3` BOOLEAN,
+ `date0` DATE,
+ `date1` DATE,
+ `date2` DATE,
+ `date3` DATE,
+ `time0` datetime,
+ `time1` VARCHAR(255),
+ `datetime0` datetime,
+ `datetime1` VARCHAR(255),
+ `zzz` VARCHAR(255)
+) DUPLICATE KEY(`key`) DISTRIBUTED BY HASH(`key`) BUCKETS 1
+ properties("replication_num" = "1");
+ """
+
+ def csvFile = """test_time_to_sec.csv"""
+ streamLoad {
+ table "test_time_function"
+ file """${csvFile}"""
+ set 'column_separator', ','
+ set 'strict_mode', 'false'
+ set 'max_filter_ratio', '1'
+ set 'trim_double_quotes', 'true'
+
+ check { result, exception, startTime, endTime ->
+ if (exception != null) {
+ throw exception
+ }
+ def json = parseJson(result)
+ assertEquals("success", json.Status.toLowerCase())
+ assertEquals(17, json.NumberTotalRows)
+ assertEquals(17, json.NumberLoadedRows)
+ assertEquals(0, json.NumberFilteredRows)
+ }
+ }
+
+
+ qt_sql """
+ SELECT
+ SUM(
+ (
+ (
+ (
+ TO_DAYS(DATE_SUB(`test_time_function`.`date3`, INTERVAL
400 DAY)) - TO_DAYS(`test_time_function`.`date0`)
+ ) + (
+ TIME_TO_SEC(
+ ADDDATE(
+ DATE_SUB(`test_time_function`.`date3`, INTERVAL
400 DAY),
+ INTERVAL 0 SECOND
+ )
+ ) - TIME_TO_SEC(ADDDATE(`test_time_function`.`date0`,
INTERVAL 0 SECOND))
+ ) / (60 * 60 * 24)
+ ) + (
+ (
+ TO_DAYS(DATE_ADD(`test_time_function`.`date3`, INTERVAL
500 DAY)) - TO_DAYS(`test_time_function`.`date2`)
+ ) + (
+ TIME_TO_SEC(
+ ADDDATE(
+ DATE_ADD(`test_time_function`.`date3`, INTERVAL
500 DAY),
+ INTERVAL 0 SECOND
+ )
+ ) - TIME_TO_SEC(ADDDATE(`test_time_function`.`date2`,
INTERVAL 0 SECOND))
+ ) / (60 * 60 * 24)
+ )
+ )
+ ) AS `TEMP(Test)(2422363430)(0)`
+FROM
+ `test_time_function`
+ """
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]