MCPcopy Create free account
hub / github.com/ClickHouse/ClickHouse / create

Function create

src/DataTypes/DataTypeCustomSimpleAggregateFunction.cpp:91–169  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

89
90
91static std::pair<DataTypePtr, DataTypeCustomDescPtr> create(const ASTPtr & arguments)
92{
93 String function_name;
94 AggregateFunctionPtr function;
95 DataTypes argument_types;
96 Array params_row;
97
98 if (!arguments || arguments->children.empty())
99 throw Exception(ErrorCodes::NUMBER_OF_ARGUMENTS_DOESNT_MATCH,
100 "Data type SimpleAggregateFunction requires parameters: "
101 "name of aggregate function and list of data types for arguments");
102
103 if (const ASTFunction * parametric = arguments->children[0]->as<ASTFunction>())
104 {
105 if (parametric->parameters)
106 throw Exception(ErrorCodes::SYNTAX_ERROR, "Unexpected level of parameters to aggregate function");
107 function_name = parametric->name;
108
109 if (parametric->arguments)
110 {
111 const ASTs & parameters = parametric->arguments->as<ASTExpressionList &>().children;
112 params_row.resize(parameters.size());
113
114 for (size_t i = 0; i < parameters.size(); ++i)
115 {
116 const ASTLiteral * lit = parameters[i]->as<ASTLiteral>();
117 if (!lit)
118 throw Exception(
119 ErrorCodes::PARAMETERS_TO_AGGREGATE_FUNCTIONS_MUST_BE_LITERALS,
120 "Parameters to aggregate functions must be literals. "
121 "Got parameter '{}' for function '{}'",
122 parameters[i]->formatForErrorMessage(),
123 function_name);
124
125 params_row[i] = lit->value;
126 }
127 }
128 }
129 else if (auto opt_name = tryGetIdentifierName(arguments->children[0]))
130 {
131 function_name = *opt_name;
132 }
133 else if (arguments->children[0]->as<ASTLiteral>())
134 {
135 throw Exception(ErrorCodes::BAD_ARGUMENTS,
136 "Aggregate function name for data type SimpleAggregateFunction must "
137 "be passed as identifier (without quotes) or function");
138 }
139 else
140 throw Exception(ErrorCodes::BAD_ARGUMENTS,
141 "Unexpected AST element passed as aggregate function name for data type "
142 "SimpleAggregateFunction. Must be identifier or function.");
143
144 for (size_t i = 1; i < arguments->children.size(); ++i)
145 argument_types.push_back(DataTypeFactory::instance().get(arguments->children[i]));
146
147 if (function_name.empty())
148 throw Exception(ErrorCodes::LOGICAL_ERROR, "Empty name of aggregate function passed");

Callers

nothing calls this directly

Calls 12

removeLowCardinalityFunction · 0.85
ExceptionClass · 0.50
tryGetIdentifierNameFunction · 0.50
emptyMethod · 0.45
resizeMethod · 0.45
sizeMethod · 0.45
formatForErrorMessageMethod · 0.45
push_backMethod · 0.45
getMethod · 0.45
getNameMethod · 0.45
equalsMethod · 0.45
getResultTypeMethod · 0.45

Tested by

no test coverage detected