// 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 namespace DB { extern const String count_second_stage = NameCountSecondStage::name; extern const String sum_on_partial_result = NameSumOnPartialResult::name; namespace { template using AggregateFunctionSumSimple = AggregateFunctionSum< T, typename NearestFieldType::Type, AggregateFunctionSumData::Type>>; template using AggregateFunctionCountSecondStage = AggregateFunctionSum< T, typename NearestFieldType::Type, AggregateFunctionSumData::Type>, NameCountSecondStage>; template using AggregateFunctionSumDecimal = AggregateFunctionSum, SumName>; template using AggregateFunctionSumWithOverflow = AggregateFunctionSum, NameSumWithOverFlow>; template using AggregateFunctionSumOnPartialResultStage = AggregateFunctionSumWithOverflow; template using AggregateFunctionSumKahan = AggregateFunctionSum, NameSumKahan>; template AggregateFunctionPtr createDecimalFunction(const IDataType * p) { if (auto dec_type = typeid_cast *>(p)) { PrecType prec = dec_type->getPrec(); ScaleType scale = dec_type->getScale(); auto [result_prec, result_scale] = Name::decimalInfer(prec, scale); auto result_type = createDecimal(result_prec, result_scale); if (checkDecimal(*result_type)) return AggregateFunctionPtr( createSumAggWithDecimalType(*dec_type, prec, scale)); if (checkDecimal(*result_type)) return AggregateFunctionPtr( createSumAggWithDecimalType(*dec_type, prec, scale)); if (checkDecimal(*result_type)) return AggregateFunctionPtr( createSumAggWithDecimalType(*dec_type, prec, scale)); if (checkDecimal(*result_type)) return AggregateFunctionPtr( createSumAggWithDecimalType(*dec_type, prec, scale)); } return nullptr; } template