This is an automated email from the ASF dual-hosted git repository.

kxiao pushed a commit to branch branch-2.0
in repository https://gitbox.apache.org/repos/asf/doris.git

commit 3f8925d1055712f86febc7bb5fa1bd53e3d0550d
Author: Mryange <[email protected]>
AuthorDate: Mon Aug 7 17:33:24 2023 +0800

    [fix](time) fix error in time_to_sec
---
 .../function_date_or_datetime_computation.h        |  3 +-
 .../data/correctness/test_time_function.out        | 13 +++++++
 .../suites/correctness/test_time_function.groovy   | 42 ++++++++++++++++++++++
 3 files changed, 57 insertions(+), 1 deletion(-)

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 c53eefd36c..3272419d6d 100644
--- a/be/src/vec/functions/function_date_or_datetime_computation.h
+++ b/be/src/vec/functions/function_date_or_datetime_computation.h
@@ -22,6 +22,7 @@
 
 #include <algorithm>
 #include <boost/iterator/iterator_facade.hpp>
+#include <cstdint>
 #include <memory>
 #include <type_traits>
 #include <utility>
@@ -1038,7 +1039,7 @@ struct TimeToSecImpl {
 
         auto& res_data = res_col->get_data();
         for (int i = 0; i < input_rows_count; ++i) {
-            res_data[i] = static_cast<int>(column_data.get_element(i));
+            res_data[i] = static_cast<int64_t>(column_data.get_element(i)) / 
(1000 * 1000);
         }
         block.replace_by_position(result, std::move(res_col));
 
diff --git a/regression-test/data/correctness/test_time_function.out 
b/regression-test/data/correctness/test_time_function.out
new file mode 100644
index 0000000000..dcdc6da37a
--- /dev/null
+++ b/regression-test/data/correctness/test_time_function.out
@@ -0,0 +1,13 @@
+-- This file is automatically generated. You should know what you did if you 
want to edit this
+-- !select1 --
+16:32:18
+
+-- !select2 --
+16:32:18
+
+-- !select3 --
+16:32:18
+
+-- !select4 --
+16:32:18
+
diff --git a/regression-test/suites/correctness/test_time_function.groovy 
b/regression-test/suites/correctness/test_time_function.groovy
new file mode 100644
index 0000000000..77a4f9be8a
--- /dev/null
+++ b/regression-test/suites/correctness/test_time_function.groovy
@@ -0,0 +1,42 @@
+// 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 """
+        set enable_nereids_planner=true,enable_fold_constant_by_be = false
+    """
+    qt_select1 """
+        select sec_to_time(time_to_sec(cast('16:32:18' as time)));
+    """
+    qt_select2 """
+        select sec_to_time(59538);
+    """
+
+    sql """
+        set enable_nereids_planner=false
+    """
+
+    qt_select3 """
+        select sec_to_time(time_to_sec(cast('16:32:18' as time)));
+    """
+    qt_select4 """
+        select sec_to_time(59538);
+    """
+
+
+    
+}
\ No newline at end of file


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to