Skip to content

Commit

Permalink
[UDAF]Add max/min UDAF (apache#8)
Browse files Browse the repository at this point in the history
* 1 add max UDAF for integer type
2 fix coredump when calls a unimplemented UDAF

* support serialize for min/max
  • Loading branch information
wangbo authored and HappenLee committed Jul 1, 2021
1 parent 19d0370 commit c1d2664
Show file tree
Hide file tree
Showing 4 changed files with 718 additions and 2 deletions.
1 change: 1 addition & 0 deletions be/src/vec/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ set(VEC_FILES
aggregate_functions/aggregate_function_count.cpp
aggregate_functions/aggregate_function_null.cpp
aggregate_functions/aggregate_function_sum.cpp
aggregate_functions/aggregate_function_min_max.cpp
columns/collator.cpp
columns/column.cpp
columns/column_const.cpp
Expand Down
72 changes: 72 additions & 0 deletions be/src/vec/aggregate_functions/aggregate_function_min_max.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
// 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.h"
#include <vec/aggregate_functions/factory_helpers.h>
#include "vec/aggregate_functions/aggregate_function_simple_factory.h"
#include <vec/aggregate_functions/helpers.h>

namespace doris::vectorized {

namespace {

/// min, max
template <template <typename, bool> class AggregateFunctionTemplate, template <typename> class Data>
static IAggregateFunction * createAggregateFunctionSingleValue(const String & name, const DataTypes & argument_types, const Array & parameters)
{
assertNoParameters(name, parameters);
assertUnary(name, argument_types);

const DataTypePtr & argument_type = argument_types[0];

WhichDataType which(argument_type);
#define DISPATCH(TYPE) \
if (which.idx == TypeIndex::TYPE) return new AggregateFunctionTemplate<Data<SingleValueDataFixed<TYPE>>, false>(argument_type);
FOR_NUMERIC_TYPES(DISPATCH)
#undef DISPATCH

// if (which.idx == TypeIndex::Date)
// return new AggregateFunctionTemplate<Data<SingleValueDataFixed<DataTypeDate::FieldType>>, false>(argument_type);
// if (which.idx == TypeIndex::DateTime)
// return new AggregateFunctionTemplate<Data<SingleValueDataFixed<DataTypeDateTime::FieldType>>, false>(argument_type);
// if (which.idx == TypeIndex::String)
// return new AggregateFunctionTemplate<Data<SingleValueDataString>, true>(argument_type);

// return new AggregateFunctionTemplate<Data<SingleValueDataGeneric>, false>(argument_type);
return nullptr;
}

AggregateFunctionPtr createAggregateFunctionMax(const std::string & name, const DataTypes & argument_types, const Array & parameters)
{
return AggregateFunctionPtr(createAggregateFunctionSingleValue<AggregateFunctionsSingleValue, AggregateFunctionMaxData>(name, argument_types, parameters));
}

AggregateFunctionPtr createAggregateFunctionMin(const std::string & name, const DataTypes & argument_types, const Array & parameters)
{
return AggregateFunctionPtr(createAggregateFunctionSingleValue<AggregateFunctionsSingleValue, AggregateFunctionMinData>(name, argument_types, parameters));
}

} // namespace

void registerAggregateFunctionMinMax(AggregateFunctionSimpleFactory& factory) {
factory.registerFunction("max", createAggregateFunctionMax);
factory.registerFunction("max", createAggregateFunctionMax, true);
factory.registerFunction("min", createAggregateFunctionMin);
factory.registerFunction("min", createAggregateFunctionMin, true);
}

} // namespace doris::vectorized
Loading

0 comments on commit c1d2664

Please sign in to comment.