You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@doris.apache.org by li...@apache.org on 2023/04/25 23:50:01 UTC

[doris] branch master updated: [fix](function) Support more behaviors of cast time in MySQL

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

lihaopeng 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 5fd6d8ebd4 [fix](function) Support more behaviors of cast time in MySQL
5fd6d8ebd4 is described below

commit 5fd6d8ebd457a5eec888fc1d83d94d2441ed3b34
Author: Mryange <59...@users.noreply.github.com>
AuthorDate: Wed Apr 26 07:49:54 2023 +0800

    [fix](function) Support more behaviors of cast time in MySQL
---
 be/src/vec/functions/function_cast.h                        | 6 ++++++
 regression-test/data/correctness/test_cast_as_time.out      | 4 +++-
 regression-test/suites/correctness/test_cast_as_time.groovy | 3 +++
 3 files changed, 12 insertions(+), 1 deletion(-)

diff --git a/be/src/vec/functions/function_cast.h b/be/src/vec/functions/function_cast.h
index 6f79522ab8..3074face87 100644
--- a/be/src/vec/functions/function_cast.h
+++ b/be/src/vec/functions/function_cast.h
@@ -120,6 +120,12 @@ struct TimeCast {
     // '300' -> 00:03:00 '20:23' ->  20:23:00 '20:23:24' -> 20:23:24
     template <typename T>
     static bool try_parse_time(char* s, size_t len, T& x) {
+        /// TODO: Maybe we can move Timecast to the io_helper.
+        if (VecDateTimeValue dv {}; dv.from_date_str(s, len)) {
+            // can be parse as a datetime
+            x = dv.hour() * 3600 + dv.minute() * 60 + dv.second();
+            return true;
+        }
         char* first_char = s;
         char* end_char = s + len;
         int hour = 0, minute = 0, second = 0;
diff --git a/regression-test/data/correctness/test_cast_as_time.out b/regression-test/data/correctness/test_cast_as_time.out
index d216f2e72f..9665ad225f 100644
--- a/regression-test/data/correctness/test_cast_as_time.out
+++ b/regression-test/data/correctness/test_cast_as_time.out
@@ -6,4 +6,6 @@
 -- !select2 --
 19:18:17
 30:20:00
-00:04:00
\ No newline at end of file
+00:04:00
+-- !select3 --
+19:19:19
\ No newline at end of file
diff --git a/regression-test/suites/correctness/test_cast_as_time.groovy b/regression-test/suites/correctness/test_cast_as_time.groovy
index a13af65679..5b6c06b97b 100644
--- a/regression-test/suites/correctness/test_cast_as_time.groovy
+++ b/regression-test/suites/correctness/test_cast_as_time.groovy
@@ -45,4 +45,7 @@ suite("test_cast_as_time") {
     qt_select2 """
         select cast(str as time) from tbl_cast_as_time order by id
     """
+    qt_select3 """
+        select cast('2023-02-21 19:19:19' as time)
+    """    
 }
\ No newline at end of file


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org