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

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


The following commit(s) were added to refs/heads/branch-3.1 by this push:
     new 95eb18e9973 branch-3.1: [fix](function) fix month=0 of 
from_iso8601_date function. #53050 (#53308)
95eb18e9973 is described below

commit 95eb18e99733dc19d8bdee2b8508ae973d12d13c
Author: daidai <[email protected]>
AuthorDate: Fri Jul 18 10:46:04 2025 +0800

    branch-3.1: [fix](function) fix month=0 of from_iso8601_date function. 
#53050 (#53308)
    
    bp #53050
---
 be/src/vec/runtime/vdatetime_value.h               |   7 +-
 be/test/vec/function/function_time_test.cpp        |  73 +++++++++++++++++++++
 .../datetime_functions/test_from_iso8601_date.out  | Bin 2281 -> 2676 bytes
 .../test_from_iso8601_date.groovy                  |  63 ++++++++++++++++++
 4 files changed, 142 insertions(+), 1 deletion(-)

diff --git a/be/src/vec/runtime/vdatetime_value.h 
b/be/src/vec/runtime/vdatetime_value.h
index 12e961f5fa9..11dfb6e796b 100644
--- a/be/src/vec/runtime/vdatetime_value.h
+++ b/be/src/vec/runtime/vdatetime_value.h
@@ -1211,13 +1211,18 @@ public:
             }
             date_v2_value_.year_ = val;
         } else if constexpr (unit == TimeUnit::MONTH) {
-            if (val > MAX_MONTH) [[unlikely]] {
+            DCHECK(date_v2_value_.year_ <= MAX_YEAR);
+            if (val > MAX_MONTH || val == 0) [[unlikely]] {
                 return false;
             }
             date_v2_value_.month_ = val;
         } else if constexpr (unit == TimeUnit::DAY) {
+            DCHECK(date_v2_value_.year_ <= MAX_YEAR);
             DCHECK(date_v2_value_.month_ <= MAX_MONTH);
             DCHECK(date_v2_value_.month_ != 0);
+            if (val == 0) [[unlikely]] {
+                return false;
+            }
             if (val > S_DAYS_IN_MONTH[date_v2_value_.month_] &&
                 !(is_leap(date_v2_value_.year_) && date_v2_value_.month_ == 2 
&& val == 29)) {
                 return false;
diff --git a/be/test/vec/function/function_time_test.cpp 
b/be/test/vec/function/function_time_test.cpp
index 1ea010e4afd..3d71d70c4a7 100644
--- a/be/test/vec/function/function_time_test.cpp
+++ b/be/test/vec/function/function_time_test.cpp
@@ -1892,4 +1892,77 @@ TEST(VTimestampFunctionsTest, next_day_test) {
                                                                             
data_set));
     }
 }
+
+TEST(VTimestampFunctionsTest, from_iso8601_date) {
+    std::string func_name = "from_iso8601_date";
+    InputTypeSet input_types = {TypeIndex::String};
+
+    DataSet data_set = {
+            {{std::string("2020-01-01")}, str_to_date_v2("2020-01-01", 
"%Y-%m-%d")},
+            {{std::string("2020-01-01")}, str_to_date_v2("2020-01-01", 
"%Y-%m-%d")},
+            {{std::string("-1")}, Null()},
+            {{std::string("2025-07-11")}, str_to_date_v2("2025-07-11", 
"%Y-%m-%d")},
+            {{std::string("2024-02-29")}, str_to_date_v2("2024-02-29", 
"%Y-%m-%d")},
+            {{std::string("2025-02-29")}, Null()},
+            {{std::string("2025-13-01")}, Null()},
+            {{std::string("2020-W10")}, str_to_date_v2("2020-03-02", 
"%Y-%m-%d")},
+            {{std::string("2025-W28")}, str_to_date_v2("2025-07-07", 
"%Y-%m-%d")},
+            {{std::string("2025-W53")}, str_to_date_v2("2025-12-29", 
"%Y-%m-%d")},
+            {{std::string("2025-W00")}, Null()},
+            {{std::string("2020-123")}, str_to_date_v2("2020-05-02", 
"%Y-%m-%d")},
+            {{std::string("2025-192")}, str_to_date_v2("2025-07-11", 
"%Y-%m-%d")},
+            {{std::string("2024-366")}, str_to_date_v2("2024-12-31", 
"%Y-%m-%d")},
+            {{std::string("2025-366")}, Null()},
+            {{std::string("2025-000")}, str_to_date_v2("2024-12-31", 
"%Y-%m-%d")},
+            {{std::string("2025/07/11")}, Null()},
+            {{std::string("25-07-11")}, Null()},
+            {{std::string("2025-7-11")}, Null()},
+            {{std::string("invalid-date")}, Null()},
+            {{std::string("2025-07-11T12:34:56")}, Null()},
+            {{std::string("-1")}, Null()},
+            {{std::string("9999-12-31")}, str_to_date_v2("9999-12-31", 
"%Y-%m-%d")},
+            {{std::string("10000-01-01")}, Null()},
+            {{std::string("0001-01-01")}, str_to_date_v2("0001-01-01", 
"%Y-%m-%d")},
+            {{std::string("0000-12-31")}, str_to_date_v2("0000-12-31", 
"%Y-%m-%d")},
+            {{std::string("-0001-01-01")}, Null()},
+            {{std::string("2025-01-01")}, str_to_date_v2("2025-01-01", 
"%Y-%m-%d")},
+            {{std::string("2025-12-31")}, str_to_date_v2("2025-12-31", 
"%Y-%m-%d")},
+            {{std::string("2025-00-01")}, Null()},
+            {{std::string("2025-13-01")}, Null()},
+            {{std::string("2025--01-01")}, Null()},
+            {{std::string("2025-01-31")}, str_to_date_v2("2025-01-31", 
"%Y-%m-%d")},
+            {{std::string("2025-04-30")}, str_to_date_v2("2025-04-30", 
"%Y-%m-%d")},
+            {{std::string("2025-02-28")}, str_to_date_v2("2025-02-28", 
"%Y-%m-%d")},
+            {{std::string("2024-02-29")}, str_to_date_v2("2024-02-29", 
"%Y-%m-%d")},
+            {{std::string("2025-01-32")}, Null()},
+            {{std::string("2025-04-31")}, Null()},
+            {{std::string("2025-02-29")}, Null()},
+            {{std::string("2025-02-30")}, Null()},
+            {{std::string("2025-01-00")}, Null()},
+            {{std::string("2025-01--01")}, Null()},
+            {{std::string("2000-02-29")}, str_to_date_v2("2000-02-29", 
"%Y-%m-%d")},
+            {{std::string("2024-02-29")}, str_to_date_v2("2024-02-29", 
"%Y-%m-%d")},
+            {{std::string("1900-02-29")}, Null()},
+            {{std::string("2100-02-29")}, Null()},
+            {{std::string("2025-02-29")}, Null()},
+            {{std::string("-2025-01-01")}, Null()},
+            {{std::string("2025--07-01")}, Null()},
+            {{std::string("2025-07--01")}, Null()},
+            {{std::string("")}, Null()},
+            {{std::string("2025")}, str_to_date_v2("2025-01-01", "%Y-%m-%d")},
+            {{std::string("2025-07")}, str_to_date_v2("2025-07-01", 
"%Y-%m-%d")},
+            {{std::string("99999-01-01")}, Null()},
+            {{std::string("2025-123-01")}, Null()},
+            {{std::string("2025-01-123")}, Null()},
+            {{std::string("2025/01/01")}, Null()},
+            {{std::string("2025.01.01")}, Null()},
+            {{std::string("2025-01-01X")}, Null()},
+            {{std::string("2025--01--01")}, Null()},
+            {{std::string("abcd-01-01")}, Null()},
+            {{std::string("2025-ab-01")}, Null()},
+            {{std::string("2025-01-ab")}, Null()},
+    };
+
+    static_cast<void>(check_function<DataTypeDateV2, true>(func_name, 
input_types, data_set));
+}
 } // namespace doris::vectorized
diff --git 
a/regression-test/data/query_p0/sql_functions/datetime_functions/test_from_iso8601_date.out
 
b/regression-test/data/query_p0/sql_functions/datetime_functions/test_from_iso8601_date.out
index 43a4f0bd496..93b8bda36e1 100644
Binary files 
a/regression-test/data/query_p0/sql_functions/datetime_functions/test_from_iso8601_date.out
 and 
b/regression-test/data/query_p0/sql_functions/datetime_functions/test_from_iso8601_date.out
 differ
diff --git 
a/regression-test/suites/query_p0/sql_functions/datetime_functions/test_from_iso8601_date.groovy
 
b/regression-test/suites/query_p0/sql_functions/datetime_functions/test_from_iso8601_date.groovy
index 813c0ca49d9..79d508cae87 100644
--- 
a/regression-test/suites/query_p0/sql_functions/datetime_functions/test_from_iso8601_date.groovy
+++ 
b/regression-test/suites/query_p0/sql_functions/datetime_functions/test_from_iso8601_date.groovy
@@ -141,4 +141,67 @@ suite("test_from_iso8601_date") {
     qt_test_87  """ select 
from_iso8601_date(k1),from_iso8601_date(k2),from_iso8601_date(k3),from_iso8601_date(k11),from_iso8601_date(k22),from_iso8601_date(k33)
 from tb2 order by  k0;"""
     qt_test_88 """ select 
from_iso8601_date(nullable(k1)),from_iso8601_date(k2),from_iso8601_date(k3),from_iso8601_date(nullable(k11)),from_iso8601_date(k22),from_iso8601_date(k33)
 from tb2 order by  k0; """ 
     qt_test_89 """ select from_iso8601_date(NULL)   from tb2 order by  k0; """ 
+
+
+    sql """
+    CREATE TABLE tb3 (id INT, date_str VARCHAR(255)) DISTRIBUTED BY HASH(id) 
BUCKETS 4 PROPERTIES ("replication_num" = "1"); """
+    sql  """
+    INSERT INTO tb3 (id, date_str) VALUES 
+    (1, '2023-01-01'),
+    (2, '2023-12-31'),
+    (3, '2020-02-29'),
+    (4, '1970-01-01'),
+    (5, '9999-12-31'),
+    (6, '1000-01-01'),
+    (7, '2023-13-01'),
+    (8, '2023-00-01'),
+    (9, '2023-01-00'),
+    (10, '2023-01-32'),
+    (11, '2023-02-29'),
+    (12, '2023-02-28'),
+    (13, '2024-02-29'),
+    (14, '2024-02-30'),
+    (15, '2023-01-01T12:00:00'),
+    (16, '2023-01-01 12:00:00'),
+    (17, '2023/01/01'),
+    (18, '01-01-2023'),
+    (19, '01/01/2023'),
+    (20, '20230101'),
+    (21, '2023-01-01Z'),
+    (22, '2023-01-01+08:00'),
+    (23, '2023-01-01-08:00'),
+    (24, '2023-W01-1'),
+    (25, '2023-001'),
+    (26, '2023-01-01T12:00:00.000Z'),
+    (27, '2023-01-01T12:00:00.000+08:00'),
+    (28, '2023-01-01T12:00:00.000-08:00'),
+    (29, '2023-01-01T12:00:00.123456Z'),
+    (30, '2023-01-01T12:00:00.123456+08:00'),
+    (31, '2023-01-01T12:00:00.123456-08:00'),
+    (32, '2023-01-01T24:00:00'),
+    (33, '2023-01-01T00:00:00.000000'),
+    (34, '2023-01-01T00:00:00.000001'),
+    (35, '2023-01-01T00:00:00.999999'),
+    (36, '2023-01-01T23:59:59.999999'),
+    (37, '2023-01-01T23:59:60'),
+    (38, '2023-01-01T23:59:59.9999999'),
+    (39, '2023-01-01T23:59:59.999999999'),
+    (40, '2023-01-01T23:59:59.999999999Z'),
+    (41, '2023-01-01T23:59:59.999999999+08:00'),
+    (42, '2023-01-01T23:59:59.999999999-08:00'),
+    (43, '2023-01-01T23:59:59.999999999999'),
+    (44, '2023-01-01T23:59:59.999999999999Z'),
+    (45, '2023-01-01T23:59:59.999999999999+08:00'),
+    (46, '2023-01-01T23:59:59.999999999999-08:00'),
+    (47, '2023-01-01T23:59:59.999999999999999'),
+    (48, '2023-01-01T23:59:59.999999999999999Z'),
+    (49, '2023-01-01T23:59:59.999999999999999+08:00'),
+    (50, '2023-01-01T23:59:59.999999999999999-08:00'); 
+    """
+    qt_test_99 """ SELECT id, from_iso8601_date(date_str) AS result FROM tb3 
order by id; """
+
+
+
+    sql """ drop table tb2 """ 
+
 }
\ No newline at end of file


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

Reply via email to