[Chore](build) enchancement for backend build time usage (#18344)

This commit is contained in:
Pxl
2023-04-06 11:13:21 +08:00
committed by GitHub
parent 4ca0c0face
commit 76d76f672c
21 changed files with 193 additions and 414 deletions

View File

@ -30,7 +30,8 @@ set(VEC_FILES
aggregate_functions/aggregate_function_sum.cpp
aggregate_functions/aggregate_function_sort.cpp
aggregate_functions/aggregate_function_min_max.cpp
aggregate_functions/aggregate_function_min_max_by.cpp
aggregate_functions/aggregate_function_min_by.cpp
aggregate_functions/aggregate_function_max_by.cpp
aggregate_functions/aggregate_function_uniq.cpp
aggregate_functions/aggregate_function_hll_union_agg.cpp
aggregate_functions/aggregate_function_bit.cpp

View File

@ -0,0 +1,29 @@
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.
#include "vec/aggregate_functions/aggregate_function_min_max_by.h"
#include "vec/aggregate_functions/aggregate_function_simple_factory.h"
namespace doris::vectorized {
void register_aggregate_function_max_by(AggregateFunctionSimpleFactory& factory) {
factory.register_function_both(
"max_by", create_aggregate_function_min_max_by<AggregateFunctionsMinMaxBy,
AggregateFunctionMaxByData>);
}
} // namespace doris::vectorized

View File

@ -0,0 +1,29 @@
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.
#include "vec/aggregate_functions/aggregate_function_min_max_by.h"
#include "vec/aggregate_functions/aggregate_function_simple_factory.h"
namespace doris::vectorized {
void register_aggregate_function_min_by(AggregateFunctionSimpleFactory& factory) {
factory.register_function_both(
"min_by", create_aggregate_function_min_max_by<AggregateFunctionsMinMaxBy,
AggregateFunctionMinByData>);
}
} // namespace doris::vectorized

View File

@ -447,12 +447,10 @@ struct AggregateFunctionMaxData : public Data {
using Self = AggregateFunctionMaxData;
using Data::IsFixedLength;
bool change_if_better(const IColumn& column, size_t row_num, Arena* arena) {
return this->change_if_greater(column, row_num, arena);
}
bool change_if_better(const Self& to, Arena* arena) {
return this->change_if_greater(to, arena);
void change_if_better(const IColumn& column, size_t row_num, Arena* arena) {
this->change_if_greater(column, row_num, arena);
}
void change_if_better(const Self& to, Arena* arena) { this->change_if_greater(to, arena); }
static const char* name() { return "max"; }
};
@ -462,10 +460,10 @@ struct AggregateFunctionMinData : Data {
using Self = AggregateFunctionMinData;
using Data::IsFixedLength;
bool change_if_better(const IColumn& column, size_t row_num, Arena* arena) {
return this->change_if_less(column, row_num, arena);
void change_if_better(const IColumn& column, size_t row_num, Arena* arena) {
this->change_if_less(column, row_num, arena);
}
bool change_if_better(const Self& to, Arena* arena) { return this->change_if_less(to, arena); }
void change_if_better(const Self& to, Arena* arena) { this->change_if_less(to, arena); }
static const char* name() { return "min"; }
};
@ -475,12 +473,10 @@ struct AggregateFunctionAnyData : Data {
using Self = AggregateFunctionAnyData;
using Data::IsFixedLength;
bool change_if_better(const IColumn& column, size_t row_num, Arena* arena) {
return this->change_first_time(column, row_num, arena);
}
bool change_if_better(const Self& to, Arena* arena) {
return this->change_first_time(to, arena);
void change_if_better(const IColumn& column, size_t row_num, Arena* arena) {
this->change_first_time(column, row_num, arena);
}
void change_if_better(const Self& to, Arena* arena) { this->change_first_time(to, arena); }
static const char* name() { return "any"; }
};

View File

@ -1,131 +0,0 @@
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.
#include "vec/aggregate_functions/aggregate_function_min_max_by.h"
#include "vec/aggregate_functions/aggregate_function_min_max.h"
#include "vec/aggregate_functions/aggregate_function_simple_factory.h"
#include "vec/aggregate_functions/factory_helpers.h"
#include "vec/aggregate_functions/helpers.h"
#include "vec/core/types.h"
namespace doris::vectorized {
/// min_by, max_by
template <template <typename> class AggregateFunctionTemplate,
template <typename, typename> class Data, typename VT>
AggregateFunctionPtr create_aggregate_function_min_max_by_impl(const DataTypes& argument_types,
const bool result_is_nullable) {
WhichDataType which(remove_nullable(argument_types[1]));
#define DISPATCH(TYPE) \
if (which.idx == TypeIndex::TYPE) \
return creator_without_type::create< \
AggregateFunctionTemplate<Data<VT, SingleValueDataFixed<TYPE>>>>( \
argument_types, result_is_nullable);
FOR_NUMERIC_TYPES(DISPATCH)
#undef DISPATCH
#define DISPATCH(TYPE) \
if (which.idx == TypeIndex::TYPE) \
return creator_without_type::create< \
AggregateFunctionTemplate<Data<VT, SingleValueDataDecimal<TYPE>>>>( \
argument_types, result_is_nullable);
FOR_DECIMAL_TYPES(DISPATCH)
#undef DISPATCH
if (which.idx == TypeIndex::String) {
return creator_without_type::create<
AggregateFunctionTemplate<Data<VT, SingleValueDataString>>>(argument_types,
result_is_nullable);
}
if (which.idx == TypeIndex::DateTime || which.idx == TypeIndex::Date) {
return creator_without_type::create<
AggregateFunctionTemplate<Data<VT, SingleValueDataFixed<Int64>>>>(
argument_types, result_is_nullable);
}
if (which.idx == TypeIndex::DateV2) {
return creator_without_type::create<
AggregateFunctionTemplate<Data<VT, SingleValueDataFixed<UInt32>>>>(
argument_types, result_is_nullable);
}
if (which.idx == TypeIndex::DateTimeV2) {
return creator_without_type::create<
AggregateFunctionTemplate<Data<VT, SingleValueDataFixed<UInt64>>>>(
argument_types, result_is_nullable);
}
return nullptr;
}
/// min_by, max_by
template <template <typename> class AggregateFunctionTemplate,
template <typename, typename> class Data>
AggregateFunctionPtr create_aggregate_function_min_max_by(const String& name,
const DataTypes& argument_types,
const bool result_is_nullable) {
assert_binary(name, argument_types);
WhichDataType which(remove_nullable(argument_types[0]));
#define DISPATCH(TYPE) \
if (which.idx == TypeIndex::TYPE) \
return create_aggregate_function_min_max_by_impl<AggregateFunctionTemplate, Data, \
SingleValueDataFixed<TYPE>>( \
argument_types, result_is_nullable);
FOR_NUMERIC_TYPES(DISPATCH)
#undef DISPATCH
#define DISPATCH(TYPE) \
if (which.idx == TypeIndex::TYPE) \
return create_aggregate_function_min_max_by_impl<AggregateFunctionTemplate, Data, \
SingleValueDataDecimal<TYPE>>( \
argument_types, result_is_nullable);
FOR_DECIMAL_TYPES(DISPATCH)
#undef DISPATCH
if (which.idx == TypeIndex::String) {
return create_aggregate_function_min_max_by_impl<AggregateFunctionTemplate, Data,
SingleValueDataString>(argument_types,
result_is_nullable);
}
if (which.idx == TypeIndex::DateTime || which.idx == TypeIndex::Date) {
return create_aggregate_function_min_max_by_impl<AggregateFunctionTemplate, Data,
SingleValueDataFixed<Int64>>(
argument_types, result_is_nullable);
}
if (which.idx == TypeIndex::DateV2) {
return create_aggregate_function_min_max_by_impl<AggregateFunctionTemplate, Data,
SingleValueDataFixed<UInt32>>(
argument_types, result_is_nullable);
}
if (which.idx == TypeIndex::DateTimeV2) {
return create_aggregate_function_min_max_by_impl<AggregateFunctionTemplate, Data,
SingleValueDataFixed<UInt64>>(
argument_types, result_is_nullable);
}
return nullptr;
}
void register_aggregate_function_min_max_by(AggregateFunctionSimpleFactory& factory) {
factory.register_function_both(
"max_by", create_aggregate_function_min_max_by<AggregateFunctionsMinMaxBy,
AggregateFunctionMaxByData>);
factory.register_function_both(
"min_by", create_aggregate_function_min_max_by<AggregateFunctionsMinMaxBy,
AggregateFunctionMinByData>);
}
} // namespace doris::vectorized

View File

@ -19,6 +19,8 @@
#include "common/logging.h"
#include "vec/aggregate_functions/aggregate_function.h"
#include "vec/aggregate_functions/aggregate_function_min_max.h"
#include "vec/aggregate_functions/helpers.h"
#include "vec/columns/column_decimal.h"
#include "vec/columns/column_vector.h"
#include "vec/common/assert_cast.h"
@ -52,21 +54,17 @@ public:
template <typename VT, typename KT>
struct AggregateFunctionMaxByData : public AggregateFunctionMinMaxByBaseData<VT, KT> {
using Self = AggregateFunctionMaxByData;
bool change_if_better(const IColumn& value_column, const IColumn& key_column, size_t row_num,
void change_if_better(const IColumn& value_column, const IColumn& key_column, size_t row_num,
Arena* arena) {
if (this->key.change_if_greater(key_column, row_num, arena)) {
this->value.change(value_column, row_num, arena);
return true;
}
return false;
}
bool change_if_better(const Self& to, Arena* arena) {
void change_if_better(const Self& to, Arena* arena) {
if (this->key.change_if_greater(to.key, arena)) {
this->value.change(to.value, arena);
return true;
}
return false;
}
static const char* name() { return "max_by"; }
@ -75,21 +73,17 @@ struct AggregateFunctionMaxByData : public AggregateFunctionMinMaxByBaseData<VT,
template <typename VT, typename KT>
struct AggregateFunctionMinByData : public AggregateFunctionMinMaxByBaseData<VT, KT> {
using Self = AggregateFunctionMinByData;
bool change_if_better(const IColumn& value_column, const IColumn& key_column, size_t row_num,
void change_if_better(const IColumn& value_column, const IColumn& key_column, size_t row_num,
Arena* arena) {
if (this->key.change_if_less(key_column, row_num, arena)) {
this->value.change(value_column, row_num, arena);
return true;
}
return false;
}
bool change_if_better(const Self& to, Arena* arena) {
void change_if_better(const Self& to, Arena* arena) {
if (this->key.change_if_less(to.key, arena)) {
this->value.change(to.value, arena);
return true;
}
return false;
}
static const char* name() { return "min_by"; }
@ -144,12 +138,94 @@ public:
}
};
AggregateFunctionPtr create_aggregate_function_max_by(const std::string& name,
const DataTypes& argument_types,
const bool result_is_nullable);
template <template <typename> class AggregateFunctionTemplate,
template <typename, typename> class Data, typename VT>
AggregateFunctionPtr create_aggregate_function_min_max_by_impl(const DataTypes& argument_types,
const bool result_is_nullable) {
WhichDataType which(remove_nullable(argument_types[1]));
AggregateFunctionPtr create_aggregate_function_min_by(const std::string& name,
const DataTypes& argument_types,
const bool result_is_nullable);
#define DISPATCH(TYPE) \
if (which.idx == TypeIndex::TYPE) \
return creator_without_type::create< \
AggregateFunctionTemplate<Data<VT, SingleValueDataFixed<TYPE>>>>( \
argument_types, result_is_nullable);
FOR_NUMERIC_TYPES(DISPATCH)
#undef DISPATCH
#define DISPATCH(TYPE) \
if (which.idx == TypeIndex::TYPE) \
return creator_without_type::create< \
AggregateFunctionTemplate<Data<VT, SingleValueDataDecimal<TYPE>>>>( \
argument_types, result_is_nullable);
FOR_DECIMAL_TYPES(DISPATCH)
#undef DISPATCH
if (which.idx == TypeIndex::String) {
return creator_without_type::create<
AggregateFunctionTemplate<Data<VT, SingleValueDataString>>>(argument_types,
result_is_nullable);
}
if (which.idx == TypeIndex::DateTime || which.idx == TypeIndex::Date) {
return creator_without_type::create<
AggregateFunctionTemplate<Data<VT, SingleValueDataFixed<Int64>>>>(
argument_types, result_is_nullable);
}
if (which.idx == TypeIndex::DateV2) {
return creator_without_type::create<
AggregateFunctionTemplate<Data<VT, SingleValueDataFixed<UInt32>>>>(
argument_types, result_is_nullable);
}
if (which.idx == TypeIndex::DateTimeV2) {
return creator_without_type::create<
AggregateFunctionTemplate<Data<VT, SingleValueDataFixed<UInt64>>>>(
argument_types, result_is_nullable);
}
return nullptr;
}
template <template <typename> class AggregateFunctionTemplate,
template <typename, typename> class Data>
AggregateFunctionPtr create_aggregate_function_min_max_by(const String& name,
const DataTypes& argument_types,
const bool result_is_nullable) {
WhichDataType which(remove_nullable(argument_types[0]));
#define DISPATCH(TYPE) \
if (which.idx == TypeIndex::TYPE) \
return create_aggregate_function_min_max_by_impl<AggregateFunctionTemplate, Data, \
SingleValueDataFixed<TYPE>>( \
argument_types, result_is_nullable);
FOR_NUMERIC_TYPES(DISPATCH)
#undef DISPATCH
#define DISPATCH(TYPE) \
if (which.idx == TypeIndex::TYPE) \
return create_aggregate_function_min_max_by_impl<AggregateFunctionTemplate, Data, \
SingleValueDataDecimal<TYPE>>( \
argument_types, result_is_nullable);
FOR_DECIMAL_TYPES(DISPATCH)
#undef DISPATCH
if (which.idx == TypeIndex::String) {
return create_aggregate_function_min_max_by_impl<AggregateFunctionTemplate, Data,
SingleValueDataString>(argument_types,
result_is_nullable);
}
if (which.idx == TypeIndex::DateTime || which.idx == TypeIndex::Date) {
return create_aggregate_function_min_max_by_impl<AggregateFunctionTemplate, Data,
SingleValueDataFixed<Int64>>(
argument_types, result_is_nullable);
}
if (which.idx == TypeIndex::DateV2) {
return create_aggregate_function_min_max_by_impl<AggregateFunctionTemplate, Data,
SingleValueDataFixed<UInt32>>(
argument_types, result_is_nullable);
}
if (which.idx == TypeIndex::DateTimeV2) {
return create_aggregate_function_min_max_by_impl<AggregateFunctionTemplate, Data,
SingleValueDataFixed<UInt64>>(
argument_types, result_is_nullable);
}
return nullptr;
}
} // namespace doris::vectorized

View File

@ -31,7 +31,8 @@ void register_aggregate_function_combinator_distinct(AggregateFunctionSimpleFact
void register_aggregate_function_sum(AggregateFunctionSimpleFactory& factory);
void register_aggregate_function_minmax(AggregateFunctionSimpleFactory& factory);
void register_aggregate_function_min_max_by(AggregateFunctionSimpleFactory& factory);
void register_aggregate_function_min_by(AggregateFunctionSimpleFactory& factory);
void register_aggregate_function_max_by(AggregateFunctionSimpleFactory& factory);
void register_aggregate_function_avg(AggregateFunctionSimpleFactory& factory);
void register_aggregate_function_count(AggregateFunctionSimpleFactory& factory);
void register_aggregate_function_HLL_union_agg(AggregateFunctionSimpleFactory& factory);
@ -63,7 +64,8 @@ AggregateFunctionSimpleFactory& AggregateFunctionSimpleFactory::instance() {
std::call_once(oc, [&]() {
register_aggregate_function_sum(instance);
register_aggregate_function_minmax(instance);
register_aggregate_function_min_max_by(instance);
register_aggregate_function_min_by(instance);
register_aggregate_function_max_by(instance);
register_aggregate_function_avg(instance);
register_aggregate_function_count(instance);
register_aggregate_function_uniq(instance);

View File

@ -89,10 +89,6 @@ using FunctionDatetimeV2SubYears =
FUNCTION_DATEV2_WITH_TWO_ARGS(NAME, IMPL, DataTypeDateTimeV2, DataTypeDateTimeV2) \
FUNCTION_DATEV2_WITH_TWO_ARGS(NAME, IMPL, DataTypeDateTimeV2, DataTypeDateV2) \
FUNCTION_DATEV2_WITH_TWO_ARGS(NAME, IMPL, DataTypeDateV2, DataTypeDateTimeV2) \
FUNCTION_DATEV2_WITH_TWO_ARGS(NAME, IMPL, DataTypeDateTimeV2, DataTypeDateTime) \
FUNCTION_DATEV2_WITH_TWO_ARGS(NAME, IMPL, DataTypeDateTime, DataTypeDateTimeV2) \
FUNCTION_DATEV2_WITH_TWO_ARGS(NAME, IMPL, DataTypeDateTime, DataTypeDateV2) \
FUNCTION_DATEV2_WITH_TWO_ARGS(NAME, IMPL, DataTypeDateV2, DataTypeDateTime) \
FUNCTION_DATEV2_WITH_TWO_ARGS(NAME, IMPL, DataTypeDateV2, DataTypeDateV2)
ALL_FUNCTION_DATEV2_WITH_TWO_ARGS(FunctionDatetimeV2DateDiff, DateDiffImpl)
@ -156,11 +152,7 @@ void register_function_date_time_computation_v2(SimpleFunctionFactory& factory)
REGISTER_DATEV2_FUNCTIONS_WITH_TWO_ARGS(NAME, DataTypeDateTimeV2, DataTypeDateTimeV2) \
REGISTER_DATEV2_FUNCTIONS_WITH_TWO_ARGS(NAME, DataTypeDateTimeV2, DataTypeDateV2) \
REGISTER_DATEV2_FUNCTIONS_WITH_TWO_ARGS(NAME, DataTypeDateV2, DataTypeDateTimeV2) \
REGISTER_DATEV2_FUNCTIONS_WITH_TWO_ARGS(NAME, DataTypeDateTimeV2, DataTypeDateTime) \
REGISTER_DATEV2_FUNCTIONS_WITH_TWO_ARGS(NAME, DataTypeDateV2, DataTypeDateTime) \
REGISTER_DATEV2_FUNCTIONS_WITH_TWO_ARGS(NAME, DataTypeDateV2, DataTypeDateV2) \
REGISTER_DATEV2_FUNCTIONS_WITH_TWO_ARGS(NAME, DataTypeDateTime, DataTypeDateV2) \
REGISTER_DATEV2_FUNCTIONS_WITH_TWO_ARGS(NAME, DataTypeDateTime, DataTypeDateTimeV2)
REGISTER_DATEV2_FUNCTIONS_WITH_TWO_ARGS(NAME, DataTypeDateV2, DataTypeDateV2)
REGISTER_ALL_DATEV2_FUNCTIONS_WITH_TWO_ARGS(FunctionDatetimeV2DateDiff)
REGISTER_ALL_DATEV2_FUNCTIONS_WITH_TWO_ARGS(FunctionDatetimeV2TimeDiff)