github-actions[bot] commented on code in PR #32065: URL: https://github.com/apache/doris/pull/32065#discussion_r1533279304
########## be/src/vec/functions/function_timestamp.cpp: ########## @@ -201,6 +201,181 @@ i); } } + template <typename ArgDateType, + typename DateValueType = date_cast::TypeToValueTypeV<ArgDateType>, + typename NativeType = date_cast::TypeToColumnV<ArgDateType>> + static void from_format_Y_m_d(FunctionContext* context, const ColumnString::Chars& ldata, + const ColumnString::Offsets& loffsets, const StringRef& rdata, + PaddedPODArray<NativeType>& res, NullMap& null_map, + int* s_days_in_month) { + size_t size = loffsets.size(); + for (size_t i = 0; i < size; ++i) { + const char* l_raw_str = reinterpret_cast<const char*>(&ldata[loffsets[i - 1]]); + size_t l_str_size = loffsets[i] - loffsets[i - 1]; + const char* year_start = l_raw_str; + while (l_str_size && isspace(*year_start)) { // length without space + year_start++; + l_str_size -= 1; + } + const char* year_end = year_start + 4; + const char* month_start = year_end + (*year_end == '-'); + const char* month_end = month_start + 2; + const char* day_start = month_end + (*month_end == '-'); + const char* day_end = day_start + 2; + bool good = true; + if (l_str_size == 8) { + good = true; + for (int index = 0; index < 8 && good; index++) { + if (!isdigit(l_raw_str[index])) good = false; + } + } else + good &= l_str_size >= 10 && *year_end == '-' && *month_end == '-'; + int64_t int_value; + auto [year, month, day, hour, minute, second] = std::tuple {0, 0, 0, 0, 0, 0}; + good &= str_to_int64(year_start, &year_end, &int_value) && int_value <= 9999; + year = int_value; + int_value = 0; + good &= str_to_int64(month_start, &month_end, &int_value) && int_value <= 12 && + int_value != 0; + month = int_value; + int_value = 0; + good &= str_to_int64(day_start, &day_end, &int_value) && + int_value <= s_days_in_month[month] && int_value != 0; + day = int_value; + good |= month == 2 && day == 29 && doris::is_leap(year); + auto& ts_val = *reinterpret_cast<DateValueType*>(&res[i]); + if constexpr (std::is_same_v<DateValueType, VecDateTimeValue>) { + if (!good || !ts_val.check_range_and_set_time(year, month, day, hour, minute, + second, TIME_DATETIME)) { + null_map[i] = 1; + } + } else { + if (!good || !ts_val.check_range_and_set_time(year, month, day, hour, minute, + second, 0, false)) { + null_map[i] = 1; + } + } + } + } + + template <typename ArgDateType, + typename DateValueType = date_cast::TypeToValueTypeV<ArgDateType>, + typename NativeType = date_cast::TypeToColumnV<ArgDateType>> + static void from_format_Y_m_d_H_i_s(FunctionContext* context, const ColumnString::Chars& ldata, + const ColumnString::Offsets& loffsets, + const StringRef& rdata, PaddedPODArray<NativeType>& res, + NullMap& null_map, int s_days_in_month[13]) { Review Comment: warning: pointer parameter 's_days_in_month' can be pointer to const [readability-non-const-parameter] ```suggestion NullMap& null_map, const int s_days_in_month[13]) { ``` ########## be/src/vec/functions/function_timestamp.cpp: ########## @@ -201,6 +201,181 @@ i); } } + template <typename ArgDateType, + typename DateValueType = date_cast::TypeToValueTypeV<ArgDateType>, + typename NativeType = date_cast::TypeToColumnV<ArgDateType>> + static void from_format_Y_m_d(FunctionContext* context, const ColumnString::Chars& ldata, + const ColumnString::Offsets& loffsets, const StringRef& rdata, + PaddedPODArray<NativeType>& res, NullMap& null_map, + int* s_days_in_month) { + size_t size = loffsets.size(); + for (size_t i = 0; i < size; ++i) { + const char* l_raw_str = reinterpret_cast<const char*>(&ldata[loffsets[i - 1]]); + size_t l_str_size = loffsets[i] - loffsets[i - 1]; + const char* year_start = l_raw_str; + while (l_str_size && isspace(*year_start)) { // length without space + year_start++; + l_str_size -= 1; + } + const char* year_end = year_start + 4; + const char* month_start = year_end + (*year_end == '-'); + const char* month_end = month_start + 2; + const char* day_start = month_end + (*month_end == '-'); + const char* day_end = day_start + 2; + bool good = true; + if (l_str_size == 8) { + good = true; + for (int index = 0; index < 8 && good; index++) { + if (!isdigit(l_raw_str[index])) good = false; + } + } else + good &= l_str_size >= 10 && *year_end == '-' && *month_end == '-'; Review Comment: warning: statement should be inside braces [readability-braces-around-statements] ```suggestion } else { good &= l_str_size >= 10 && *year_end == '-' && *month_end == '-'; } ``` ########## be/src/vec/functions/function_timestamp.cpp: ########## @@ -201,6 +201,181 @@ struct StrToDate { i); } } + template <typename ArgDateType, + typename DateValueType = date_cast::TypeToValueTypeV<ArgDateType>, + typename NativeType = date_cast::TypeToColumnV<ArgDateType>> + static void from_format_Y_m_d(FunctionContext* context, const ColumnString::Chars& ldata, + const ColumnString::Offsets& loffsets, const StringRef& rdata, + PaddedPODArray<NativeType>& res, NullMap& null_map, + int* s_days_in_month) { Review Comment: warning: pointer parameter 's_days_in_month' can be pointer to const [readability-non-const-parameter] ```suggestion const int* s_days_in_month) { ``` ########## be/src/vec/functions/function_timestamp.cpp: ########## @@ -201,6 +201,181 @@ i); } } + template <typename ArgDateType, + typename DateValueType = date_cast::TypeToValueTypeV<ArgDateType>, + typename NativeType = date_cast::TypeToColumnV<ArgDateType>> + static void from_format_Y_m_d(FunctionContext* context, const ColumnString::Chars& ldata, + const ColumnString::Offsets& loffsets, const StringRef& rdata, + PaddedPODArray<NativeType>& res, NullMap& null_map, + int* s_days_in_month) { + size_t size = loffsets.size(); + for (size_t i = 0; i < size; ++i) { + const char* l_raw_str = reinterpret_cast<const char*>(&ldata[loffsets[i - 1]]); + size_t l_str_size = loffsets[i] - loffsets[i - 1]; + const char* year_start = l_raw_str; + while (l_str_size && isspace(*year_start)) { // length without space + year_start++; + l_str_size -= 1; + } + const char* year_end = year_start + 4; + const char* month_start = year_end + (*year_end == '-'); + const char* month_end = month_start + 2; + const char* day_start = month_end + (*month_end == '-'); + const char* day_end = day_start + 2; + bool good = true; + if (l_str_size == 8) { + good = true; + for (int index = 0; index < 8 && good; index++) { + if (!isdigit(l_raw_str[index])) good = false; Review Comment: warning: statement should be inside braces [readability-braces-around-statements] ```suggestion if (!isdigit(l_raw_str[index])) { good = false; } ``` -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org For additional commands, e-mail: commits-h...@doris.apache.org