This is an automated email from the ASF dual-hosted git repository.
zhangstar333 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 24b7b95f4d8 [fix](function) fix error result when STR_TO_DATE input
all space (#48872)
24b7b95f4d8 is described below
commit 24b7b95f4d8b50db274649bbdae3bdabc6137b1b
Author: Mryange <[email protected]>
AuthorDate: Tue Mar 11 15:09:00 2025 +0800
[fix](function) fix error result when STR_TO_DATE input all space (#48872)
### What problem does this PR solve?
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 |
+-----------------------------------------+
```
Problem Summary:
### Release note
None
### Check List (For Author)
- Test <!-- At least one of them must be included. -->
- [x] Regression test
- [x] Unit Test
- [ ] Manual test (add detailed scripts or steps below)
- [ ] No need to test or manual test. Explain why:
- [ ] This is a refactor/code format and no logic has been changed.
- [ ] Previous test can cover this change.
- [ ] No code files have been changed.
- [ ] Other reason <!-- Add your reason? -->
- Behavior changed:
- [x] No.
- [ ] Yes. <!-- Explain the behavior change -->
- Does this need documentation?
- [x] No.
- [ ] Yes. <!-- Add document PR link here. eg:
https://github.com/apache/doris-website/pull/1214 -->
### Check List (For Reviewer who merge this PR)
- [ ] Confirm the release note
- [ ] Confirm test cases
- [ ] Confirm document
- [ ] Add branch pick label <!-- Add branch pick label that this PR
should merge into -->
---
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 729 -> 757 bytes
.../suites/correctness/test_str_to_date.groovy | 5 +++
4 files changed, 50 insertions(+), 6 deletions(-)
diff --git a/be/src/vec/runtime/vdatetime_value.cpp
b/be/src/vec/runtime/vdatetime_value.cpp
index 1f2c14360e2..4a9f8081d3b 100644
--- a/be/src/vec/runtime/vdatetime_value.cpp
+++ b/be/src/vec/runtime/vdatetime_value.cpp
@@ -1248,9 +1248,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;
@@ -2277,9 +2274,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 fd0b3a1d2e5..0660345078a 100644
--- a/be/test/vec/runtime/vdatetime_value_test.cpp
+++ b/be/test/vec/runtime/vdatetime_value_test.cpp
@@ -630,4 +630,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 f145ff9e4be..cf5b74fc8cc 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 75234b1f3b3..8829a2a03ca 100644
--- a/regression-test/suites/correctness/test_str_to_date.groovy
+++ b/regression-test/suites/correctness/test_str_to_date.groovy
@@ -77,4 +77,9 @@ suite("test_str_to_date") {
check_fold_consistency "STR_TO_DATE('2019-12-01', null)"
check_fold_consistency "STR_TO_DATE(null, null)"
check_fold_consistency "STR_TO_DATE('无效日期', 'yyyy-MM-dd')"
+
+
+ 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]