This is an automated email from the ASF dual-hosted git repository.
yiguolei pushed a commit to branch branch-2.0
in repository https://gitbox.apache.org/repos/asf/doris.git
The following commit(s) were added to refs/heads/branch-2.0 by this push:
new ae9f70a87bd [Bug](fix) str_to_date "" should be null (#29476)
ae9f70a87bd is described below
commit ae9f70a87bd356ebc62dc9ed60e4bc995c96c9db
Author: HappenLee <[email protected]>
AuthorDate: Wed Jan 3 23:15:47 2024 +0800
[Bug](fix) str_to_date "" should be null (#29476)
---
be/src/vec/functions/function_timestamp.cpp | 13 +++++++------
be/src/vec/runtime/vdatetime_value.cpp | 4 ++++
.../sql_functions/datetime_functions/test_date_function.out | 3 +++
.../datetime_functions/test_date_function.groovy | 1 +
4 files changed, 15 insertions(+), 6 deletions(-)
diff --git a/be/src/vec/functions/function_timestamp.cpp
b/be/src/vec/functions/function_timestamp.cpp
index 9a42569dde4..d698cee3dce 100644
--- a/be/src/vec/functions/function_timestamp.cpp
+++ b/be/src/vec/functions/function_timestamp.cpp
@@ -216,12 +216,13 @@ private:
auto& ts_val = *reinterpret_cast<DateValueType*>(&res[index]);
if (!ts_val.from_date_format_str(r_raw_str, r_str_size, l_raw_str,
l_str_size)) {
null_map[index] = 1;
- }
- if constexpr (std::is_same_v<DateValueType, VecDateTimeValue>) {
- if (context->get_return_type().type ==
doris::PrimitiveType::TYPE_DATETIME) {
- ts_val.to_datetime();
- } else {
- ts_val.cast_to_date();
+ } else {
+ if constexpr (std::is_same_v<DateValueType, VecDateTimeValue>) {
+ if (context->get_return_type().type ==
doris::PrimitiveType::TYPE_DATETIME) {
+ ts_val.to_datetime();
+ } else {
+ ts_val.cast_to_date();
+ }
}
}
}
diff --git a/be/src/vec/runtime/vdatetime_value.cpp
b/be/src/vec/runtime/vdatetime_value.cpp
index d4aa060af30..e7c8d0915d9 100644
--- a/be/src/vec/runtime/vdatetime_value.cpp
+++ b/be/src/vec/runtime/vdatetime_value.cpp
@@ -2477,6 +2477,10 @@ bool DateV2Value<T>::from_date_format_str(const char*
format, int format_len, co
}
}
+ // ptr == format means input value string is "", not do parse format
failed here
+ if (ptr == format) {
+ return false;
+ }
// continue to iterate pattern if has
// to find out if it has time part.
while (ptr < end) {
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 9858f809ea0..40c2dda3ec8 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
@@ -269,6 +269,9 @@ February
-- !sql --
2014-12-21T12:34:56
+-- !sql --
+\N
+
-- !sql --
2014-12-21T12:34:56
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 6647728c0d1..3d34c67a938 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
@@ -329,6 +329,7 @@ suite("test_date_function") {
sql """ truncate table ${tableName} """
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("", "%Y-%m-%d %H:%i:%s"); """
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('2023-07-05T02:09:55.880Z','%Y-%m-%dT%H:%i:%s.%fZ') """
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]