diff --git a/be/src/vec/functions/function_timestamp.cpp b/be/src/vec/functions/function_timestamp.cpp index 7c2e62e5723067f..e212b1af0be4147 100644 --- a/be/src/vec/functions/function_timestamp.cpp +++ b/be/src/vec/functions/function_timestamp.cpp @@ -31,6 +31,7 @@ #include #include +#include "common/cast_set.h" #include "common/status.h" #include "runtime/decimalv2_value.h" #include "runtime/define_primitive_type.h" @@ -70,6 +71,7 @@ #include "vec/utils/util.hpp" namespace doris::vectorized { +#include "common/compile_check_begin.h" template struct StrToDate { @@ -195,9 +197,9 @@ struct StrToDate { const char* r_raw_str = reinterpret_cast(&rdata[roffsets[i - 1]]); size_t r_str_size = roffsets[i] - roffsets[i - 1]; const StringRef format_str = rewrite_specific_format(r_raw_str, r_str_size); - _execute_inner_loop(l_raw_str, l_str_size, format_str.data, - format_str.size, context, res, null_map, - i); + _execute_inner_loop( + l_raw_str, cast_set(l_str_size), format_str.data, + cast_set(format_str.size), context, res, null_map, i); } } template (format_str.size); for (size_t i = 0; i < size; ++i) { const char* l_raw_str = reinterpret_cast(&ldata[loffsets[i - 1]]); - size_t l_str_size = loffsets[i] - loffsets[i - 1]; + auto l_str_size = loffsets[i] - loffsets[i - 1]; - _execute_inner_loop(l_raw_str, l_str_size, format_str.data, - format_str.size, context, res, null_map, - i); + _execute_inner_loop(l_raw_str, cast_set(l_str_size), + format_str.data, format_str_size, + context, res, null_map, i); } } template - static void _execute_inner_loop(const char* l_raw_str, size_t l_str_size, const char* r_raw_str, - size_t r_str_size, FunctionContext* context, + static void _execute_inner_loop(const char* l_raw_str, int l_str_size, const char* r_raw_str, + int r_str_size, FunctionContext* context, PaddedPODArray& res, NullMap& null_map, size_t index) { auto& ts_val = *reinterpret_cast(&res[index]); @@ -373,7 +376,7 @@ struct MakeDateImpl { // l checked outside if constexpr (std::is_same_v) { VecDateTimeValue ts_value = VecDateTimeValue(); - ts_value.unchecked_set_time(l, 1, 1, 0, 0, 0); + ts_value.unchecked_set_time(l, 1U, 1U, 0U, 0U, 0U); TimeInterval interval(DAY, r - 1, false); res_val = ts_value; @@ -383,7 +386,8 @@ struct MakeDateImpl { } res_val.cast_to_date(); } else { - res_val.unchecked_set_time(l, 1, 1, 0, 0, 0, 0); + // caller has checked range of l + res_val.unchecked_set_time(cast_set(l), 1U, 1U, 0U, 0U, 0U, 0U); TimeInterval interval(DAY, r - 1, false); if (!res_val.template date_add_interval(interval)) { null_map[index] = 1; @@ -577,7 +581,7 @@ struct UnixTimeStampImpl { size_t input_rows_count) { auto col_result = ColumnVector::create(); col_result->resize(1); - col_result->get_data()[0] = context->state()->timestamp_ms() / 1000; + col_result->get_data()[0] = static_cast(context->state()->timestamp_ms() / 1000); auto col_const = ColumnConst::create(std::move(col_result), input_rows_count); block.replace_by_position(result, std::move(col_const)); return Status::OK(); @@ -713,7 +717,8 @@ struct UnixTimeStampStrImpl { StringRef fmt = col_format->get_data_at(index_check_const(i, format_const)); DateV2Value ts_value; - if (!ts_value.from_date_format_str(fmt.data, fmt.size, source.data, source.size)) { + if (!ts_value.from_date_format_str(fmt.data, cast_set(fmt.size), source.data, + cast_set(source.size))) { null_map_data[i] = true; continue; } @@ -916,7 +921,7 @@ struct LastDayImpl { null_map[i] = 1; continue; } - int day = get_last_month_day(ts_value.year(), ts_value.month()); + auto day = get_last_month_day(ts_value.year(), ts_value.month()); // day is definitely legal if constexpr (date_cast::IsV1()) { ts_value.unchecked_set_time(ts_value.year(), ts_value.month(), day, 0, 0, 0); @@ -941,7 +946,7 @@ struct LastDayImpl { const auto& cur_data = data_col[i]; auto ts_value = binary_cast(cur_data); DCHECK(ts_value.is_valid_date()); - int day = get_last_month_day(ts_value.year(), ts_value.month()); + auto day = get_last_month_day(ts_value.year(), ts_value.month()); ts_value.template unchecked_set_time_unit(day); if constexpr (std::is_same_v) { @@ -954,7 +959,7 @@ struct LastDayImpl { } } - static int get_last_month_day(int year, int month) { + static uint8 get_last_month_day(int year, int month) { bool is_leap_year = doris::is_leap(year); if (month == 2) { return is_leap_year ? 29 : 28; diff --git a/be/src/vec/functions/function_tokenize.cpp b/be/src/vec/functions/function_tokenize.cpp index be0eb5dddc960d3..5f71787de4c60c5 100644 --- a/be/src/vec/functions/function_tokenize.cpp +++ b/be/src/vec/functions/function_tokenize.cpp @@ -25,6 +25,7 @@ #include "CLucene/StdHeader.h" #include "CLucene/config/repl_wchar.h" +#include "common/cast_set.h" #include "olap/inverted_index_parser.h" #include "olap/rowset/segment_v2/inverted_index/analyzer/analyzer.h" #include "olap/rowset/segment_v2/inverted_index_reader.h" @@ -36,6 +37,7 @@ #include "vec/data_types/data_type_number.h" namespace doris::vectorized { +#include "common/compile_check_begin.h" Status parse(const std::string& str, std::map& result) { boost::regex pattern( @@ -82,7 +84,7 @@ void FunctionTokenize::_do_tokenize(const ColumnString& src_column_string, } auto reader = doris::segment_v2::inverted_index::InvertedIndexAnalyzer::create_reader( inverted_index_ctx.char_filter_map); - reader->init(tokenize_str.data, tokenize_str.size, true); + reader->init(tokenize_str.data, cast_set(tokenize_str.size), true); std::vector query_tokens = doris::segment_v2::inverted_index::InvertedIndexAnalyzer::get_analyse_result( diff --git a/be/src/vec/functions/function_width_bucket.cpp b/be/src/vec/functions/function_width_bucket.cpp index 7f9a3ae31e87653..9ecabc038e9451e 100644 --- a/be/src/vec/functions/function_width_bucket.cpp +++ b/be/src/vec/functions/function_width_bucket.cpp @@ -20,9 +20,11 @@ #include #include +#include #include #include +#include "common/cast_set.h" #include "common/status.h" #include "vec/aggregate_functions/aggregate_function.h" #include "vec/columns/column.h" @@ -44,6 +46,7 @@ class FunctionContext; } // namespace doris namespace doris::vectorized { +#include "common/compile_check_begin.h" class FunctionWidthBucket : public IFunction { public: static constexpr auto name = "width_bucket"; @@ -103,18 +106,21 @@ class FunctionWidthBucket : public IFunction { for (size_t i = 0; i < input_rows_count; ++i) { auto min_value = min_value_column_concrete.get_data()[i]; auto max_value = max_value_column_concrete.get_data()[i]; - auto average_value = (max_value - min_value) / (1.0 * num_buckets); + auto range = max_value - min_value; + using arg_type = decltype(range); + auto average_value = static_cast(range) / static_cast(num_buckets); if (expr_column_concrete.get_data()[i] < min_value) { continue; } else if (expr_column_concrete.get_data()[i] >= max_value) { nested_column_concrete.get_data()[i] = num_buckets + 1; } else { - if ((max_value - min_value) / num_buckets == 0) { + if (range / static_cast(num_buckets) == static_cast(0)) { continue; } nested_column_concrete.get_data()[i] = - (int64_t)(1 + - (expr_column_concrete.get_data()[i] - min_value) / average_value); + (int64_t)(1 + static_cast(expr_column_concrete.get_data()[i] - + min_value) / + average_value); } } } diff --git a/be/src/vec/functions/int_div.h b/be/src/vec/functions/int_div.h index 91952a3db258701..5a8af383d010340 100644 --- a/be/src/vec/functions/int_div.h +++ b/be/src/vec/functions/int_div.h @@ -21,13 +21,13 @@ #pragma once #include -#include #include "vec/columns/column_vector.h" #include "vec/core/types.h" #include "vec/data_types/number_traits.h" namespace doris::vectorized { +#include "common/compile_check_begin.h" template struct DivideIntegralImpl { @@ -38,20 +38,26 @@ struct DivideIntegralImpl { static void apply(const typename Traits::ArrayA& a, B b, typename ColumnVector::Container& c, typename Traits::ArrayNull& null_map) { - size_t size = c.size(); - UInt8 is_null = b == 0; - memset(null_map.data(), is_null, size); + if constexpr (!std::is_integral_v || !std::is_integral_v) { + throw doris::Exception(ErrorCode::RUNTIME_ERROR, + "DivideIntegralImpl only support integral types"); + __builtin_unreachable(); + } else { + size_t size = c.size(); + UInt8 is_null = b == 0; + memset(null_map.data(), is_null, size); - if (!is_null) { - if constexpr (!std::is_floating_point_v && !std::is_same_v && - !std::is_same_v && !std::is_same_v) { - const auto divider = libdivide::divider(A(b)); - for (size_t i = 0; i < size; i++) { - c[i] = a[i] / divider; - } - } else { - for (size_t i = 0; i < size; i++) { - c[i] = Result(a[i] / b); + if (!is_null) { + if constexpr (!std::is_floating_point_v && !std::is_same_v && + !std::is_same_v && !std::is_same_v) { + const auto divider = libdivide::divider(A(b)); + for (size_t i = 0; i < size; i++) { + c[i] = a[i] / divider; + } + } else { + for (size_t i = 0; i < size; i++) { + c[i] = Result(a[i] / b); + } } } } @@ -59,9 +65,16 @@ struct DivideIntegralImpl { template static inline Result apply(A a, B b, UInt8& is_null) { - is_null = b == 0; - return Result(a / (b + is_null)); + if constexpr (!std::is_integral_v || !std::is_integral_v) { + throw doris::Exception(ErrorCode::RUNTIME_ERROR, + "DivideIntegralImpl only support integral types"); + __builtin_unreachable(); + } else { + is_null = b == 0; + return Result(a / (b + is_null)); + } } }; } // namespace doris::vectorized +#include "common/compile_check_end.h" diff --git a/be/src/vec/functions/like.cpp b/be/src/vec/functions/like.cpp index 0207089b666f4a1..5a73986b186fe1f 100644 --- a/be/src/vec/functions/like.cpp +++ b/be/src/vec/functions/like.cpp @@ -26,6 +26,7 @@ #include #include +#include "common/cast_set.h" #include "common/logging.h" #include "vec/columns/column.h" #include "vec/columns/column_const.h" @@ -37,6 +38,7 @@ #include "vec/functions/simple_function_factory.h" namespace doris::vectorized { +#include "common/compile_check_begin.h" // A regex to match any regex pattern is equivalent to a substring search. static const RE2 SUBSTRING_RE(R"((?:\.\*)*([^\.\^\{\[\(\|\)\]\}\+\*\?\$\\]*)(?:\.\*)*)"); @@ -253,7 +255,8 @@ Status FunctionLikeBase::constant_starts_with_fn_scalar(LikeSearchState* state, const StringRef& pattern, unsigned char* result) { *result = (val.size >= state->search_string_sv.size) && - (state->search_string_sv == val.substring(0, state->search_string_sv.size)); + (state->search_string_sv == + val.substring(0, cast_set(state->search_string_sv.size))); return Status::OK(); } @@ -287,8 +290,9 @@ Status FunctionLikeBase::constant_ends_with_fn_scalar(LikeSearchState* state, co const StringRef& pattern, unsigned char* result) { *result = (val.size >= state->search_string_sv.size) && - (state->search_string_sv == val.substring(val.size - state->search_string_sv.size, - state->search_string_sv.size)); + (state->search_string_sv == + val.substring(cast_set(val.size - state->search_string_sv.size), + cast_set(state->search_string_sv.size))); return Status::OK(); } @@ -384,7 +388,8 @@ Status FunctionLikeBase::vector_substring_fn(const ColumnString& vals, Status FunctionLikeBase::constant_regex_fn_scalar(LikeSearchState* state, const StringRef& val, const StringRef& pattern, unsigned char* result) { if (state->hs_database) { // use hyperscan - auto ret = hs_scan(state->hs_database.get(), val.data, val.size, 0, state->hs_scratch.get(), + auto ret = hs_scan(state->hs_database.get(), val.data, cast_set(val.size), 0, + state->hs_scratch.get(), doris::vectorized::LikeSearchState::hs_match_handler, (void*)result); if (ret != HS_SUCCESS && ret != HS_SCAN_TERMINATED) { return Status::RuntimeError(fmt::format("hyperscan error: {}", ret)); @@ -418,8 +423,8 @@ Status FunctionLikeBase::constant_regex_fn(LikeSearchState* state, const ColumnS if (state->hs_database) { // use hyperscan for (size_t i = 0; i < sz; i++) { const auto& str_ref = val.get_data_at(i); - auto ret = hs_scan(state->hs_database.get(), str_ref.data, str_ref.size, 0, - state->hs_scratch.get(), + auto ret = hs_scan(state->hs_database.get(), str_ref.data, + cast_set(str_ref.size), 0, state->hs_scratch.get(), doris::vectorized::LikeSearchState::hs_match_handler, (void*)(result.data() + i)); if (ret != HS_SUCCESS && ret != HS_SCAN_TERMINATED) { @@ -447,8 +452,8 @@ Status FunctionLikeBase::regexp_fn(LikeSearchState* state, const ColumnString& v auto sz = val.size(); for (size_t i = 0; i < sz; i++) { const auto& str_ref = val.get_data_at(i); - auto ret = hs_scan(database, str_ref.data, str_ref.size, 0, scratch, - doris::vectorized::LikeSearchState::hs_match_handler, + auto ret = hs_scan(database, str_ref.data, cast_set(str_ref.size), 0, + scratch, doris::vectorized::LikeSearchState::hs_match_handler, (void*)(result.data() + i)); if (ret != HS_SUCCESS && ret != HS_SCAN_TERMINATED) { return Status::RuntimeError(fmt::format("hyperscan error: {}", ret)); @@ -770,8 +775,8 @@ void FunctionLike::convert_like_pattern(LikeSearchState* state, const std::strin void FunctionLike::remove_escape_character(std::string* search_string) { std::string tmp_search_string; tmp_search_string.swap(*search_string); - int len = tmp_search_string.length(); - for (int i = 0; i < len;) { + auto len = tmp_search_string.length(); + for (std::string::size_type i = 0; i < len;) { if (tmp_search_string[i] == '\\' && i + 1 < len && (tmp_search_string[i + 1] == '%' || tmp_search_string[i + 1] == '_' || tmp_search_string[i + 1] == '\\')) { @@ -791,7 +796,7 @@ bool re2_full_match(const std::string& str, const RE2& re, std::vector arguments; std::vector arguments_ptrs; - std::size_t args_count = re.NumberOfCapturingGroups(); + auto args_count = re.NumberOfCapturingGroups(); arguments.resize(args_count); arguments_ptrs.resize(args_count); results.resize(args_count); diff --git a/be/src/vec/functions/match.cpp b/be/src/vec/functions/match.cpp index 5b74c3b9c188a8c..07cbf9c6dfadb19 100644 --- a/be/src/vec/functions/match.cpp +++ b/be/src/vec/functions/match.cpp @@ -19,12 +19,14 @@ #include +#include "common/cast_set.h" #include "olap/rowset/segment_v2/inverted_index/analyzer/analyzer.h" #include "runtime/query_context.h" #include "runtime/runtime_state.h" #include "util/debug_points.h" namespace doris::vectorized { +#include "common/compile_check_begin.h" Status FunctionMatchBase::evaluate_inverted_index( const ColumnsWithTypeAndName& arguments, const std::vector& data_type_with_names, @@ -178,7 +180,7 @@ std::vector FunctionMatchBase::analyse_query_str_token( } auto reader = doris::segment_v2::inverted_index::InvertedIndexAnalyzer::create_reader( inverted_index_ctx->char_filter_map); - reader->init(match_query_str.data(), match_query_str.size(), true); + reader->init(match_query_str.data(), cast_set(match_query_str.size()), true); query_tokens = doris::segment_v2::inverted_index::InvertedIndexAnalyzer::get_analyse_result( reader.get(), inverted_index_ctx->analyzer, column_name, get_query_type_from_fn_name()); return query_tokens; @@ -186,7 +188,7 @@ std::vector FunctionMatchBase::analyse_query_str_token( inline std::vector FunctionMatchBase::analyse_data_token( const std::string& column_name, InvertedIndexCtx* inverted_index_ctx, - const ColumnString* string_col, int32_t current_block_row_idx, + const ColumnString* string_col, size_t current_block_row_idx, const ColumnArray::Offsets64* array_offsets, int32_t& current_src_array_offset) const { std::vector data_tokens; auto query_type = get_query_type_from_fn_name(); @@ -200,7 +202,7 @@ inline std::vector FunctionMatchBase::analyse_data_token( } auto reader = doris::segment_v2::inverted_index::InvertedIndexAnalyzer::create_reader( inverted_index_ctx->char_filter_map); - reader->init(str_ref.data, str_ref.size, true); + reader->init(str_ref.data, cast_set(str_ref.size), true); std::vector element_tokens = doris::segment_v2::inverted_index::InvertedIndexAnalyzer::get_analyse_result( @@ -215,7 +217,7 @@ inline std::vector FunctionMatchBase::analyse_data_token( } else { auto reader = doris::segment_v2::inverted_index::InvertedIndexAnalyzer::create_reader( inverted_index_ctx->char_filter_map); - reader->init(str_ref.data, str_ref.size, true); + reader->init(str_ref.data, cast_set(str_ref.size), true); data_tokens = doris::segment_v2::inverted_index::InvertedIndexAnalyzer::get_analyse_result( reader.get(), inverted_index_ctx->analyzer, column_name, query_type, @@ -259,7 +261,7 @@ Status FunctionMatchAny::execute_match(FunctionContext* context, const std::stri } auto current_src_array_offset = 0; - for (int i = 0; i < input_rows_count; i++) { + for (size_t i = 0; i < input_rows_count; i++) { std::vector data_tokens = analyse_data_token(column_name, inverted_index_ctx, string_col, i, array_offsets, current_src_array_offset); @@ -297,7 +299,7 @@ Status FunctionMatchAll::execute_match(FunctionContext* context, const std::stri } auto current_src_array_offset = 0; - for (int i = 0; i < input_rows_count; i++) { + for (size_t i = 0; i < input_rows_count; i++) { std::vector data_tokens = analyse_data_token(column_name, inverted_index_ctx, string_col, i, array_offsets, current_src_array_offset); @@ -341,7 +343,7 @@ Status FunctionMatchPhrase::execute_match(FunctionContext* context, const std::s } auto current_src_array_offset = 0; - for (int i = 0; i < input_rows_count; i++) { + for (size_t i = 0; i < input_rows_count; i++) { std::vector data_tokens = analyse_data_token(column_name, inverted_index_ctx, string_col, i, array_offsets, current_src_array_offset); @@ -404,11 +406,10 @@ Status FunctionMatchPhrasePrefix::execute_match( auto data_tokens = analyse_data_token(column_name, inverted_index_ctx, string_col, i, array_offsets, current_src_array_offset); - int32_t dis_count = data_tokens.size() - query_tokens.size(); - if (dis_count < 0) { + if (data_tokens.size() < query_tokens.size()) { continue; } - + auto dis_count = data_tokens.size() - query_tokens.size(); for (size_t j = 0; j < dis_count + 1; j++) { if (data_tokens[j] == query_tokens[0] || query_tokens.size() == 1) { bool match = true; @@ -479,15 +480,15 @@ Status FunctionMatchRegexp::execute_match(FunctionContext* context, const std::s try { auto current_src_array_offset = 0; - for (int i = 0; i < input_rows_count; i++) { + for (size_t i = 0; i < input_rows_count; i++) { std::vector data_tokens = analyse_data_token(column_name, inverted_index_ctx, string_col, i, array_offsets, current_src_array_offset); for (auto& input : data_tokens) { bool is_match = false; - if (hs_scan(database, input.data(), input.size(), 0, scratch, on_match, - (void*)&is_match) != HS_SUCCESS) { + if (hs_scan(database, input.data(), cast_set(input.size()), 0, + scratch, on_match, (void*)&is_match) != HS_SUCCESS) { LOG(ERROR) << "hyperscan match failed: " << input; break; } @@ -530,11 +531,10 @@ Status FunctionMatchPhraseEdge::execute_match( auto data_tokens = analyse_data_token(column_name, inverted_index_ctx, string_col, i, array_offsets, current_src_array_offset); - int32_t dis_count = data_tokens.size() - query_tokens.size(); - if (dis_count < 0) { + if (data_tokens.size() < query_tokens.size()) { continue; } - + auto dis_count = data_tokens.size() - query_tokens.size(); for (size_t j = 0; j < dis_count + 1; j++) { bool match = true; if (query_tokens.size() == 1) { diff --git a/be/src/vec/functions/match.h b/be/src/vec/functions/match.h index 477ab0a34091d32..e55a0db0debd798 100644 --- a/be/src/vec/functions/match.h +++ b/be/src/vec/functions/match.h @@ -87,7 +87,7 @@ class FunctionMatchBase : public IFunction { std::vector analyse_data_token(const std::string& column_name, InvertedIndexCtx* inverted_index_ctx, const ColumnString* string_col, - int32_t current_block_row_idx, + size_t current_block_row_idx, const ColumnArray::Offsets64* array_offsets, int32_t& current_src_array_offset) const; diff --git a/be/src/vec/functions/math.cpp b/be/src/vec/functions/math.cpp index 2d9faaf19bc4925..5aae6065c3f0b44 100644 --- a/be/src/vec/functions/math.cpp +++ b/be/src/vec/functions/math.cpp @@ -25,6 +25,7 @@ #include #include +#include "common/cast_set.h" #include "common/status.h" #include "vec/columns/column.h" #include "vec/columns/column_string.h" @@ -52,6 +53,7 @@ struct Log2Impl; } // namespace doris namespace doris::vectorized { +#include "common/compile_check_begin.h" struct AcosName { static constexpr auto name = "acos"; // https://dev.mysql.com/doc/refman/8.4/en/mathematical-functions.html#function_acos @@ -137,7 +139,7 @@ struct LogImpl { if (!is_null) { for (size_t i = 0; i < size; i++) { - if (a[i] <= 0 || std::fabs(a[i] - 1.0) < EPSILON) { + if (a[i] <= 0 || std::fabs(static_cast(a[i]) - 1.0) < EPSILON) { null_map[i] = 1; } else { c[i] = static_cast(std::log(static_cast(b)) / @@ -149,7 +151,7 @@ struct LogImpl { template static inline Result apply(A a, B b, UInt8& is_null) { - is_null = a <= 0 || b <= 0 || std::fabs(a - 1.0) < EPSILON; + is_null = a <= 0 || b <= 0 || std::fabs(static_cast(a) - 1.0) < EPSILON; return static_cast(std::log(static_cast(b)) / std::log(static_cast(a))); } @@ -275,7 +277,7 @@ struct RadiansImpl { using ResultType = A; static inline ResultType apply(A a) { - return static_cast(a * PiImpl::value / 180.0); + return static_cast(static_cast(a) * PiImpl::value / 180.0); } }; @@ -290,7 +292,7 @@ struct DegreesImpl { using ResultType = A; static inline ResultType apply(A a) { - return static_cast(a * 180.0 / PiImpl::value); + return static_cast(static_cast(a) * 180.0 / PiImpl::value); } }; diff --git a/be/src/vec/functions/minus.cpp b/be/src/vec/functions/minus.cpp index 122842b2d9d7f64..b3980ce103f71ff 100644 --- a/be/src/vec/functions/minus.cpp +++ b/be/src/vec/functions/minus.cpp @@ -27,6 +27,7 @@ #include "vec/functions/simple_function_factory.h" namespace doris::vectorized { +#include "common/compile_check_begin.h" template struct MinusImpl { @@ -35,7 +36,7 @@ struct MinusImpl { template static inline Result apply(A a, B b) { - return static_cast(a) - b; + return static_cast(a) - static_cast(b); } template diff --git a/be/src/vec/functions/modulo.cpp b/be/src/vec/functions/modulo.cpp index 7a2dfc004efc7d6..312a84db2bcd64b 100644 --- a/be/src/vec/functions/modulo.cpp +++ b/be/src/vec/functions/modulo.cpp @@ -32,6 +32,7 @@ #include "vec/functions/simple_function_factory.h" namespace doris::vectorized { +#include "common/compile_check_begin.h" template inline void throw_if_division_leads_to_FPE(A a, B b) { @@ -63,7 +64,7 @@ struct ModuloImpl { if (!is_null) { for (size_t i = 0; i < size; i++) { if constexpr (std::is_floating_point_v) { - c[i] = std::fmod((double)a[i], (double)b); + c[i] = static_cast(std::fmod((double)a[i], (double)b)); } else { throw_if_division_leads_to_FPE(a[i], b); c[i] = a[i] % b; @@ -78,7 +79,7 @@ struct ModuloImpl { b += is_null; if constexpr (std::is_floating_point_v) { - return std::fmod((double)a, (double)b); + return static_cast(std::fmod(a, b)); } else { throw_if_division_leads_to_FPE(a, b); return a % b; @@ -108,10 +109,11 @@ struct PModuloImpl { if (!is_null) { for (size_t i = 0; i < size; i++) { if constexpr (std::is_floating_point_v) { - c[i] = std::fmod(std::fmod((double)a[i], (double)b) + (double)b, double(b)); + c[i] = static_cast( + std::fmod(std::fmod((double)a[i], (double)b) + (double)b, double(b))); } else { throw_if_division_leads_to_FPE(a[i], b); - c[i] = (a[i] % b + b) % b; + c[i] = static_cast((a[i] % b + b) % b); } } } @@ -123,10 +125,11 @@ struct PModuloImpl { b += is_null; if constexpr (std::is_floating_point_v) { - return std::fmod(std::fmod((double)a, (double)b) + (double)b, (double)b); + return static_cast( + std::fmod(std::fmod((double)a, (double)b) + (double)b, (double)b)); } else { throw_if_division_leads_to_FPE(a, b); - return (a % b + b) % b; + return static_cast((a % b + b) % b); } } diff --git a/be/src/vec/functions/multiply.cpp b/be/src/vec/functions/multiply.cpp index f871a3a742cb6c8..536a0f2709eb96f 100644 --- a/be/src/vec/functions/multiply.cpp +++ b/be/src/vec/functions/multiply.cpp @@ -32,6 +32,7 @@ #include "vec/functions/simple_function_factory.h" namespace doris::vectorized { +#include "common/compile_check_begin.h" template struct MultiplyImpl { @@ -40,7 +41,7 @@ struct MultiplyImpl { template static inline Result apply(A a, B b) { - return static_cast(a) * b; + return static_cast(a) * static_cast(b); } template diff --git a/be/src/vec/functions/plus.cpp b/be/src/vec/functions/plus.cpp index 480db82a58100ae..304da60b5f44b5a 100644 --- a/be/src/vec/functions/plus.cpp +++ b/be/src/vec/functions/plus.cpp @@ -27,6 +27,7 @@ #include "vec/functions/simple_function_factory.h" namespace doris::vectorized { +#include "common/compile_check_begin.h" template struct PlusImpl { @@ -36,7 +37,7 @@ struct PlusImpl { template static inline Result apply(A a, B b) { /// Next everywhere, static_cast - so that there is no wrong result in expressions of the form Int64 c = UInt32(a) * Int32(-1). - return static_cast(a) + b; + return static_cast(a) + static_cast(b); } template diff --git a/be/src/vec/functions/random.cpp b/be/src/vec/functions/random.cpp index 1b8dea935d19a17..817fa5e94b8343f 100644 --- a/be/src/vec/functions/random.cpp +++ b/be/src/vec/functions/random.cpp @@ -41,6 +41,7 @@ #include "vec/functions/simple_function_factory.h" namespace doris::vectorized { +#include "common/compile_check_begin.h" class Random : public IFunction { public: static constexpr auto name = "random"; @@ -71,7 +72,7 @@ class Random : public IFunction { if (!context->is_col_constant(0)) { return Status::InvalidArgument("The param of rand function must be literal"); } - uint32_t seed = 0; + int64_t seed = 0; if (!context->get_constant_col(0)->column_ptr->is_null_at(0)) { seed = (*context->get_constant_col(0)->column_ptr)[0].get(); } diff --git a/be/src/vec/functions/round.h b/be/src/vec/functions/round.h index dbf4f95037c62a0..9f02b733fcb0c85 100644 --- a/be/src/vec/functions/round.h +++ b/be/src/vec/functions/round.h @@ -42,6 +42,7 @@ #include #include +#include "common/cast_set.h" #include "vec/columns/column.h" #include "vec/columns/column_decimal.h" #include "vec/core/call_on_type_index.h" @@ -49,6 +50,7 @@ #include "vec/data_types/data_type_number.h" namespace doris::vectorized { +#include "common/compile_check_begin.h" enum class ScaleMode { Positive, // round to a number with N decimal places after the decimal point @@ -80,8 +82,6 @@ template ) { + // no need to check cast value for scale, since it's + // already checked before + *out = compute(*in, cast_set(scale), cast_set(target_scale)); + } else { + *out = compute(*in, scale, target_scale); + } } }; @@ -164,8 +170,8 @@ class DecimalRoundingImpl { public: static NO_INLINE void apply(const Container& in, UInt32 in_scale, Container& out, - Int16 out_scale) { - Int16 scale_arg = in_scale - out_scale; + Int32 out_scale) { + Int32 scale_arg = in_scale - out_scale; if (scale_arg > 0) { auto scale = DecimalScaleParams::get_scale_factor(scale_arg); @@ -193,8 +199,8 @@ class DecimalRoundingImpl { } static NO_INLINE void apply(const NativeType& in, UInt32 in_scale, NativeType& out, - Int16 out_scale) { - Int16 scale_arg = in_scale - out_scale; + Int32 out_scale) { + Int32 scale_arg = in_scale - out_scale; if (scale_arg > 0) { auto scale = DecimalScaleParams::get_scale_factor(scale_arg); if (out_scale < 0) { @@ -268,7 +274,7 @@ class BaseFloatRoundingComputation { return roundWithMode(val, mode); } - static VectorType prepare(size_t scale) { return load1(scale); } + static VectorType prepare(size_t scale) { return load1(static_cast(scale)); } }; /** Implementation of low-level round-off functions for floating-point values. @@ -550,7 +556,7 @@ struct Dispatcher { return col_res; } else if constexpr (IsDecimalNumber) { const auto* decimal_col = assert_cast*>(col_general); - const Int32 input_scale = decimal_col->get_scale(); + const auto input_scale = decimal_col->get_scale(); auto col_res = ColumnDecimal::create(input_row_count, result_scale); for (size_t i = 0; i < input_row_count; ++i) { @@ -649,7 +655,7 @@ struct Dispatcher { typename ColumnVector::Container& vec_res = col_res->get_data(); for (size_t i = 0; i < input_rows_count; ++i) { - const Int16 scale_arg = col_scale_i32.get_data()[i]; + const auto scale_arg = col_scale_i32.get_data()[i]; if (scale_arg == 0) { size_t scale = 1; FunctionRoundingImpl::apply(general_val, scale, vec_res[i]); @@ -716,7 +722,8 @@ class FunctionRounding : public IFunction { name, scale_arg); } - *scale = scale_arg; + // scale_arg value is already checked + *scale = static_cast(scale_arg); return Status::OK(); } @@ -746,7 +753,7 @@ class FunctionRounding : public IFunction { // For decimal, we will always make sure result Decimal has exactly same precision and scale with // arguments from query plan. - Int16 result_scale = 0; + UInt32 result_scale = 0; if constexpr (IsDataTypeDecimal) { if (column_result.type->get_type_id() == TypeIndex::Nullable) { if (auto nullable_type = std::dynamic_pointer_cast( @@ -773,7 +780,7 @@ class FunctionRounding : public IFunction { } res = Dispatcher::apply_vec_const( - col_general, scale_arg, result_scale); + col_general, scale_arg, cast_set(result_scale)); } else { // the SECOND arugment is COLUMN if (is_col_general_const) { @@ -781,12 +788,12 @@ class FunctionRounding : public IFunction { apply_const_vec( &assert_cast(*column_general.column), block.get_by_position(arguments[1]).column.get(), - result_scale); + cast_set(result_scale)); } else { res = Dispatcher:: apply_vec_vec(col_general, block.get_by_position(arguments[1]).column.get(), - result_scale); + cast_set(result_scale)); } } return true; @@ -876,3 +883,4 @@ struct DecimalRoundOneImpl { }; } // namespace doris::vectorized +#include "common/compile_check_end.h" diff --git a/be/src/vec/functions/url/functions_url.h b/be/src/vec/functions/url/functions_url.h index b6736496d24345c..7089f64aee73f9a 100644 --- a/be/src/vec/functions/url/functions_url.h +++ b/be/src/vec/functions/url/functions_url.h @@ -20,10 +20,12 @@ #pragma once +#include "common/cast_set.h" #include "vec/columns/column_string.h" #include "vec/common/memcpy_small.h" namespace doris::vectorized { +#include "common/compile_check_begin.h" /** URL processing functions. See implementation in separate .cpp files. * All functions are not strictly follow RFC, instead they are maximally simplified for performance reasons. @@ -93,7 +95,7 @@ struct ExtractSubstringImpl { memcpy_small_allow_read_write_overflow15(&res_data[res_offset], start, length); res_offset += length; - res_offsets[i] = res_offset; + res_offsets[i] = cast_set(res_offset); prev_offset = offsets[i]; } } @@ -152,3 +154,4 @@ struct CutSubstringImpl { }; } // namespace doris::vectorized +#include "common/compile_check_end.h"