@@ -216,7 +216,55 @@ ColumnPtr FunctionArrayReduce::executeImpl(const ColumnsWithTypeAndName & argume
216216
217217REGISTER_FUNCTION (ArrayReduce)
218218{
219- factory.registerFunction <FunctionArrayReduce>();
219+ FunctionDocumentation::Description description = R"(
220+ Applies an aggregate function to array elements and returns its result.
221+ The name of the aggregation function is passed as a string in single quotes `'max'`, `'sum'`.
222+ When using parametric aggregate functions, the parameter is indicated after the function name in parentheses `'uniqUpTo(6)'`.
223+ )" ;
224+ FunctionDocumentation::Syntax syntax = " arrayReduce(agg_f, x1, x2, ..., xN)" ;
225+ FunctionDocumentation::Arguments arguments = {
226+ {" agg_f" , " The name of an aggregate function which should be a constant [string](/sql-reference/data-types/string)." },
227+ {" xN" , " Any number of [array](/sql-reference/data-types/array) type columns as the parameters of the aggregation function." },
228+ };
229+ FunctionDocumentation::ReturnedValue returned_value = " Returns the result of the aggregate function" ;
230+ FunctionDocumentation::Examples examples = {
231+ {" Usage example" , " SELECT arrayReduce('max', [1, 2, 3]);" ,
232+ R"(
233+ ┌─arrayReduce('max', [1, 2, 3])─┐
234+ │ 3 │
235+ └───────────────────────────────┘
236+ )"
237+ },
238+ {" Example with aggregate function using multiple arguments" ,
239+ R"(
240+ If an aggregate function takes multiple arguments, then this function must be applied to multiple arrays of the same size.
241+
242+ ```sql
243+ SELECT arrayReduce('maxIf', [3, 5], [1, 0]);
244+ ```
245+ )" ,
246+ R"(
247+ ┌─arrayReduce('maxIf', [3, 5], [1, 0])─┐
248+ │ 3 │
249+ └──────────────────────────────────────┘
250+ )"
251+ },
252+ {" Example with a parametric aggregate function" ,
253+ R"(
254+ SELECT arrayReduce('uniqUpTo(3)', [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]);
255+ )" ,
256+ R"(
257+ ┌─arrayReduce('uniqUpTo(3)', [1, 2, 3, 4, 5, 6, 7, 8, 9, 10])─┐
258+ │ 4 │
259+ └─────────────────────────────────────────────────────────────┘
260+ )"
261+ }
262+ };
263+ FunctionDocumentation::IntroducedIn introduced_in = {1 , 1 };
264+ FunctionDocumentation::Category category = FunctionDocumentation::Category::Array;
265+ FunctionDocumentation documentation = {description, syntax, arguments, returned_value, examples, introduced_in, category};
266+
267+ factory.registerFunction <FunctionArrayReduce>(documentation);
220268}
221269
222270}
0 commit comments