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 4996eafe74 [bugfix](VecDateTimeValue) eat the value of microsecond in 
function from_date_format_str (#13446)
4996eafe74 is described below

commit 4996eafe74132e21d57cba878acfa454b36703b2
Author: xiaojunjie <971308...@qq.com>
AuthorDate: Thu Oct 20 09:02:33 2022 +0800

    [bugfix](VecDateTimeValue) eat the value of microsecond in function 
from_date_format_str (#13446)
    
    * [bugfix](VecDateTimeValue) eat the value of microsecond in function 
from_date_format_str
    
    * add sql based regression test
    
    Co-authored-by: xiaojunjie <xiaojun...@baidu.com>
---
 be/src/vec/runtime/vdatetime_value.cpp              |  6 ++++++
 be/test/vec/runtime/vdatetime_value_test.cpp        | 21 +++++++++++++++++++++
 .../datetime_functions/test_date_function.out       |  3 +++
 .../datetime_functions/test_date_function.groovy    |  1 +
 4 files changed, 31 insertions(+)

diff --git a/be/src/vec/runtime/vdatetime_value.cpp 
b/be/src/vec/runtime/vdatetime_value.cpp
index 1458349e0c..b8622b2a84 100644
--- a/be/src/vec/runtime/vdatetime_value.cpp
+++ b/be/src/vec/runtime/vdatetime_value.cpp
@@ -1275,6 +1275,12 @@ bool VecDateTimeValue::from_date_format_str(const char* 
format, int format_len,
                 break;
                 // Micro second
             case 'f':
+                // _microsecond is removed, but need to eat this val
+                tmp = val + min(6, val_end - val);
+                if (!str_to_int64(val, &tmp, &int_value)) {
+                    return false;
+                }
+                val = tmp;
                 break;
                 // AM/PM
             case 'p':
diff --git a/be/test/vec/runtime/vdatetime_value_test.cpp 
b/be/test/vec/runtime/vdatetime_value_test.cpp
index 312b0ed423..39b91bde77 100644
--- a/be/test/vec/runtime/vdatetime_value_test.cpp
+++ b/be/test/vec/runtime/vdatetime_value_test.cpp
@@ -481,6 +481,27 @@ TEST(VDateTimeValueTest, date_diff_test) {
         EXPECT_TRUE(datetime_diff<TimeUnit::MINUTE>(date_v2_1, date_v2_2) == 
31 * 24 * 60);
         EXPECT_TRUE(datetime_diff<TimeUnit::SECOND>(date_v2_1, date_v2_2) == 
31 * 24 * 60 * 60);
     }
+
+    {
+        VecDateTimeValue date_v2_1;
+        std::string origin_date1 = "2022-05-24 06:00:00";
+        std::string date_format1 = "%Y-%m-%d %H:%i:%s";
+        EXPECT_TRUE(date_v2_1.from_date_format_str(date_format1.data(), 
date_format1.size(),
+                                                   origin_date1.data(), 
origin_date1.size()));
+
+        VecDateTimeValue date_v2_2;
+        std::string origin_date2 = "2022-06-24 06:00:00.123 AM";
+        std::string date_format2 = "%Y-%m-%d %h:%i:%s.%f %p";
+        EXPECT_TRUE(date_v2_2.from_date_format_str(date_format2.data(), 
date_format2.size(),
+                                                   origin_date2.data(), 
origin_date2.size()));
+
+        EXPECT_TRUE(datetime_diff<TimeUnit::DAY>(date_v2_1, date_v2_2) == 31);
+        EXPECT_TRUE(datetime_diff<TimeUnit::YEAR>(date_v2_1, date_v2_2) == 0);
+        EXPECT_TRUE(datetime_diff<TimeUnit::MONTH>(date_v2_1, date_v2_2) == 1);
+        EXPECT_TRUE(datetime_diff<TimeUnit::HOUR>(date_v2_1, date_v2_2) == 31 
* 24);
+        EXPECT_TRUE(datetime_diff<TimeUnit::MINUTE>(date_v2_1, date_v2_2) == 
31 * 24 * 60);
+        EXPECT_TRUE(datetime_diff<TimeUnit::SECOND>(date_v2_1, date_v2_2) == 
31 * 24 * 60 * 60);
+    }
 }
 
 TEST(VDateTimeValueTest, date_v2_to_string_test) {
diff --git 
a/regression-test/data/query_p0/sql_functions/datetime_functions/test_date_function.out
 
b/regression-test/data/query_p0/sql_functions/datetime_functions/test_date_function.out
index c435725dbd..4c8b24b8c7 100644
--- 
a/regression-test/data/query_p0/sql_functions/datetime_functions/test_date_function.out
+++ 
b/regression-test/data/query_p0/sql_functions/datetime_functions/test_date_function.out
@@ -173,6 +173,9 @@ February
 -- !sql --
 2014-12-21T12:34:56
 
+-- !sql --
+2014-12-21T12:34:56
+
 -- !sql --
 2004-10-18
 
diff --git 
a/regression-test/suites/query_p0/sql_functions/datetime_functions/test_date_function.groovy
 
b/regression-test/suites/query_p0/sql_functions/datetime_functions/test_date_function.groovy
index a78120b34a..5250447e45 100644
--- 
a/regression-test/suites/query_p0/sql_functions/datetime_functions/test_date_function.groovy
+++ 
b/regression-test/suites/query_p0/sql_functions/datetime_functions/test_date_function.groovy
@@ -180,6 +180,7 @@ suite("test_date_function") {
     sql """ insert into ${tableName} values ("2014-12-21 12:34:56")  """
     qt_sql """ select str_to_date(test_datetime, '%Y-%m-%d %H:%i:%s') from 
${tableName}; """
     qt_sql """ select str_to_date("2014-12-21 12:34%3A56", '%Y-%m-%d 
%H:%i%%3A%s'); """
+    qt_sql """ select str_to_date("2014-12-21 12:34:56.789 PM", '%Y-%m-%d 
%h:%i:%s.%f %p'); """
     qt_sql """ select str_to_date('200442 Monday', '%X%V %W') """
     sql """ truncate table ${tableName} """
     sql """ insert into ${tableName} values ("2020-09-01")  """


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

Reply via email to