This is an automated email from the ASF dual-hosted git repository.
dataroaring pushed a commit to branch branch-3.0
in repository https://gitbox.apache.org/repos/asf/doris.git
The following commit(s) were added to refs/heads/branch-3.0 by this push:
new 98700203388 [fix](function) fix error result when STR_TO_DATE input
all space (#4… (#48921)
98700203388 is described below
commit 98700203388ea531f65157ecc135d7885f3f8b3f
Author: Mryange <[email protected]>
AuthorDate: Tue Apr 22 10:42:29 2025 +0800
[fix](function) fix error result when STR_TO_DATE input all space (#4…
(#48921)
…8872)
https://github.com/apache/doris/pull/48872
before
```
mysql> select STR_TO_DATE (' ', '%Y-%m-%d %H:%i:%s');
+-----------------------------------------+
| STR_TO_DATE (' ', '%Y-%m-%d %H:%i:%s') |
+-----------------------------------------+
| |
+-----------------------------------------+
```
now
```
mysql> select STR_TO_DATE (' ', '%Y-%m-%d %H:%i:%s');
+-----------------------------------------+
| STR_TO_DATE (' ', '%Y-%m-%d %H:%i:%s') |
+-----------------------------------------+
| NULL |
+-----------------------------------------+
```
---
be/src/vec/runtime/vdatetime_value.cpp | 6 ---
be/test/vec/runtime/vdatetime_value_test.cpp | 45 +++++++++++++++++++++
.../data/correctness/test_str_to_date.out | Bin 443 -> 471 bytes
.../suites/correctness/test_str_to_date.groovy | 4 ++
4 files changed, 49 insertions(+), 6 deletions(-)
diff --git a/be/src/vec/runtime/vdatetime_value.cpp
b/be/src/vec/runtime/vdatetime_value.cpp
index 4f889ce7f1f..5cd2e5f4777 100644
--- a/be/src/vec/runtime/vdatetime_value.cpp
+++ b/be/src/vec/runtime/vdatetime_value.cpp
@@ -1247,9 +1247,6 @@ bool VecDateTimeValue::from_date_format_str(const char*
format, int format_len,
while (val < val_end && check_space(*val)) {
val++;
}
- if (val >= val_end) {
- break;
- }
// Check switch
if (*ptr == '%' && ptr + 1 < end) {
const char* tmp = nullptr;
@@ -2298,9 +2295,6 @@ bool DateV2Value<T>::from_date_format_str(const char*
format, int format_len, co
while (val < val_end && check_space(*val)) {
val++;
}
- if (val >= val_end) {
- break;
- }
// Check switch
if (*ptr == '%' && ptr + 1 < end) {
const char* tmp = nullptr;
diff --git a/be/test/vec/runtime/vdatetime_value_test.cpp
b/be/test/vec/runtime/vdatetime_value_test.cpp
index 6c0bfad6b56..24d25f80ba7 100644
--- a/be/test/vec/runtime/vdatetime_value_test.cpp
+++ b/be/test/vec/runtime/vdatetime_value_test.cpp
@@ -632,4 +632,49 @@ TEST(VDateTimeValueTest, date_v2_daynr_test) {
}
}
+TEST(VDateTimeValueTest, date_v2_from_date_format_str_with_all_space) {
+ auto test_all_space = [](const std::string& format_str) {
+ std::string date_str = " ";
+ {
+ DateV2Value<DateTimeV2ValueType> date;
+ EXPECT_FALSE(date.from_date_format_str(format_str.data(),
format_str.size(),
+ date_str.data(),
date_str.size()));
+ }
+
+ {
+ DateV2Value<DateV2ValueType> date;
+ EXPECT_FALSE(date.from_date_format_str(format_str.data(),
format_str.size(),
+ date_str.data(),
date_str.size()));
+ }
+
+ {
+ VecDateTimeValue date;
+ date._type = TIME_DATE;
+ EXPECT_FALSE(date.from_date_format_str(format_str.data(),
format_str.size(),
+ date_str.data(),
date_str.size()));
+ }
+
+ {
+ VecDateTimeValue date;
+ date._type = TIME_DATETIME;
+ EXPECT_FALSE(date.from_date_format_str(format_str.data(),
format_str.size(),
+ date_str.data(),
date_str.size()));
+ }
+ };
+
+ test_all_space("%Y-%m-%d %H:%i:%s.%f");
+ test_all_space("%Y");
+ test_all_space("%Y-%m-%d");
+ test_all_space("%Y-%m-%d %H:%i:%s");
+ test_all_space("%Y-%m-%d %H:%i:%s.%f %p");
+ for (char ch = 'a'; ch <= 'z'; ch++) {
+ std::string fomat_str = "%" + std::string(1, ch);
+ test_all_space(fomat_str);
+ }
+ for (char ch = 'A'; ch <= 'Z'; ch++) {
+ std::string fomat_str = "%" + std::string(1, ch);
+ test_all_space(fomat_str);
+ }
+}
+
} // namespace doris::vectorized
diff --git a/regression-test/data/correctness/test_str_to_date.out
b/regression-test/data/correctness/test_str_to_date.out
index c4326914a7c..9e896c97c7a 100644
Binary files a/regression-test/data/correctness/test_str_to_date.out and
b/regression-test/data/correctness/test_str_to_date.out differ
diff --git a/regression-test/suites/correctness/test_str_to_date.groovy
b/regression-test/suites/correctness/test_str_to_date.groovy
index c2fe22f1f72..3335bff7a85 100644
--- a/regression-test/suites/correctness/test_str_to_date.groovy
+++ b/regression-test/suites/correctness/test_str_to_date.groovy
@@ -52,4 +52,8 @@ suite("test_str_to_date") {
qt_short_2 " select STR_TO_DATE('2023-12', '%Y-%m') "
qt_short_3 " select STR_TO_DATE('2023-12', '%Y')"
qt_short_4 " select STR_TO_DATE('2020%2', '%Y%%%m')"
+
+ qt_select_all_space """
+ SELECT STR_TO_DATE(' ', '%Y-%m-%d %H:%i:%s');
+ """
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]