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 fadc78c6cf [fix](str_to_date) str_to_date support format without leading zero (#11817) fadc78c6cf is described below commit fadc78c6cf186c1450c6e1390c5b62dd2f0160d3 Author: camby <104178...@qq.com> AuthorDate: Tue Aug 16 18:23:16 2022 +0800 [fix](str_to_date) str_to_date support format without leading zero (#11817) Co-authored-by: cambyzju <zhuxiaol...@baidu.com> --- be/src/runtime/datetime_value.cpp | 4 ++++ be/src/vec/runtime/vdatetime_value.cpp | 9 +++++---- .../sql_functions/datetime_functions/test_date_function.out | 3 +++ .../sql_functions/datetime_functions/test_date_function.groovy | 1 + 4 files changed, 13 insertions(+), 4 deletions(-) diff --git a/be/src/runtime/datetime_value.cpp b/be/src/runtime/datetime_value.cpp index de535a1363..a5880c1889 100644 --- a/be/src/runtime/datetime_value.cpp +++ b/be/src/runtime/datetime_value.cpp @@ -988,6 +988,10 @@ static bool str_to_int64(const char* ptr, const char** endptr, int64_t* ret) { if (ptr >= end) { return false; } + // a valid input should at least contains one digit + if (!isdigit(*ptr)) { + return false; + } // Skip '0' while (ptr < end && *ptr == '0') { ptr++; diff --git a/be/src/vec/runtime/vdatetime_value.cpp b/be/src/vec/runtime/vdatetime_value.cpp index 04dd72b8d4..6bb93c1e6e 100644 --- a/be/src/vec/runtime/vdatetime_value.cpp +++ b/be/src/vec/runtime/vdatetime_value.cpp @@ -1009,6 +1009,10 @@ static bool str_to_int64(const char* ptr, const char** endptr, int64_t* ret) { if (ptr >= end) { return false; } + // a valid input should at least contains one digit + if (!isdigit(*ptr)) { + return false; + } // Skip '0' while (ptr < end && *ptr == '0') { ptr++; @@ -1018,10 +1022,7 @@ static bool str_to_int64(const char* ptr, const char** endptr, int64_t* ret) { n_end = end; } uint64_t value_1 = 0; - while (ptr < n_end) { - if (!isdigit(*ptr)) { - return false; - } + while (ptr < n_end && isdigit(*ptr)) { value_1 *= 10; value_1 += *ptr++ - '0'; } diff --git a/regression-test/data/query/sql_functions/datetime_functions/test_date_function.out b/regression-test/data/query/sql_functions/datetime_functions/test_date_function.out index 902bfc5147..1d6f5de323 100644 --- a/regression-test/data/query/sql_functions/datetime_functions/test_date_function.out +++ b/regression-test/data/query/sql_functions/datetime_functions/test_date_function.out @@ -356,3 +356,6 @@ true -- !sql -- 2022-07-12T20:00:45 +-- !sql -- +2018-04-02T15:03:28 + diff --git a/regression-test/suites/query/sql_functions/datetime_functions/test_date_function.groovy b/regression-test/suites/query/sql_functions/datetime_functions/test_date_function.groovy index b5387f8205..8dc63147f2 100644 --- a/regression-test/suites/query/sql_functions/datetime_functions/test_date_function.groovy +++ b/regression-test/suites/query/sql_functions/datetime_functions/test_date_function.groovy @@ -294,4 +294,5 @@ suite("test_date_function", "query") { qt_sql """ select date_format('2022-08-04', '%X %V %w'); """ qt_sql """ select STR_TO_DATE('Tue Jul 12 20:00:45 CST 2022', '%a %b %e %H:%i:%s %Y'); """ qt_sql """ select STR_TO_DATE('Tue Jul 12 20:00:45 CST 2022', '%a %b %e %T CST %Y'); """ + qt_sql """ select STR_TO_DATE('2018-4-2 15:3:28','%Y-%m-%d %H:%i:%s'); """ } --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org For additional commands, e-mail: commits-h...@doris.apache.org