Skip to content

Commit fa5f1c8

Browse files
committed
Add documentation to source code
1 parent 68f91aa commit fa5f1c8

File tree

4 files changed

+62
-6
lines changed

4 files changed

+62
-6
lines changed

src/Functions/array/arrayJaccardIndex.cpp

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,19 @@ class FunctionArrayJaccardIndex : public IFunction
151151

152152
REGISTER_FUNCTION(ArrayJaccardIndex)
153153
{
154-
factory.registerFunction<FunctionArrayJaccardIndex>();
154+
FunctionDocumentation::Description description = "Returns the [Jaccard index](https://en.wikipedia.org/wiki/Jaccard_index) of two arrays.";
155+
FunctionDocumentation::Syntax syntax = "arrayJaccardIndex(x, y)";
156+
FunctionDocumentation::Arguments arguments = {
157+
{"x", "First array. [Array](/sql-reference/data-types/array)."},
158+
{"y", "Second array. [Array](/sql-reference/data-types/array)."},
159+
};
160+
FunctionDocumentation::ReturnedValue returned_value = "Returns the Jaccard index of `x` and `y`.[Float64](/sql-reference/data-types/float)";
161+
FunctionDocumentation::Examples examples = {{"Usage example", "SELECT arrayJaccardIndex([1, 2], [2, 3]) AS res", "0.3333333333333333"}};
162+
FunctionDocumentation::IntroducedIn introduced_in = {23, 7};
163+
FunctionDocumentation::Category category = FunctionDocumentation::Category::Array;
164+
FunctionDocumentation documentation = {description, syntax, arguments, returned_value, examples, introduced_in, category};
165+
166+
factory.registerFunction<FunctionArrayJaccardIndex>(documentation);
155167
}
156168

157169
}

src/Functions/array/arrayReduce.cpp

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,55 @@ ColumnPtr FunctionArrayReduce::executeImpl(const ColumnsWithTypeAndName & argume
216216

217217
REGISTER_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
}

tests/queries/0_stateless/02415_all_new_functions_must_be_documented.reference

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,6 @@ arrayFirstIndex
113113
arrayFirstOrNull
114114
arrayFlatten
115115
arrayIntersect
116-
arrayJaccardIndex
117116
arrayJoin
118117
arrayLast
119118
arrayLastIndex
@@ -128,7 +127,6 @@ arrayPushBack
128127
arrayPushFront
129128
arrayROCAUC
130129
arrayRandomSample
131-
arrayReduce
132130
arrayReduceInRanges
133131
arrayResize
134132
arrayReverse

tests/queries/0_stateless/02415_all_new_functions_must_have_version_information.reference

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,6 @@ arrayFirstOrNull
132132
arrayFlatten
133133
arrayFold
134134
arrayIntersect
135-
arrayJaccardIndex
136135
arrayJoin
137136
arrayLast
138137
arrayLastIndex
@@ -152,7 +151,6 @@ arrayPushBack
152151
arrayPushFront
153152
arrayROCAUC
154153
arrayRandomSample
155-
arrayReduce
156154
arrayReduceInRanges
157155
arrayResize
158156
arrayReverse

0 commit comments

Comments
 (0)