This is an automated email from the ASF dual-hosted git repository.
yiguolei 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 f54f79515c7 [Bug](fix) str_to_date "" should be null (#29402)
f54f79515c7 is described below
commit f54f79515c7c9a4468aae019ab0e3e022932c0fb
Author: HappenLee <[email protected]>
AuthorDate: Wed Jan 3 08:25:22 2024 +0800
[Bug](fix) str_to_date "" should be null (#29402)
---
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 801fa37ca0c..764c6a72f44 100644
--- a/be/src/vec/functions/function_timestamp.cpp
+++ b/be/src/vec/functions/function_timestamp.cpp
@@ -228,12 +228,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 f625631ace9..2be57b0ae20 100644
--- a/be/src/vec/runtime/vdatetime_value.cpp
+++ b/be/src/vec/runtime/vdatetime_value.cpp
@@ -2479,6 +2479,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 7ad5b93341c..dc1d05c9d48 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
@@ -266,6 +266,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 902883c5be0..cbef7072b26 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
@@ -330,6 +330,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]