| 89 | |
| 90 | |
| 91 | static 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"); |
nothing calls this directly
no test coverage detected