// 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 { /// Substitute return type for Date and DateTime class AggregateFunctionGroupUniqArrayDate : public AggregateFunctionGroupUniqArray { DataTypePtr getReturnType() const override { return std::make_shared(std::make_shared()); } }; class AggregateFunctionGroupUniqArrayDateTime : public AggregateFunctionGroupUniqArray { DataTypePtr getReturnType() const override { return std::make_shared(std::make_shared()); } }; IAggregateFunction * createWithExtraTypes(const DataTypePtr & argument_type) { if (typeid_cast(argument_type.get())) return new AggregateFunctionGroupUniqArrayDate; else if (typeid_cast(argument_type.get())) return new AggregateFunctionGroupUniqArrayDateTime; else { /// Check that we can use plain version of AggregateFunctionGroupUniqArrayGeneric if (argument_type->isValueUnambiguouslyRepresentedInContiguousMemoryRegion()) return new AggregateFunctionGroupUniqArrayGeneric(argument_type); else return new AggregateFunctionGroupUniqArrayGeneric(argument_type); } } AggregateFunctionPtr createAggregateFunctionGroupUniqArray( const Context & /* context not used */, const std::string & name, const DataTypes & argument_types, const Array & parameters) { assertNoParameters(name, parameters); assertUnary(name, argument_types); AggregateFunctionPtr res(createWithNumericType(*argument_types[0])); if (!res) res = AggregateFunctionPtr(createWithExtraTypes(argument_types[0])); if (!res) throw Exception( "Illegal type " + argument_types[0]->getName() + " of argument for aggregate function " + name, ErrorCodes::ILLEGAL_TYPE_OF_ARGUMENT); return res; } } // namespace void registerAggregateFunctionGroupUniqArray(AggregateFunctionFactory & factory) { factory.registerFunction("groupUniqArray", createAggregateFunctionGroupUniqArray); } } // namespace DB