1#pragma once
2
3#include <AggregateFunctions/IAggregateFunction.h>
4
5#include <DataTypes/IDataType.h>
6
7
8namespace DB
9{
10
11/** Type - the state of the aggregate function.
12 * Type parameters is an aggregate function, the types of its arguments, and its parameters (for parametric aggregate functions).
13 */
14class DataTypeAggregateFunction final : public IDataType
15{
16private:
17 AggregateFunctionPtr function;
18 DataTypes argument_types;
19 Array parameters;
20
21public:
22 static constexpr bool is_parametric = true;
23
24 DataTypeAggregateFunction(const AggregateFunctionPtr & function_, const DataTypes & argument_types_, const Array & parameters_)
25 : function(function_), argument_types(argument_types_), parameters(parameters_)
26 {
27 }
28
29 std::string getFunctionName() const { return function->getName(); }
30 AggregateFunctionPtr getFunction() const { return function; }
31
32 std::string doGetName() const override;
33 const char * getFamilyName() const override { return "AggregateFunction"; }
34 TypeIndex getTypeId() const override { return TypeIndex::AggregateFunction; }
35
36 bool canBeInsideNullable() const override { return false; }
37
38 DataTypePtr getReturnType() const { return function->getReturnType(); }
39 DataTypePtr getReturnTypeToPredict() const { return function->getReturnTypeToPredict(); }
40 DataTypes getArgumentsDataTypes() const { return argument_types; }
41
42 /// NOTE These two functions for serializing single values are incompatible with the functions below.
43 void serializeBinary(const Field & field, WriteBuffer & ostr) const override;
44 void deserializeBinary(Field & field, ReadBuffer & istr) const override;
45
46 void serializeBinary(const IColumn & column, size_t row_num, WriteBuffer & ostr) const override;
47 void deserializeBinary(IColumn & column, ReadBuffer & istr) const override;
48 void serializeBinaryBulk(const IColumn & column, WriteBuffer & ostr, size_t offset, size_t limit) const override;
49 void deserializeBinaryBulk(IColumn & column, ReadBuffer & istr, size_t limit, double avg_value_size_hint) const override;
50 void serializeText(const IColumn & column, size_t row_num, WriteBuffer & ostr, const FormatSettings &) const override;
51 void serializeTextEscaped(const IColumn & column, size_t row_num, WriteBuffer & ostr, const FormatSettings &) const override;
52 void deserializeTextEscaped(IColumn & column, ReadBuffer & istr, const FormatSettings &) const override;
53 void serializeTextQuoted(const IColumn & column, size_t row_num, WriteBuffer & ostr, const FormatSettings &) const override;
54 void deserializeTextQuoted(IColumn & column, ReadBuffer & istr, const FormatSettings &) const override;
55 void deserializeWholeText(IColumn & column, ReadBuffer & istr, const FormatSettings &) const override;
56
57 void serializeTextJSON(const IColumn & column, size_t row_num, WriteBuffer & ostr, const FormatSettings &) const override;
58 void deserializeTextJSON(IColumn & column, ReadBuffer & istr, const FormatSettings &) const override;
59 void serializeTextXML(const IColumn & column, size_t row_num, WriteBuffer & ostr, const FormatSettings &) const override;
60 void serializeTextCSV(const IColumn & column, size_t row_num, WriteBuffer & ostr, const FormatSettings &) const override;
61 void deserializeTextCSV(IColumn & column, ReadBuffer & istr, const FormatSettings & settings) const override;
62 void serializeProtobuf(const IColumn & column, size_t row_num, ProtobufWriter & protobuf, size_t & value_index) const override;
63 void deserializeProtobuf(IColumn & column, ProtobufReader & protobuf, bool allow_add_row, bool & row_added) const override;
64
65 MutableColumnPtr createColumn() const override;
66
67 Field getDefault() const override;
68
69 bool equals(const IDataType & rhs) const override;
70
71 bool isParametric() const override { return true; }
72 bool haveSubtypes() const override { return false; }
73 bool shouldAlignRightInPrettyFormats() const override { return false; }
74};
75
76
77}
78
79