mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-24 08:32:02 +00:00
70d1adfe4b
* save format string for NetException * format exceptions * format exceptions 2 * format exceptions 3 * format exceptions 4 * format exceptions 5 * format exceptions 6 * fix * format exceptions 7 * format exceptions 8 * Update MergeTreeIndexGin.cpp * Update AggregateFunctionMap.cpp * Update AggregateFunctionMap.cpp * fix
58 lines
2.4 KiB
C++
58 lines
2.4 KiB
C++
#include <AggregateFunctions/AggregateFunctionQuantile.h>
|
|
#include <AggregateFunctions/QuantileExact.h>
|
|
#include <AggregateFunctions/AggregateFunctionFactory.h>
|
|
#include <AggregateFunctions/Helpers.h>
|
|
#include <DataTypes/DataTypeDate.h>
|
|
#include <DataTypes/DataTypeDateTime.h>
|
|
#include <Core/Field.h>
|
|
|
|
|
|
namespace DB
|
|
{
|
|
struct Settings;
|
|
|
|
namespace ErrorCodes
|
|
{
|
|
extern const int ILLEGAL_TYPE_OF_ARGUMENT;
|
|
}
|
|
|
|
namespace
|
|
{
|
|
|
|
template <typename Value, bool _> using FuncQuantileExactInclusive = AggregateFunctionQuantile<Value, QuantileExactInclusive<Value>, NameQuantileExactInclusive, false, Float64, false>;
|
|
template <typename Value, bool _> using FuncQuantilesExactInclusive = AggregateFunctionQuantile<Value, QuantileExactInclusive<Value>, NameQuantilesExactInclusive, false, Float64, true>;
|
|
|
|
template <template <typename, bool> class Function>
|
|
AggregateFunctionPtr createAggregateFunctionQuantile(
|
|
const std::string & name, const DataTypes & argument_types, const Array & params, const Settings *)
|
|
{
|
|
/// Second argument type check doesn't depend on the type of the first one.
|
|
Function<void, true>::assertSecondArg(argument_types);
|
|
|
|
const DataTypePtr & argument_type = argument_types[0];
|
|
WhichDataType which(argument_type);
|
|
|
|
#define DISPATCH(TYPE) \
|
|
if (which.idx == TypeIndex::TYPE) return std::make_shared<Function<TYPE, true>>(argument_types, params);
|
|
FOR_BASIC_NUMERIC_TYPES(DISPATCH)
|
|
#undef DISPATCH
|
|
if (which.idx == TypeIndex::Date) return std::make_shared<Function<DataTypeDate::FieldType, false>>(argument_types, params);
|
|
if (which.idx == TypeIndex::DateTime) return std::make_shared<Function<DataTypeDateTime::FieldType, false>>(argument_types, params);
|
|
|
|
throw Exception(ErrorCodes::ILLEGAL_TYPE_OF_ARGUMENT, "Illegal type {} of argument for aggregate function {}",
|
|
argument_type->getName(), name);
|
|
}
|
|
|
|
}
|
|
|
|
void registerAggregateFunctionsQuantileExactInclusive(AggregateFunctionFactory & factory)
|
|
{
|
|
/// For aggregate functions returning array we cannot return NULL on empty set.
|
|
AggregateFunctionProperties properties = { .returns_default_when_only_null = true };
|
|
|
|
factory.registerFunction(NameQuantileExactInclusive::name, createAggregateFunctionQuantile<FuncQuantileExactInclusive>);
|
|
factory.registerFunction(NameQuantilesExactInclusive::name, { createAggregateFunctionQuantile<FuncQuantilesExactInclusive>, properties });
|
|
}
|
|
|
|
}
|