This is an automated email from the ASF dual-hosted git repository.
zclllyybb 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 6879d610659 [fix](be) Normalize v1 date string cast result (#64575)
6879d610659 is described below
commit 6879d61065915c51995e6a8de68872eab1e1baca
Author: TengJianPing <[email protected]>
AuthorDate: Wed Jun 17 14:56:42 2026 +0800
[fix](be) Normalize v1 date string cast result (#64575)
Problem Summary: Strict-mode string casts to v1 DATE can return early
after parsing a compact datetime string or an hour-only time part. Those
early returns skipped the common target-type normalization, so DATE
results could keep non-zero time fields such as 2024-05-01 01:00:00
instead of 2024-05-01. Normalize the parsed value before both early
returns so DATE clears the time fields and DATETIME keeps datetime
semantics.
---------
Co-authored-by: github-actions[bot]
<41898282+github-actions[bot]@users.noreply.github.com>
---
be/src/exprs/function/cast/cast_to_date_or_datetime_impl.hpp | 2 ++
be/test/exprs/function/cast/cast_to_date_test.cpp | 12 ++++++++++++
2 files changed, 14 insertions(+)
diff --git a/be/src/exprs/function/cast/cast_to_date_or_datetime_impl.hpp
b/be/src/exprs/function/cast/cast_to_date_or_datetime_impl.hpp
index 1a3c749529a..e5529be9bdb 100644
--- a/be/src/exprs/function/cast/cast_to_date_or_datetime_impl.hpp
+++ b/be/src/exprs/function/cast/cast_to_date_or_datetime_impl.hpp
@@ -434,6 +434,7 @@ inline bool
CastToDateOrDatetime::from_string_strict_mode(const StringRef& str,
has_second = true;
if (ptr == end) {
// no fraction or timezone part, just return.
+ cast_to_type<TargetType>(res);
return true;
}
goto FRAC;
@@ -556,6 +557,7 @@ inline bool
CastToDateOrDatetime::from_string_strict_mode(const StringRef& str,
part[0]);
if (ptr == end) {
// no minute part, just return.
+ cast_to_type<TargetType>(res);
return true;
}
if (*ptr == ':') {
diff --git a/be/test/exprs/function/cast/cast_to_date_test.cpp
b/be/test/exprs/function/cast/cast_to_date_test.cpp
index f0af88ac1fd..d88bc66d74e 100644
--- a/be/test/exprs/function/cast/cast_to_date_test.cpp
+++ b/be/test/exprs/function/cast/cast_to_date_test.cpp
@@ -85,6 +85,18 @@ TEST_F(FunctionCastTest,
string_to_date_valid_case_strict_mode) {
check_function_for_cast_strict_mode<DataTypeDateV2>(input_types, data_set);
}
+TEST_F(FunctionCastTest, string_to_datev1_valid_case_strict_mode) {
+ InputTypeSet input_types = {PrimitiveType::TYPE_VARCHAR};
+ DataSet data_set = {
+ // Compact formats
+ {{std::string("20240501 01")}, std::string("2024-05-01")},
+ {{std::string("20230716 1920Z")}, std::string("2023-07-16")},
+ {{std::string("20240501T0000")}, std::string("2024-05-01")},
+ {{std::string("20120102030405")}, std::string("2012-01-02")},
+ };
+ check_function_for_cast_strict_mode<DataTypeDate>(input_types, data_set);
+}
+
TEST_F(FunctionCastTest, string_to_date_invalid_cases_in_strict_mode) {
InputTypeSet input_types = {PrimitiveType::TYPE_VARCHAR};
DataSet data_set = {
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]