#include #include #include #include #include namespace DB { struct Settings; namespace ErrorCodes { extern const int ILLEGAL_TYPE_OF_ARGUMENT; } namespace { bool allowType(const DataTypePtr& type) noexcept { const WhichDataType t(type); return t.isInt() || t.isUInt() || t.isFloat() || t.isDecimal(); } AggregateFunctionPtr createAggregateFunctionAvg(const std::string & name, const DataTypes & argument_types, const Array & parameters, const Settings *) { assertNoParameters(name, parameters); assertUnary(name, argument_types); const DataTypePtr& data_type = argument_types[0]; if (!allowType(data_type)) throw Exception(ErrorCodes::ILLEGAL_TYPE_OF_ARGUMENT, "Illegal type {} of argument for aggregate function {}", data_type->getName(), name); AggregateFunctionPtr res; if (isDecimal(data_type)) res.reset(createWithDecimalType( *data_type, argument_types, getDecimalScale(*data_type))); else res.reset(createWithNumericType(*data_type, argument_types)); return res; } } void registerAggregateFunctionAvg(AggregateFunctionFactory & factory) { factory.registerFunction("avg", createAggregateFunctionAvg, AggregateFunctionFactory::CaseInsensitive); } }