Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions be/src/service/internal_service.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
#include <vec/sink/varrow_flight_result_writer.h>

#include <algorithm>
#include <exception>
#include <filesystem>
#include <memory>
#include <set>
Expand Down Expand Up @@ -340,6 +341,8 @@ void PInternalService::_exec_plan_fragment_in_pthread(google::protobuf::RpcContr
st = _exec_plan_fragment_impl(request->request(), version, compact);
} catch (const Exception& e) {
st = e.to_status();
} catch (const std::exception& e) {
st = Status::Error(ErrorCode::INTERNAL_ERROR, e.what());
} catch (...) {
st = Status::Error(ErrorCode::INTERNAL_ERROR,
"_exec_plan_fragment_impl meet unknown error");
Expand Down Expand Up @@ -2220,6 +2223,8 @@ void PInternalService::group_commit_insert(google::protobuf::RpcController* cont
});
} catch (const Exception& e) {
st = e.to_status();
} catch (const std::exception& e) {
st = Status::Error(ErrorCode::INTERNAL_ERROR, e.what());
} catch (...) {
st = Status::Error(ErrorCode::INTERNAL_ERROR,
"_exec_plan_fragment_impl meet unknown error");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,17 @@
namespace doris::vectorized {
#include "common/compile_check_begin.h"

template <int define_index>
using creator = creator_with_type_list_base<define_index, TYPE_TINYINT, TYPE_SMALLINT, TYPE_INT,
TYPE_BIGINT, TYPE_LARGEINT>;

template <size_t N>
AggregateFunctionPtr create_aggregate_function_multi_top_sum_impl(
const DataTypes& argument_types, const bool result_is_nullable,
const AggregateFunctionAttr& attr) {
if (N == argument_types.size() - 3) {
return creator_with_integer_type_with_index<N>::template create<
AggregateFunctionApproxTopSumSimple>(argument_types, result_is_nullable, attr,
attr.column_names);
return creator<N>::template create<AggregateFunctionApproxTopSumSimple>(
argument_types, result_is_nullable, attr, attr.column_names);
} else {
return create_aggregate_function_multi_top_sum_impl<N - 1>(argument_types,
result_is_nullable, attr);
Expand All @@ -44,7 +47,7 @@ template <>
AggregateFunctionPtr create_aggregate_function_multi_top_sum_impl<0>(
const DataTypes& argument_types, const bool result_is_nullable,
const AggregateFunctionAttr& attr) {
return creator_with_integer_type::create<AggregateFunctionApproxTopSumSimple>(
return creator<0>::create<AggregateFunctionApproxTopSumSimple>(
argument_types, result_is_nullable, attr, attr.column_names);
}

Expand Down
5 changes: 2 additions & 3 deletions be/src/vec/aggregate_functions/aggregate_function_avg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,9 @@ void register_aggregate_function_avg(AggregateFunctionSimpleFactory& factory) {
AggregateFunctionCreator creator = [&](const std::string& name, const DataTypes& types,
const bool result_is_nullable,
const AggregateFunctionAttr& attr) {
if (attr.enable_decimal256) {
if (attr.enable_decimal256 && is_decimal(types[0]->get_primitive_type())) {
return creator_with_type_list<
TYPE_TINYINT, TYPE_SMALLINT, TYPE_INT, TYPE_BIGINT, TYPE_LARGEINT, TYPE_DOUBLE,
TYPE_DECIMAL32, TYPE_DECIMAL64, TYPE_DECIMAL128I, TYPE_DECIMALV2,
TYPE_DECIMAL32, TYPE_DECIMAL64, TYPE_DECIMAL128I,
TYPE_DECIMAL256>::creator<AggregateFuncAvgDecimal256>(name, types,
result_is_nullable, attr);
} else {
Expand Down
14 changes: 7 additions & 7 deletions be/src/vec/aggregate_functions/aggregate_function_distinct.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

#include "vec/aggregate_functions/aggregate_function_distinct.h"

#include <ostream>
#include <algorithm>

#include "vec/aggregate_functions/aggregate_function_combinator.h"
#include "vec/aggregate_functions/aggregate_function_simple_factory.h"
Expand Down Expand Up @@ -63,8 +63,10 @@ class AggregateFunctionCombinatorDistinct final : public IAggregateFunctionCombi

if (arguments.size() == 1) {
AggregateFunctionPtr res(
creator_with_numeric_type::create<AggregateFunctionDistinctNumeric>(
arguments, result_is_nullable, attr, nested_function));
creator_with_type_list<TYPE_TINYINT, TYPE_SMALLINT, TYPE_INT, TYPE_BIGINT,
TYPE_LARGEINT>::
create<AggregateFunctionDistinctNumeric>(arguments, result_is_nullable,
attr, nested_function));
if (res) {
return res;
}
Expand All @@ -80,16 +82,14 @@ class AggregateFunctionCombinatorDistinct final : public IAggregateFunctionCombi
}
};

const std::string DISTINCT_FUNCTION_PREFIX = "multi_distinct_";

void register_aggregate_function_combinator_distinct(AggregateFunctionSimpleFactory& factory) {
AggregateFunctionCreator creator = [&](const std::string& name, const DataTypes& types,
const bool result_is_nullable,
const AggregateFunctionAttr& attr) {
// 1. we should get not nullable types;
DataTypes nested_types(types.size());
std::transform(types.begin(), types.end(), nested_types.begin(),
[](const auto& e) { return remove_nullable(e); });
std::ranges::transform(types, nested_types.begin(),
[](const auto& e) { return remove_nullable(e); });
auto function_combinator = std::make_shared<AggregateFunctionCombinatorDistinct>();
auto transform_arguments = function_combinator->transform_arguments(nested_types);
auto nested_function_name = name.substr(DISTINCT_FUNCTION_PREFIX.size());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,10 @@ inline AggregateFunctionPtr create_aggregate_function_group_array_intersect_impl
const AggregateFunctionAttr& attr) {
const auto& nested_type = remove_nullable(
dynamic_cast<const DataTypeArray&>(*(argument_types[0])).get_nested_type());
AggregateFunctionPtr res =
creator_with_numeric_type::create<AggregateFunctionGroupArrayIntersect>(
argument_types, result_is_nullable, attr);
AggregateFunctionPtr res = creator_with_type_list<
TYPE_TINYINT, TYPE_SMALLINT, TYPE_INT, TYPE_BIGINT,
TYPE_LARGEINT>::create<AggregateFunctionGroupArrayIntersect>(argument_types,
result_is_nullable, attr);

if (!res) {
res = AggregateFunctionPtr(create_with_extra_types(nested_type, argument_types, attr));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,10 @@ AggregateFunctionPtr create_aggregate_function_orthogonal(const std::string& nam
argument_types, result_is_nullable, attr);
} else {
AggregateFunctionPtr res(
creator_with_integer_type_with_index<1>::create<AggFunctionOrthBitmapFunc, Impl>(
argument_types, result_is_nullable, attr));
creator_with_type_list_base<1, TYPE_TINYINT, TYPE_SMALLINT, TYPE_INT, TYPE_BIGINT,
TYPE_LARGEINT>::create<AggFunctionOrthBitmapFunc,
Impl>(argument_types,
result_is_nullable, attr));
if (res) {
return res;
} else if (is_string_type(argument_types[1]->get_primitive_type())) {
Expand Down
10 changes: 5 additions & 5 deletions be/src/vec/aggregate_functions/aggregate_function_percentile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,12 @@ AggregateFunctionPtr create_aggregate_function_percentile_approx_weighted(
}

void register_aggregate_function_percentile(AggregateFunctionSimpleFactory& factory) {
factory.register_function_both("percentile",
creator_with_numeric_type::creator<AggregateFunctionPercentile>);
using creator = creator_with_type_list<TYPE_TINYINT, TYPE_SMALLINT, TYPE_INT, TYPE_BIGINT,
TYPE_LARGEINT, TYPE_FLOAT, TYPE_DOUBLE>;
factory.register_function_both("percentile", creator::creator<AggregateFunctionPercentile>);
factory.register_alias("percentile", "percentile_cont");
factory.register_function_both(
"percentile_array",
creator_with_numeric_type::creator<AggregateFunctionPercentileArray>);
factory.register_function_both("percentile_array",
creator::creator<AggregateFunctionPercentileArray>);
}

void register_percentile_approx_old_function(AggregateFunctionSimpleFactory& factory) {
Expand Down
7 changes: 6 additions & 1 deletion be/src/vec/aggregate_functions/aggregate_function_reader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,12 @@ void register_aggregate_function_reader_load(AggregateFunctionSimpleFactory& fac
factory.register_function_both(name + AGG_LOAD_SUFFIX, creator);
};

register_function_both("sum", creator_with_type::creator<AggregateFunctionSumSimpleReader>);
register_function_both(
"sum",
creator_with_type_list<TYPE_TINYINT, TYPE_SMALLINT, TYPE_INT, TYPE_BIGINT,
TYPE_LARGEINT, TYPE_FLOAT, TYPE_DOUBLE, TYPE_DECIMAL32,
TYPE_DECIMAL64, TYPE_DECIMAL128I, TYPE_DECIMAL256,
TYPE_DECIMALV2>::creator<AggregateFunctionSumSimpleReader>);
register_function_both("max", create_aggregate_function_single_value<AggregateFunctionMaxData>);
register_function_both("min", create_aggregate_function_single_value<AggregateFunctionMinData>);
register_function_both("bitmap_union",
Expand Down
77 changes: 11 additions & 66 deletions be/src/vec/aggregate_functions/aggregate_function_regr_union.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,91 +25,36 @@
namespace doris::vectorized {
#include "common/compile_check_begin.h"

template <PrimitiveType T, template <PrimitiveType> class StatFunctionTemplate>
AggregateFunctionPtr type_dispatch_for_aggregate_function_regr(const DataTypes& argument_types,
const bool& result_is_nullable,
const AggregateFunctionAttr& attr,
bool y_nullable_input,
bool x_nullable_input) {
template <template <PrimitiveType> class StatFunctionTemplate>
AggregateFunctionPtr create_aggregate_function_regr(const std::string& name,
const DataTypes& argument_types,
const bool result_is_nullable,
const AggregateFunctionAttr& attr) {
bool y_nullable_input = argument_types[0]->is_nullable();
bool x_nullable_input = argument_types[1]->is_nullable();
if (y_nullable_input) {
if (x_nullable_input) {
return creator_without_type::create_ignore_nullable<
AggregateFunctionRegrSimple<StatFunctionTemplate<T>, true, true>>(
AggregateFunctionRegrSimple<StatFunctionTemplate<TYPE_DOUBLE>, true, true>>(
argument_types, result_is_nullable, attr);
} else {
return creator_without_type::create_ignore_nullable<
AggregateFunctionRegrSimple<StatFunctionTemplate<T>, true, false>>(
AggregateFunctionRegrSimple<StatFunctionTemplate<TYPE_DOUBLE>, true, false>>(
argument_types, result_is_nullable, attr);
}
} else {
if (x_nullable_input) {
return creator_without_type::create_ignore_nullable<
AggregateFunctionRegrSimple<StatFunctionTemplate<T>, false, true>>(
AggregateFunctionRegrSimple<StatFunctionTemplate<TYPE_DOUBLE>, false, true>>(
argument_types, result_is_nullable, attr);
} else {
return creator_without_type::create_ignore_nullable<
AggregateFunctionRegrSimple<StatFunctionTemplate<T>, false, false>>(
AggregateFunctionRegrSimple<StatFunctionTemplate<TYPE_DOUBLE>, false, false>>(
argument_types, result_is_nullable, attr);
}
}
}

template <template <PrimitiveType> class StatFunctionTemplate>
AggregateFunctionPtr create_aggregate_function_regr(const std::string& name,
const DataTypes& argument_types,
const bool result_is_nullable,
const AggregateFunctionAttr& attr) {
if (argument_types.size() != 2) {
LOG(WARNING) << "aggregate function " << name << " requires exactly 2 arguments";
return nullptr;
}
if (!result_is_nullable) {
LOG(WARNING) << "aggregate function " << name << " requires nullable result type";
return nullptr;
}

bool y_nullable_input = argument_types[0]->is_nullable();
bool x_nullable_input = argument_types[1]->is_nullable();

if (argument_types[0]->get_primitive_type() == PrimitiveType::TYPE_BOOLEAN &&
argument_types[1]->get_primitive_type() == PrimitiveType::TYPE_BOOLEAN) {
return type_dispatch_for_aggregate_function_regr<TYPE_BOOLEAN, StatFunctionTemplate>(
argument_types, result_is_nullable, attr, y_nullable_input, x_nullable_input);
} else if (argument_types[0]->get_primitive_type() == PrimitiveType::TYPE_TINYINT &&
argument_types[1]->get_primitive_type() == PrimitiveType::TYPE_TINYINT) {
return type_dispatch_for_aggregate_function_regr<TYPE_TINYINT, StatFunctionTemplate>(
argument_types, result_is_nullable, attr, y_nullable_input, x_nullable_input);
} else if (argument_types[0]->get_primitive_type() == PrimitiveType::TYPE_SMALLINT &&
argument_types[1]->get_primitive_type() == PrimitiveType::TYPE_SMALLINT) {
return type_dispatch_for_aggregate_function_regr<TYPE_SMALLINT, StatFunctionTemplate>(
argument_types, result_is_nullable, attr, y_nullable_input, x_nullable_input);
} else if (argument_types[0]->get_primitive_type() == PrimitiveType::TYPE_INT &&
argument_types[1]->get_primitive_type() == PrimitiveType::TYPE_INT) {
return type_dispatch_for_aggregate_function_regr<TYPE_INT, StatFunctionTemplate>(
argument_types, result_is_nullable, attr, y_nullable_input, x_nullable_input);
} else if (argument_types[0]->get_primitive_type() == PrimitiveType::TYPE_BIGINT &&
argument_types[1]->get_primitive_type() == PrimitiveType::TYPE_BIGINT) {
return type_dispatch_for_aggregate_function_regr<TYPE_BIGINT, StatFunctionTemplate>(
argument_types, result_is_nullable, attr, y_nullable_input, x_nullable_input);
} else if (argument_types[0]->get_primitive_type() == PrimitiveType::TYPE_LARGEINT &&
argument_types[1]->get_primitive_type() == PrimitiveType::TYPE_LARGEINT) {
return type_dispatch_for_aggregate_function_regr<TYPE_LARGEINT, StatFunctionTemplate>(
argument_types, result_is_nullable, attr, y_nullable_input, x_nullable_input);
} else if (argument_types[0]->get_primitive_type() == PrimitiveType::TYPE_FLOAT &&
argument_types[1]->get_primitive_type() == PrimitiveType::TYPE_FLOAT) {
return type_dispatch_for_aggregate_function_regr<TYPE_FLOAT, StatFunctionTemplate>(
argument_types, result_is_nullable, attr, y_nullable_input, x_nullable_input);
} else if (argument_types[0]->get_primitive_type() == PrimitiveType::TYPE_DOUBLE &&
argument_types[1]->get_primitive_type() == PrimitiveType::TYPE_DOUBLE) {
return type_dispatch_for_aggregate_function_regr<TYPE_DOUBLE, StatFunctionTemplate>(
argument_types, result_is_nullable, attr, y_nullable_input, x_nullable_input);
} else {
LOG(WARNING) << "unsupported input types " << argument_types[0]->get_name() << " and "
<< argument_types[1]->get_name() << " for aggregate function " << name;
return nullptr;
}
}

void register_aggregate_function_regr_union(AggregateFunctionSimpleFactory& factory) {
factory.register_function_both("regr_slope", create_aggregate_function_regr<RegrSlopeFunc>);
factory.register_function_both("regr_intercept",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,6 @@ AggregateFunctionPtr create_aggregate_function_sequence_base(const std::string&
case TYPE_DATETIMEV2:
return creator_without_type::create<AggregateFunction<TYPE_DATETIMEV2>>(
argument_types, result_is_nullable, attr);
case TYPE_DATETIME:
return creator_without_type::create<AggregateFunction<TYPE_DATETIME>>(
argument_types, result_is_nullable, attr);
case TYPE_DATEV2:
return creator_without_type::create<AggregateFunction<TYPE_DATEV2>>(
argument_types, result_is_nullable, attr);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ void register_aggregate_function_combinator_foreach(AggregateFunctionSimpleFacto
void register_aggregate_function_combinator_foreachv2(AggregateFunctionSimpleFactory& factory);

void register_aggregate_function_sum(AggregateFunctionSimpleFactory& factory);
void register_aggregate_function_sum0(AggregateFunctionSimpleFactory& factory);
void register_aggregate_function_minmax(AggregateFunctionSimpleFactory& factory);
void register_aggregate_function_min_by(AggregateFunctionSimpleFactory& factory);
void register_aggregate_function_max_by(AggregateFunctionSimpleFactory& factory);
Expand Down Expand Up @@ -85,7 +84,6 @@ AggregateFunctionSimpleFactory& AggregateFunctionSimpleFactory::instance() {
static AggregateFunctionSimpleFactory instance;
std::call_once(oc, [&]() {
register_aggregate_function_sum(instance);
register_aggregate_function_sum0(instance);
register_aggregate_function_minmax(instance);
register_aggregate_function_min_by(instance);
register_aggregate_function_max_by(instance);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ inline std::string types_name(const DataTypes& types) {
return name;
}

constexpr std::string DISTINCT_FUNCTION_PREFIX = "multi_distinct_";

class AggregateFunctionSimpleFactory {
public:
using Creator = AggregateFunctionCreator;
Expand Down Expand Up @@ -164,6 +166,7 @@ class AggregateFunctionSimpleFactory {
for (const auto& s : combiner_names) {
function_alias[alias + std::string(s)] = name + std::string(s);
}
function_alias[DISTINCT_FUNCTION_PREFIX + alias] = DISTINCT_FUNCTION_PREFIX + name;
}

void register_alternative_function(const std::string& name, const Creator& creator,
Expand Down
Loading
Loading