From a6f10d12f11b7f10239a9c5cdf3b819f97239f20 Mon Sep 17 00:00:00 2001 From: jacktengg <18241664+jacktengg@users.noreply.github.com> Date: Mon, 4 Nov 2024 17:04:31 +0800 Subject: [PATCH] [env](compile) open compile check for some files --- be/src/vec/functions/function_timestamp.cpp | 33 +++++++------ be/src/vec/functions/function_tokenize.cpp | 4 +- .../vec/functions/function_width_bucket.cpp | 10 ++-- be/src/vec/functions/int_div.h | 46 +++++++++++++------ be/src/vec/functions/like.cpp | 20 ++++---- be/src/vec/functions/match.cpp | 30 ++++++------ be/src/vec/functions/match.h | 2 +- be/src/vec/functions/math.cpp | 10 ++-- be/src/vec/functions/minus.cpp | 9 +++- be/src/vec/functions/modulo.cpp | 13 +++--- be/src/vec/functions/multiply.cpp | 3 +- be/src/vec/functions/plus.cpp | 3 +- be/src/vec/functions/random.cpp | 3 +- be/src/vec/functions/round.h | 33 +++++++------ be/src/vec/functions/url/functions_url.h | 4 +- 15 files changed, 138 insertions(+), 85 deletions(-) diff --git a/be/src/vec/functions/function_timestamp.cpp b/be/src/vec/functions/function_timestamp.cpp index 7c2e62e5723067f..1528941f0753620 100644 --- a/be/src/vec/functions/function_timestamp.cpp +++ b/be/src/vec/functions/function_timestamp.cpp @@ -68,8 +68,10 @@ #include "vec/functions/simple_function_factory.h" #include "vec/runtime/vdatetime_value.h" #include "vec/utils/util.hpp" +#include "common/cast_set.h" namespace doris::vectorized { +// #include "common/compile_check_begin.h" template struct StrToDate { @@ -195,8 +197,8 @@ 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, + _execute_inner_loop(l_raw_str, cast_set(l_str_size), format_str.data, + cast_set(format_str.size), context, res, null_map, i); } } @@ -210,18 +212,19 @@ struct StrToDate { size_t size = loffsets.size(); res.resize(size); const StringRef format_str = rewrite_specific_format(rdata.data, rdata.size); + int format_str_size = cast_set(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, + _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,8 @@ 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; + // timestamp in seconds is 10 digits + 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 +718,7 @@ 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; } @@ -927,7 +932,8 @@ struct LastDayImpl { res_data[i] = binary_cast(ts_value); } else { ts_value.template unchecked_set_time_unit(day); - ts_value.unchecked_set_time(ts_value.year(), ts_value.month(), day, 0, 0, 0, 0); + // get_last_month_day guarantees day is legal + ts_value.unchecked_set_time(ts_value.year(), ts_value.month(), cast_set(day), 0, 0, 0, 0); UInt64 cast_value = binary_cast(ts_value); DataTypeDateTimeV2::cast_to_date_v2(cast_value, res_data[i]); } @@ -947,7 +953,8 @@ struct LastDayImpl { if constexpr (std::is_same_v) { res_data[i] = binary_cast(ts_value); } else if constexpr (std::is_same_v) { - ts_value.unchecked_set_time(ts_value.year(), ts_value.month(), day, 0, 0, 0, 0); + // get_last_month_day guarantees day is legal + ts_value.unchecked_set_time(ts_value.year(), ts_value.month(), cast_set(day), 0, 0, 0, 0); UInt64 cast_value = binary_cast(ts_value); DataTypeDateTimeV2::cast_to_date_v2(cast_value, res_data[i]); } diff --git a/be/src/vec/functions/function_tokenize.cpp b/be/src/vec/functions/function_tokenize.cpp index be0eb5dddc960d3..2868675eb928d60 100644 --- a/be/src/vec/functions/function_tokenize.cpp +++ b/be/src/vec/functions/function_tokenize.cpp @@ -34,8 +34,10 @@ #include "vec/core/column_with_type_and_name.h" #include "vec/data_types/data_type_nullable.h" #include "vec/data_types/data_type_number.h" +#include "common/cast_set.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..6287ec76fe02928 100644 --- a/be/src/vec/functions/function_width_bucket.cpp +++ b/be/src/vec/functions/function_width_bucket.cpp @@ -38,12 +38,14 @@ #include "vec/data_types/data_type_number.h" #include "vec/functions/function.h" #include "vec/functions/simple_function_factory.h" +#include "common/cast_set.h" namespace doris { 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 +105,20 @@ 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); + using arg_type = decltype(min_value); + auto range = max_value - min_value; + 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); + 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..95b6baeec96a6af 100644 --- a/be/src/vec/functions/int_div.h +++ b/be/src/vec/functions/int_div.h @@ -22,12 +22,15 @@ #include #include +#include +#include "common/status.h" #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 +41,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 +68,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..5c199928cfb8d44 100644 --- a/be/src/vec/functions/like.cpp +++ b/be/src/vec/functions/like.cpp @@ -35,8 +35,10 @@ #include "vec/core/block.h" #include "vec/core/column_with_type_and_name.h" #include "vec/functions/simple_function_factory.h" +#include "common/cast_set.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,7 @@ 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 +289,8 @@ 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 +386,7 @@ 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,7 +420,7 @@ 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, + 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)); @@ -447,7 +449,7 @@ 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, + 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) { @@ -770,8 +772,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 +793,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..2fb8f823a514938 100644 --- a/be/src/vec/functions/match.cpp +++ b/be/src/vec/functions/match.cpp @@ -23,8 +23,10 @@ #include "runtime/query_context.h" #include "runtime/runtime_state.h" #include "util/debug_points.h" +#include "common/cast_set.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,14 +480,14 @@ 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, + 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..ff26c179281008c 100644 --- a/be/src/vec/functions/math.cpp +++ b/be/src/vec/functions/math.cpp @@ -42,6 +42,7 @@ #include "vec/functions/function_totype.h" #include "vec/functions/function_unary_arithmetic.h" #include "vec/functions/simple_function_factory.h" +#include "common/cast_set.h" namespace doris { namespace vectorized { @@ -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..515ed0e09ff1270 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,13 @@ struct MinusImpl { template static inline Result apply(A a, B b) { - return static_cast(a) - b; + // if constexpr (!std::is_integral_v && (!std::is_same_v || !std::is_same_v)) { + // throw doris::Exception(ErrorCode::RUNTIME_ERROR, + // "MinusImpl param types error"); + // __builtin_unreachable(); + // } else { + 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..fa3979d0850d9c0 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 std::fmod(static_cast(a), static_cast(b)); } else { throw_if_division_leads_to_FPE(a, b); return a % b; @@ -108,10 +109,10 @@ 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 +124,10 @@ 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..68b4c8c926426e0 100644 --- a/be/src/vec/functions/round.h +++ b/be/src/vec/functions/round.h @@ -47,8 +47,10 @@ #include "vec/core/call_on_type_index.h" #include "vec/data_types/data_type_decimal.h" #include "vec/data_types/data_type_number.h" +#include "common/cast_set.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 @@ -150,7 +152,11 @@ struct IntegerRoundingComputation { return; } } - *out = compute(*in, scale, target_scale); + if constexpr (!std::is_same_v) { + *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) { + auto 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) { + auto 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,7 @@ class FunctionRounding : public IFunction { name, scale_arg); } - *scale = scale_arg; + *scale = static_cast(scale_arg); return Status::OK(); } @@ -746,7 +752,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 +779,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 +787,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 +882,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..43eb52da9b0e887 100644 --- a/be/src/vec/functions/url/functions_url.h +++ b/be/src/vec/functions/url/functions_url.h @@ -24,6 +24,7 @@ #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. @@ -80,7 +81,7 @@ struct ExtractSubstringImpl { res_data.reserve(size * Extractor::get_reserve_length_for_element()); size_t prev_offset = 0; - size_t res_offset = 0; + ColumnString::Offset res_offset = 0; /// Matched part. Pos start; @@ -152,3 +153,4 @@ struct CutSubstringImpl { }; } // namespace doris::vectorized +#include "common/compile_check_end.h"