This is an automated email from the ASF dual-hosted git repository.
kxiao 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 79289e32dc [fix](cast) fix wrong result of casting empty string to
array date (#22281)
79289e32dc is described below
commit 79289e32dc0e7e0091301d676209fd0cd822483a
Author: TengJianPing <[email protected]>
AuthorDate: Sun Jul 30 21:15:03 2023 +0800
[fix](cast) fix wrong result of casting empty string to array date (#22281)
---
be/src/vec/data_types/data_type_time_v2.cpp | 12 ------------
be/src/vec/runtime/vdatetime_value.cpp | 6 ++++++
.../cast_function/test_cast_string_to_array.out | 17 ++++++++++++++++-
.../cast_function/test_cast_string_to_array.groovy | 9 +++++++++
4 files changed, 31 insertions(+), 13 deletions(-)
diff --git a/be/src/vec/data_types/data_type_time_v2.cpp
b/be/src/vec/data_types/data_type_time_v2.cpp
index 06275d029c..c4b397f6e7 100644
--- a/be/src/vec/data_types/data_type_time_v2.cpp
+++ b/be/src/vec/data_types/data_type_time_v2.cpp
@@ -67,12 +67,6 @@ void DataTypeDateV2::to_string(const IColumn& column, size_t
row_num, BufferWrit
UInt32 int_val = assert_cast<const
ColumnUInt32&>(*ptr).get_element(row_num);
DateV2Value<DateV2ValueType> val = binary_cast<UInt32,
DateV2Value<DateV2ValueType>>(int_val);
- // if this is an invalid date, write nothing(instead of 0000-00-00) to
output string, or else
- // it will cause problem for null DataTypeDateV2 value in cast function,
- // e.g. cast(cast(null_date as char) as date)
- if (!val.is_valid_date()) {
- return;
- }
char buf[64];
char* pos = val.to_string(buf);
@@ -150,12 +144,6 @@ void DataTypeDateTimeV2::to_string(const IColumn& column,
size_t row_num,
UInt64 int_val = assert_cast<const
ColumnUInt64&>(*ptr).get_element(row_num);
DateV2Value<DateTimeV2ValueType> val =
binary_cast<UInt64, DateV2Value<DateTimeV2ValueType>>(int_val);
- // if this is an invalid date, write nothing(instead of 0000-00-00) to
output string, or else
- // it will cause problem for null DataTypeDateV2 value in cast function,
- // e.g. cast(cast(null_date as char) as date)
- if (!val.is_valid_date()) {
- return;
- }
char buf[64];
char* pos = val.to_string(buf, _scale);
diff --git a/be/src/vec/runtime/vdatetime_value.cpp
b/be/src/vec/runtime/vdatetime_value.cpp
index a8db4d6f66..8aaa51a376 100644
--- a/be/src/vec/runtime/vdatetime_value.cpp
+++ b/be/src/vec/runtime/vdatetime_value.cpp
@@ -2406,6 +2406,12 @@ bool DateV2Value<T>::from_date_format_str(const char*
format, int format_len, co
template <typename T>
int32_t DateV2Value<T>::to_buffer(char* buffer, int scale) const {
+ // if this is an invalid date, write nothing(instead of 0000-00-00) to
output string, or else
+ // it will cause problem for null DataTypeDateV2 value in cast function,
+ // e.g. cast(cast(null_date as char) as date)
+ if (!is_valid_date()) {
+ return 0;
+ }
char* start = buffer;
uint32_t temp;
// Year
diff --git
a/regression-test/data/query_p0/sql_functions/cast_function/test_cast_string_to_array.out
b/regression-test/data/query_p0/sql_functions/cast_function/test_cast_string_to_array.out
index 1c2a470c90..7a6acbd024 100644
---
a/regression-test/data/query_p0/sql_functions/cast_function/test_cast_string_to_array.out
+++
b/regression-test/data/query_p0/sql_functions/cast_function/test_cast_string_to_array.out
@@ -30,5 +30,20 @@
[1.340, 2.010, 0.000, 0.000, 0.000]
-- !sql --
-[2022-09-01, 0000-00-00, 0000-00-00]
+[2022-09-01, , ]
+
+-- !sql --
+["2022-09-01", "", ""]
+
+-- !sql --
+[2022-09-01, NULL, NULL]
+
+-- !sql --
+[2022-09-01, , ]
+
+-- !sql --
+["2022-09-01", "", ""]
+
+-- !sql --
+[2022-09-01, NULL, NULL]
diff --git
a/regression-test/suites/query_p0/sql_functions/cast_function/test_cast_string_to_array.groovy
b/regression-test/suites/query_p0/sql_functions/cast_function/test_cast_string_to_array.groovy
index d9c5ee3546..b246fb5534 100644
---
a/regression-test/suites/query_p0/sql_functions/cast_function/test_cast_string_to_array.groovy
+++
b/regression-test/suites/query_p0/sql_functions/cast_function/test_cast_string_to_array.groovy
@@ -41,5 +41,14 @@ suite("test_cast_string_to_array") {
qt_sql """ select cast ("[1,2,3,,,]" as array<int>) """
qt_sql """ select cast ("[a,b,c,,,]" as array<string>) """
qt_sql """ select cast ("[1.34,2.01,,,]" as array<decimal(10, 3)>) """
+
+ sql """ ADMIN SET FRONTEND CONFIG ("enable_date_conversion" = "false"); """
+ qt_sql """ select cast ("[2022-09-01,,]" as array<date>) """
+ qt_sql """ select cast ("[2022-09-01,,]" as array<string>) """
+ qt_sql """ select cast(cast ("[2022-09-01,,]" as array<string>) as
array<date>) """
+
+ sql """ ADMIN SET FRONTEND CONFIG ("enable_date_conversion" = "true"); """
qt_sql """ select cast ("[2022-09-01,,]" as array<date>) """
+ qt_sql """ select cast ("[2022-09-01,,]" as array<string>) """
+ qt_sql """ select cast(cast ("[2022-09-01,,]" as array<string>) as
array<date>) """
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]