Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 0 additions & 6 deletions be/src/vec/runtime/vdatetime_value.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
45 changes: 45 additions & 0 deletions be/test/vec/runtime/vdatetime_value_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
3 changes: 3 additions & 0 deletions regression-test/data/correctness/test_str_to_date.out
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,6 @@
6 \N
7 \N

-- !select_all_space --
\N

5 changes: 5 additions & 0 deletions regression-test/suites/correctness/test_str_to_date.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -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');
"""
}
Loading