Skip to content

Commit cadd693

Browse files
committed
Add documentation to source code
1 parent 1c90b24 commit cadd693

File tree

5 files changed

+47
-6
lines changed

5 files changed

+47
-6
lines changed

src/Functions/array/arrayAUC.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -502,7 +502,7 @@ For more details, please see [here](https://developers.google.com/machine-learni
502502
)";
503503
FunctionDocumentation::Syntax syntax_roc = "arrayROCAUC(scores, labels[, scale[, partial_offsets]])";
504504
FunctionDocumentation::Arguments arguments_roc = {
505-
{"scores", "Scores prediction model gives. [Array](/sql-reference/data-types/array) of [Integers](../data-types/int-uint.md) or [Floats](../data-types/float.md)."},
505+
{"scores", "Scores prediction model gives. [`Array(T)`](/sql-reference/data-types/array) of [Integers](../data-types/int-uint.md) or [Floats](../data-types/float.md)."},
506506
{"labels", "Labels of samples, usually 1 for positive sample and 0 for negative sample. [Array](/sql-reference/data-types/array) of [Integers](../data-types/int-uint.md) or [Enums](../data-types/enum.md)."},
507507
{"scale", "Decides whether to return the normalized area. If false, returns the area under the TP (true positives) x FP (false positives) curve instead. Default value: true. [Bool](../data-types/boolean.md). Optional."}
508508
{"partial_offsets", R"(
@@ -543,7 +543,7 @@ For more details, please see [here](https://developers.google.com/machine-learni
543543
{"cores", "Scores prediction model gives. [Array](/sql-reference/data-types/array) of [Integers](../data-types/int-uint.md) or [Floats](../data-types/float.md)."},
544544
{"labels", "Labels of samples, usually 1 for positive sample and 0 for negative sample. [Array](/sql-reference/data-types/array) of [Integers](../data-types/int-uint.md) or [Enums](../data-types/enum.md)."},
545545
{"partial_offsets", R"(
546-
- Optional. An [Array](/sql-reference/data-types/array) of three non-negative integers for calculating a partial area under the PR curve (equivalent to a vertical band of the PR space) instead of the whole AUC. This option is useful for distributed computation of the PR AUC. The array must contain the following elements [`higher_partitions_tp`, `higher_partitions_fp`, `total_positives`]. [Array](/sql-reference/data-types/array) of non-negative [Integers](../data-types/int-uint.md). Optional.
546+
- Optional. An [`Array(T)`](/sql-reference/data-types/array) of three non-negative integers for calculating a partial area under the PR curve (equivalent to a vertical band of the PR space) instead of the whole AUC. This option is useful for distributed computation of the PR AUC. The array must contain the following elements [`higher_partitions_tp`, `higher_partitions_fp`, `total_positives`]. [Array](/sql-reference/data-types/array) of non-negative [Integers](../data-types/int-uint.md). Optional.
547547
- `higher_partitions_tp`: The number of positive labels in the higher-scored partitions.
548548
- `higher_partitions_fp`: The number of negative labels in the higher-scored partitions.
549549
- `total_positives`: The total number of positive samples in the entire dataset.

src/Functions/array/arrayFilter.cpp

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,30 @@ ColumnPtr ArrayFilterImpl::execute(const ColumnArray & array, ColumnPtr mapped)
4949

5050
REGISTER_FUNCTION(ArrayFilter)
5151
{
52-
factory.registerFunction<FunctionArrayFilter>();
52+
FunctionDocumentation::Description description = "Returns an array containing only the elements in `arrN` for which `func(arr1[i], ..., arrN[i])` return something other than `0`.";
53+
FunctionDocumentation::Syntax syntax = "arrayFilter(func, arr1 [, arr2, ... , arrN)]";
54+
FunctionDocumentation::Arguments arguments = {
55+
{"func", "Function to apply to each element of the array(s). [Lambda function](/sql-reference/functions/overview#arrow-operator-and-lambda)"},
56+
{"arr1 [, arr2, ... , arrN)]", "N arrays over which to operate. [`Array(T)`](/sql-reference/data-types/array)."},
57+
};
58+
FunctionDocumentation::ReturnedValue returned_value = "Returns a filtered array. [`Array(T)`](/sql-reference/data-types/array).";
59+
FunctionDocumentation::Examples examples = {
60+
{"Example 1", "SELECT arrayFilter(x -> x LIKE '%World%', ['Hello', 'abc World']) AS res", "['abc World']"},
61+
{"Example 2", R"(
62+
SELECT
63+
arrayFilter(
64+
(i, x) -> x LIKE '%World%',
65+
arrayEnumerate(arr),
66+
['Hello', 'abc World'] AS arr)
67+
AS res
68+
)",
69+
"[2]"}
70+
};
71+
FunctionDocumentation::IntroducedIn introduced_in = {1, 1};
72+
FunctionDocumentation::Category category = FunctionDocumentation::Category::Array;
73+
FunctionDocumentation documentation = {description, syntax, arguments, returned_value, examples, introduced_in, category};
74+
75+
factory.registerFunction<FunctionArrayFilter>(documentation);
5376
}
5477

5578
}

src/Functions/array/arrayMap.cpp

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,27 @@ namespace DB
66

77
REGISTER_FUNCTION(ArrayMap)
88
{
9-
factory.registerFunction<FunctionArrayMap>();
9+
FunctionDocumentation::Description description = R"(
10+
Returns an array obtained from the original arrays by application of `func(arr1[i], ..., arrN[i])` for each element.
11+
Arrays `arr1` ... `arrN` must have the same number of elements.
12+
13+
`arrayMap` is a [higher-order function](/sql-reference/functions/overview#higher-order-functions). You must pass a lambda function to it as the first argument, and it can't be omitted.
14+
)";
15+
FunctionDocumentation::Syntax syntax = "arrayMap(func, arr1 [, ..., arrN])";
16+
FunctionDocumentation::Arguments arguments = {
17+
{"func", "Function to apply to each element of the array(s). Optional. [Lambda function](/sql-reference/functions/overview#arrow-operator-and-lambda)"},
18+
{"arr1 [, ..., arrN]", "N arrays to apply `f` to. [Array(T)](/sql-reference/data-types/array)."},
19+
};
20+
FunctionDocumentation::ReturnedValue returned_value = "Returns an array with elements the results of applying `f` to the original array. [`Array(T)`](/sql-reference/data-types/array)";
21+
FunctionDocumentation::Examples examples = {
22+
{"Usage example", "SELECT arrayMap(x -> (x + 2), [1, 2, 3]) as res;", "[3,4,5]"},
23+
{"Creating a tuple of elements from different arrays", "SELECT arrayMap((x, y) -> (x, y), [1, 2, 3], [4, 5, 6]) AS res", "[(1,4),(2,5),(3,6)]"}
24+
};
25+
FunctionDocumentation::IntroducedIn introduced_in = {1, 1};
26+
FunctionDocumentation::Category category = FunctionDocumentation::Category::Array;
27+
FunctionDocumentation documentation = {description, syntax, arguments, returned_value, examples, introduced_in, category};
28+
29+
factory.registerFunction<FunctionArrayMap>(documentation);
1030
}
1131

1232
}

tests/queries/0_stateless/02415_all_new_functions_must_be_documented.reference

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,6 @@ arrayJoin
116116
arrayLast
117117
arrayLastIndex
118118
arrayLastOrNull
119-
arrayMap
120119
arrayMax
121120
arrayMin
122121
arrayPopBack

tests/queries/0_stateless/02415_all_new_functions_must_have_version_information.reference

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,6 @@ arrayLastIndex
137137
arrayLastOrNull
138138
arrayLevenshteinDistance
139139
arrayLevenshteinDistanceWeighted
140-
arrayMap
141140
arrayMax
142141
arrayMin
143142
arrayPartialReverseSort

0 commit comments

Comments
 (0)