// Copyright 2023 PingCAP, Inc. // // Licensed 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 #include #include #include #include #include namespace DB { namespace ErrorCodes { extern const int NUMBER_OF_ARGUMENTS_DOESNT_MATCH; } namespace { template < template class Data, typename Name, bool have_second_arg, typename FloatReturnType, bool returns_many> AggregateFunctionPtr createAggregateFunctionQuantile( const Context & /* context not used */, const std::string & name, const DataTypes & argument_types, const Array & params) { if (have_second_arg) assertBinary(name, argument_types); else assertUnary(name, argument_types); const DataTypePtr & argument_type = argument_types[0]; #define CREATE(TYPE) \ if (typeid_cast(argument_type.get())) \ return std::make_shared< \ AggregateFunctionQuantile, Name, have_second_arg, FloatReturnType, returns_many>>( \ argument_type, \ params); FOR_NUMERIC_TYPES(CREATE) #undef CREATE if (typeid_cast(argument_type.get())) return std::make_shared, Name, have_second_arg, void, returns_many>>(argument_type, params); if (typeid_cast(argument_type.get())) return std::make_shared, Name, have_second_arg, void, returns_many>>(argument_type, params); throw Exception( "Illegal type " + argument_type->getName() + " of argument for aggregate function " + name, ErrorCodes::ILLEGAL_TYPE_OF_ARGUMENT); } #undef FOR_NUMERIC_TYPES } // namespace void registerAggregateFunctionsQuantile(AggregateFunctionFactory & factory) { factory.registerFunction( NameQuantile::name, createAggregateFunctionQuantile); factory.registerFunction( NameQuantiles::name, createAggregateFunctionQuantile); factory.registerFunction( NameQuantileDeterministic::name, createAggregateFunctionQuantile< QuantileReservoirSamplerDeterministic, NameQuantileDeterministic, true, Float64, false>); factory.registerFunction( NameQuantilesDeterministic::name, createAggregateFunctionQuantile< QuantileReservoirSamplerDeterministic, NameQuantilesDeterministic, true, Float64, true>); factory.registerFunction( NameQuantileExact::name, createAggregateFunctionQuantile); factory.registerFunction( NameQuantilesExact::name, createAggregateFunctionQuantile); factory.registerFunction( NameQuantileExactWeighted::name, createAggregateFunctionQuantile); factory.registerFunction( NameQuantilesExactWeighted::name, createAggregateFunctionQuantile); factory.registerFunction( NameQuantileTiming::name, createAggregateFunctionQuantile); factory.registerFunction( NameQuantilesTiming::name, createAggregateFunctionQuantile); factory.registerFunction( NameQuantileTimingWeighted::name, createAggregateFunctionQuantile); factory.registerFunction( NameQuantilesTimingWeighted::name, createAggregateFunctionQuantile); factory.registerFunction( NameQuantileTDigest::name, createAggregateFunctionQuantile); factory.registerFunction( NameQuantilesTDigest::name, createAggregateFunctionQuantile); factory.registerFunction( NameQuantileTDigestWeighted::name, createAggregateFunctionQuantile); factory.registerFunction( NameQuantilesTDigestWeighted::name, createAggregateFunctionQuantile); /// 'median' is an alias for 'quantile' factory.registerFunction( "median", createAggregateFunctionQuantile); factory.registerFunction( "medianDeterministic", createAggregateFunctionQuantile< QuantileReservoirSamplerDeterministic, NameQuantileDeterministic, true, Float64, false>); factory.registerFunction( "medianExact", createAggregateFunctionQuantile); factory.registerFunction( "medianExactWeighted", createAggregateFunctionQuantile); factory.registerFunction( "medianTiming", createAggregateFunctionQuantile); factory.registerFunction( "medianTimingWeighted", createAggregateFunctionQuantile); factory.registerFunction( "medianTDigest", createAggregateFunctionQuantile); factory.registerFunction( "medianTDigestWeighted", createAggregateFunctionQuantile); } } // namespace DB