Skip to content

Commit

Permalink
[env](compile)open compile check in some function agg file (#44549)
Browse files Browse the repository at this point in the history
### What problem does this PR solve?

This is part of the changes because modifying too much at once can
easily cause conflicts with other PRs.
  • Loading branch information
Mryange authored Dec 3, 2024
1 parent 829b4b7 commit 3e3948c
Show file tree
Hide file tree
Showing 88 changed files with 260 additions and 64 deletions.
3 changes: 3 additions & 0 deletions be/src/vec/aggregate_functions/aggregate_function.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
#include "vec/data_types/data_type_string.h"

namespace doris::vectorized {
#include "common/compile_check_begin.h"

class Arena;
class IColumn;
Expand Down Expand Up @@ -598,3 +599,5 @@ class AggregateFunctionGuard {
};

} // namespace doris::vectorized

#include "common/compile_check_end.h"
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#include "vec/functions/function.h"

namespace doris::vectorized {
#include "common/compile_check_begin.h"

AggregateFunctionPtr create_aggregate_function_approx_count_distinct(
const std::string& name, const DataTypes& argument_types, const bool result_is_nullable,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
#include "vec/io/io_helper.h"

namespace doris {
#include "common/compile_check_begin.h"
namespace vectorized {
class Arena;
class BufferReadable;
Expand All @@ -64,8 +65,7 @@ struct AggregateFunctionApproxCountDistinctData {
void write(BufferWritable& buf) const {
std::string result;
result.resize(hll_data.max_serialized_size());
int size = hll_data.serialize((uint8_t*)result.data());
result.resize(size);
result.resize(hll_data.serialize((uint8_t*)result.data()));
write_binary(result, buf);
}

Expand Down Expand Up @@ -136,3 +136,5 @@ class AggregateFunctionApproxCountDistinct final
};

} // namespace doris::vectorized

#include "common/compile_check_end.h"
1 change: 1 addition & 0 deletions be/src/vec/aggregate_functions/aggregate_function_avg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include "vec/core/field.h"

namespace doris::vectorized {
#include "common/compile_check_begin.h"

template <typename T>
struct Avg {
Expand Down
16 changes: 12 additions & 4 deletions be/src/vec/aggregate_functions/aggregate_function_avg.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
#include "vec/io/io_helper.h"

namespace doris {
#include "common/compile_check_begin.h"
namespace vectorized {
class Arena;
class BufferReadable;
Expand Down Expand Up @@ -72,7 +73,8 @@ struct AggregateFunctionAvgData {
ResultT result() const {
if constexpr (std::is_floating_point_v<ResultT>) {
if constexpr (std::numeric_limits<ResultT>::is_iec559) {
return static_cast<ResultT>(sum) / count; /// allow division by zero
return static_cast<ResultT>(sum) /
static_cast<ResultT>(count); /// allow division by zero
}
}

Expand All @@ -91,7 +93,7 @@ struct AggregateFunctionAvgData {
if constexpr (IsDecimal256<T>) {
return static_cast<ResultT>(sum / T(count));
} else {
return static_cast<ResultT>(sum) / count;
return static_cast<ResultT>(sum) / static_cast<ResultT>(count);
}
}
}
Expand Down Expand Up @@ -124,7 +126,11 @@ class AggregateFunctionAvg final
IsDecimalV2<T>, ColumnDecimal<Decimal128V2>,
std::conditional_t<IsDecimalNumber<T>, ColumnDecimal<typename Data::ResultType>,
ColumnFloat64>>;
// The result calculated by PercentileApprox is an approximate value,
// so the underlying storage uses float. The following calls will involve
// an implicit cast to float.

using DataType = typename Data::ResultType;
/// ctor for native types
AggregateFunctionAvg(const DataTypes& argument_types_)
: IAggregateFunctionDataHelper<Data, AggregateFunctionAvg<T, Data>>(argument_types_),
Expand All @@ -148,9 +154,9 @@ class AggregateFunctionAvg final
const auto& column =
assert_cast<const ColVecType&, TypeCheckOnRelease::DISABLE>(*columns[0]);
if constexpr (IsDecimalNumber<T>) {
this->data(place).sum += column.get_data()[row_num].value;
this->data(place).sum += (DataType)column.get_data()[row_num].value;
} else {
this->data(place).sum += column.get_data()[row_num];
this->data(place).sum += (DataType)column.get_data()[row_num];
}
++this->data(place).count;
}
Expand Down Expand Up @@ -282,3 +288,5 @@ class AggregateFunctionAvg final
};

} // namespace doris::vectorized

#include "common/compile_check_end.h"
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include "vec/aggregate_functions/helpers.h"

namespace doris::vectorized {
#include "common/compile_check_begin.h"
void register_aggregate_function_avg_weighted(AggregateFunctionSimpleFactory& factory) {
factory.register_function_both("avg_weighted",
creator_with_type::creator<AggregateFunctionAvgWeight>);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
#include "vec/io/io_helper.h"

namespace doris {
#include "common/compile_check_begin.h"
namespace vectorized {
class Arena;
class BufferReadable;
Expand All @@ -57,7 +58,7 @@ struct AggregateFunctionAvgWeightedData {
DecimalV2Value value = binary_cast<Int128, DecimalV2Value>(data_val);
data_sum = data_sum + (double(value) * weight_val);
} else {
data_sum = data_sum + (data_val * weight_val);
data_sum = data_sum + (double(data_val) * weight_val);
}
weight_sum = weight_sum + weight_val;
}
Expand Down Expand Up @@ -138,3 +139,5 @@ class AggregateFunctionAvgWeight final
};

} // namespace doris::vectorized

#include "common/compile_check_end.h"
3 changes: 3 additions & 0 deletions be/src/vec/aggregate_functions/aggregate_function_binary.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
#include "vec/io/io_helper.h"

namespace doris::vectorized {
#include "common/compile_check_begin.h"

template <typename T1, typename T2, template <typename> typename Moments>
struct StatFunc {
Expand Down Expand Up @@ -127,3 +128,5 @@ AggregateFunctionPtr create_with_two_basic_numeric_types(const DataTypePtr& firs
}

} // namespace doris::vectorized

#include "common/compile_check_end.h"
1 change: 1 addition & 0 deletions be/src/vec/aggregate_functions/aggregate_function_bit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include "vec/aggregate_functions/helpers.h"

namespace doris::vectorized {
#include "common/compile_check_begin.h"

void register_aggregate_function_bit(AggregateFunctionSimpleFactory& factory) {
factory.register_function_both(
Expand Down
4 changes: 3 additions & 1 deletion be/src/vec/aggregate_functions/aggregate_function_bit.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#include "vec/io/io_helper.h"

namespace doris {
#include "common/compile_check_begin.h"
namespace vectorized {
class Arena;
class BufferReadable;
Expand Down Expand Up @@ -142,4 +143,5 @@ class AggregateFunctionBitwise final
}
};

} // namespace doris::vectorized
} // namespace doris::vectorized
#include "common/compile_check_end.h"
7 changes: 6 additions & 1 deletion be/src/vec/aggregate_functions/aggregate_function_bitmap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include "vec/data_types/data_type_nullable.h"

namespace doris::vectorized {
#include "common/compile_check_begin.h"

template <bool nullable, template <bool, typename> class AggregateFunctionTemplate>
AggregateFunctionPtr create_with_int_data_type(const DataTypes& argument_type) {
Expand All @@ -33,7 +34,11 @@ AggregateFunctionPtr create_with_int_data_type(const DataTypes& argument_type) {
return std::make_shared<AggregateFunctionTemplate<nullable, ColumnVector<TYPE>>>( \
argument_type); \
}
FOR_INTEGER_TYPES(DISPATCH)
// Keep consistent with the FE definition; the function does not have an int128 type.
DISPATCH(Int8)
DISPATCH(Int16)
DISPATCH(Int32)
DISPATCH(Int64)
#undef DISPATCH
LOG(WARNING) << "with unknowed type, failed in create_with_int_data_type bitmap_union_int"
<< " and type is: " << argument_type[0]->get_name();
Expand Down
4 changes: 3 additions & 1 deletion be/src/vec/aggregate_functions/aggregate_function_bitmap.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
#include "vec/data_types/data_type_number.h"

namespace doris {
#include "common/compile_check_begin.h"
namespace vectorized {
class Arena;
class BufferReadable;
Expand Down Expand Up @@ -432,4 +433,5 @@ AggregateFunctionPtr create_aggregate_function_bitmap_union(const std::string& n
const DataTypes& argument_types,
const bool result_is_nullable);

} // namespace doris::vectorized
} // namespace doris::vectorized
#include "common/compile_check_end.h"
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include "vec/data_types/data_type_nullable.h"

namespace doris::vectorized {
#include "common/compile_check_begin.h"

template <bool nullable>
AggregateFunctionPtr create_with_int_data_type(const DataTypes& argument_types) {
Expand All @@ -32,7 +33,11 @@ AggregateFunctionPtr create_with_int_data_type(const DataTypes& argument_types)
if (which.idx == TypeIndex::TYPE) { \
return std::make_shared<AggregateFunctionBitmapAgg<nullable, TYPE>>(argument_types); \
}
FOR_INTEGER_TYPES(DISPATCH)
// Keep consistent with the FE definition; the function does not have an int128 type.
DISPATCH(Int8)
DISPATCH(Int16)
DISPATCH(Int32)
DISPATCH(Int64)
#undef DISPATCH
LOG(WARNING) << "with unknown type, failed in create_with_int_data_type bitmap_union_int"
<< " and type is: " << argument_types[0]->get_name();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#include "vec/data_types/data_type_bitmap.h"

namespace doris {
#include "common/compile_check_begin.h"
namespace vectorized {
class Arena;
class BufferReadable;
Expand Down Expand Up @@ -226,4 +227,5 @@ class AggregateFunctionBitmapAgg final
}
};

} // namespace doris::vectorized
} // namespace doris::vectorized
#include "common/compile_check_end.h"
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include "vec/aggregate_functions/helpers.h"

namespace doris::vectorized {
#include "common/compile_check_begin.h"

template <typename T, typename HasLimit, typename ShowNull>
AggregateFunctionPtr do_create_agg_function_collect(bool distinct, const DataTypes& argument_types,
Expand Down
3 changes: 3 additions & 0 deletions be/src/vec/aggregate_functions/aggregate_function_collect.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
#include "vec/io/var_int.h"

namespace doris {
#include "common/compile_check_begin.h"
namespace vectorized {
class Arena;
} // namespace vectorized
Expand Down Expand Up @@ -836,3 +837,5 @@ class AggregateFunctionCollect
};

} // namespace doris::vectorized

#include "common/compile_check_end.h"
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include "vec/data_types/data_type.h"

namespace doris::vectorized {
#include "common/compile_check_begin.h"

/** Aggregate function combinator allows to take one aggregate function
* and transform it to another aggregate function.
Expand Down Expand Up @@ -69,3 +70,5 @@ class IAggregateFunctionCombinator {
};

} // namespace doris::vectorized

#include "common/compile_check_end.h"
1 change: 1 addition & 0 deletions be/src/vec/aggregate_functions/aggregate_function_corr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include "vec/core/types.h"

namespace doris::vectorized {
#include "common/compile_check_begin.h"

template <typename T>
struct CorrMoment {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include "vec/aggregate_functions/factory_helpers.h"

namespace doris::vectorized {
#include "common/compile_check_begin.h"

AggregateFunctionPtr create_aggregate_function_count(const std::string& name,
const DataTypes& argument_types,
Expand Down
3 changes: 3 additions & 0 deletions be/src/vec/aggregate_functions/aggregate_function_count.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
#include "vec/io/var_int.h"

namespace doris {
#include "common/compile_check_begin.h"
namespace vectorized {
class Arena;
class BufferReadable;
Expand Down Expand Up @@ -321,3 +322,5 @@ class AggregateFunctionCountNotNullUnary final
};

} // namespace doris::vectorized

#include "common/compile_check_end.h"
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include "vec/core/types.h"

namespace doris::vectorized {
#include "common/compile_check_begin.h"

AggregateFunctionPtr create_aggregate_function_count_by_enum(const std::string& name,
const DataTypes& argument_types,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
#include "vec/io/io_helper.h"

namespace doris::vectorized {
#include "common/compile_check_begin.h"

struct CountByEnumData {
std::unordered_map<std::string, uint64_t> cbe;
Expand All @@ -46,8 +47,7 @@ void build_json_from_vec(rapidjson::StringBuffer& buffer,
doc.SetArray();
rapidjson::Document::AllocatorType& allocator = doc.GetAllocator();

int vec_size_number = data_vec.size();
for (int idx = 0; idx < vec_size_number; ++idx) {
for (size_t idx = 0; idx < data_vec.size(); ++idx) {
rapidjson::Value obj(rapidjson::kObjectType);

rapidjson::Value obj_cbe(rapidjson::kObjectType);
Expand Down Expand Up @@ -239,4 +239,5 @@ class AggregateFunctionCountByEnum final
size_t arg_count;
};

} // namespace doris::vectorized
} // namespace doris::vectorized
#include "common/compile_check_end.h"
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include "vec/data_types/data_type_nullable.h"

namespace doris::vectorized {
#include "common/compile_check_begin.h"

template <template <typename> class Function, template <typename> class Data>
AggregateFunctionPtr create_function_single_value(const String& name,
Expand Down
9 changes: 5 additions & 4 deletions be/src/vec/aggregate_functions/aggregate_function_covar.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,12 @@ struct BaseData {
if (count == 1) {
return 0.0;
}
return sum_xy / count - sum_x * sum_y / (count * count);
return sum_xy / (double)count - sum_x * sum_y / ((double)count * (double)count);
}

double get_samp_result() const {
return sum_xy / (count - 1) - sum_x * sum_y / (count * (count - 1));
return sum_xy / double(count - 1) -
sum_x * sum_y / ((double)(count) * ((double)(count - 1)));
}

void merge(const BaseData& rhs) {
Expand All @@ -95,10 +96,10 @@ struct BaseData {
void add(const IColumn* column_x, const IColumn* column_y, size_t row_num) {
const auto& sources_x =
assert_cast<const ColumnVector<T>&, TypeCheckOnRelease::DISABLE>(*column_x);
double source_data_x = sources_x.get_data()[row_num];
double source_data_x = double(sources_x.get_data()[row_num]);
const auto& sources_y =
assert_cast<const ColumnVector<T>&, TypeCheckOnRelease::DISABLE>(*column_y);
double source_data_y = sources_y.get_data()[row_num];
double source_data_y = double(sources_y.get_data()[row_num]);

sum_x += source_data_x;
sum_y += source_data_y;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include "vec/data_types/data_type_nullable.h"

namespace doris::vectorized {
#include "common/compile_check_begin.h"

template <typename T>
struct Reducer {
Expand Down
Loading

0 comments on commit 3e3948c

Please sign in to comment.