Skip to content

Commit daa48e0

Browse files
committed
Add documentation to source code
1 parent 6a8551f commit daa48e0

File tree

3 files changed

+97
-4
lines changed

3 files changed

+97
-4
lines changed

src/Functions/array/arrayEnumerate.cpp

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,52 @@ class FunctionArrayEnumerate : public IFunction
7676

7777
REGISTER_FUNCTION(ArrayEnumerate)
7878
{
79-
factory.registerFunction<FunctionArrayEnumerate>();
79+
FunctionDocumentation::Description description = R"(
80+
Returns the array `[1, 2, 3, ..., length (arr)]`
81+
82+
This function is normally used with the [`ARRAY JOIN`](/sql-reference/statements/select/array-join) clause. It allows counting something just
83+
once for each array after applying `ARRAY JOIN`.
84+
This function can also be used in higher-order functions. For example, you can use it to get array indexes for elements that match a condition.
85+
)";
86+
FunctionDocumentation::Syntax syntax = "arrayEnumerate(x)";
87+
FunctionDocumentation::Arguments arguments = {
88+
{"x", "The array to enumerate. [`Array`](/sql-reference/data-types/array)."}
89+
};
90+
FunctionDocumentation::ReturnedValue returned_value = "Returns the array `[1, 2, 3, ..., length (arr)]`. Array(UInt32)"
91+
FunctionDocumentation::Examples examples = {{"Basic example with ARRAY JOIN", R"(
92+
CREATE TABLE test
93+
(
94+
`id` UInt8,
95+
`tag` Array(String),
96+
`version` Array(String)
97+
)
98+
ENGINE = MergeTree
99+
ORDER BY id;
100+
101+
INSERT INTO test VALUES (1, ['release-stable', 'dev', 'security'], ['2.4.0', '2.6.0-alpha', '2.4.0-sec1']);
102+
103+
SELECT
104+
id,
105+
tag,
106+
version,
107+
seq
108+
FROM test
109+
ARRAY JOIN
110+
tag,
111+
version,
112+
arrayEnumerate(tag) AS seq
113+
)", R"(
114+
┌─id─┬─tag────────────┬─version─────┬─seq─┐
115+
│ 1 │ release-stable │ 2.4.0 │ 1 │
116+
│ 1 │ dev │ 2.6.0-alpha │ 2 │
117+
│ 1 │ security │ 2.4.0-sec1 │ 3 │
118+
└────┴────────────────┴─────────────┴─────┘
119+
)"}};
120+
FunctionDocumentation::IntroducedIn introduced_in = {1, 1};
121+
FunctionDocumentation::Category category = FunctionDocumentation::Category::Array;
122+
FunctionDocumentation documentation = {description, syntax, arguments, returned_value, examples, introduced_in, category};
123+
124+
factory.registerFunction<FunctionArrayEnumerate>(documentation);
80125
}
81126

82127
}

src/Functions/array/arrayEnumerateUniqRanked.cpp

Lines changed: 51 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,57 @@ class FunctionArrayEnumerateUniqRanked : public FunctionArrayEnumerateRankedExte
1616

1717
REGISTER_FUNCTION(ArrayEnumerateUniqRanked)
1818
{
19-
factory.registerFunction<FunctionArrayEnumerateUniqRanked>();
19+
FunctionDocumentation::Description description = R"(
20+
Returns an array (or multi-dimensional array) with the same dimensions as the source array,
21+
indicating for each element what it's position is among elements with the same value.
22+
It allows for enumeration of a multi-dimensional array with the ability to specify how deep to look inside the array.
23+
)";
24+
FunctionDocumentation::Syntax syntax = "arrayEnumerateUniqRanked(clear_depth, arr, max_array_depth)";
25+
FunctionDocumentation::Arguments arguments = {
26+
{"clear_depth", "Enumerate elements at the specified level separately. Positive [Integer](../data-types/int-uint.md) less than or equal to `max_arr_depth`."},
27+
{"arr", "N-dimensional array to enumerate. [Array](/sql-reference/data-types/array)."},
28+
{"max_array_depth", "The maximum effective depth. Positive [Integer](../data-types/int-uint.md) less than or equal to the depth of `arr`."}
29+
};
30+
FunctionDocumentation::ReturnedValue returned_value = "Returns an N-dimensional array the same size as `arr` with each element showing the position of that element in relation to other elements of the same value."
31+
FunctionDocumentation::Examples examples = {
32+
{"Example 1", R"(
33+
With `clear_depth=1` and `max_array_depth=1`, the result of `arrayEnumerateUniqRanked` is identical to that which [`arrayEnumerateUniq`](#arrayenumerateuniq) would give for the same array.
34+
35+
```sql
36+
SELECT arrayEnumerateUniqRanked(1, [1,2,1], 1);
37+
```
38+
)", "[1,1,2]"},
39+
{"Example 2", R"(
40+
41+
With `clear_depth=1` and `max_array_depth=1`, the result of `arrayEnumerateUniqRanked` is identical to that which [`arrayEnumerateUniq`](#arrayenumerateuniq) would give for the same array.
42+
43+
```sql
44+
SELECT arrayEnumerateUniqRanked(1, [[1,2,3],[2,2,1],[3]], 2);", "[[1,1,1],[2,3,2],[2]]
45+
```
46+
)", "[1,1,2]"},
47+
{"Example 3", R"(
48+
49+
In this example, `arrayEnumerateUniqRanked` is used to obtain an array indicating, for each element of the multidimensional array, what its position is among elements of the same value. For the first row of the passed array,`[1,2,3]`, the corresponding result is `[1,1,1]`, indicating that this is the first time `1`,`2` and `3` are encountered. For the second row of the provided array,`[2,2,1]`, the corresponding result is `[2,3,3]`, indicating that `2` is encountered for a second and third time, and `1` is encountered for the second time. Likewise, for the third row of the provided array `[3]` the corresponding result is `[2]` indicating that `3` is encountered for the second time.
50+
51+
```sql
52+
SELECT arrayEnumerateUniqRanked(1, [[1,2,3],[2,2,1],[3]], 2);
53+
```
54+
)", "[[1,1,1],[2,3,2],[2]]"
55+
},
56+
{"Example 4", R"(
57+
58+
Changing `clear_depth=2`, results in elements being enumerated separately for each row.
59+
60+
```sql
61+
SELECT arrayEnumerateUniqRanked(2, [[1,2,3],[2,2,1],[3]], 2);
62+
```
63+
)", "[[1,1,1],[1,2,1],[1]]"},
64+
};
65+
FunctionDocumentation::IntroducedIn introduced_in = {1, 1};
66+
FunctionDocumentation::Category category = FunctionDocumentation::Category::Array;
67+
FunctionDocumentation documentation = {description, syntax, arguments, returned_value, examples, introduced_in, category};
68+
69+
factory.registerFunction<FunctionArrayEnumerateUniqRanked>(documentation);
2070
}
2171

2272
}

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
@@ -98,11 +98,9 @@ arrayCumSum
9898
arrayCumSumNonNegative
9999
arrayDifference
100100
arrayDistinct
101-
arrayEnumerate
102101
arrayEnumerateDense
103102
arrayEnumerateDenseRanked
104103
arrayEnumerateUniq
105-
arrayEnumerateUniqRanked
106104
arrayExists
107105
arrayFill
108106
arrayFilter

0 commit comments

Comments
 (0)