Skip to content

Commit 63833ab

Browse files
authored
Merge pull request ClickHouse#80705 from Blargian/autogen_functions_formatting
Docs: autogenerated docs formatting improvement
2 parents 9e91879 + 0d78cd5 commit 63833ab

File tree

6 files changed

+26
-20
lines changed

6 files changed

+26
-20
lines changed

src/Common/FunctionDocumentation.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,13 @@ std::string FunctionDocumentation::examplesAsString() const
2727
std::string res;
2828
for (const auto & [name, query, result] : examples)
2929
{
30-
res += name + ":\n\n";
31-
res += "```sql\n";
30+
res += "**" + name + "**" + "\n\n";
31+
res += "```sql title=""Query""\n";
3232
res += query + "\n";
3333
res += "```\n\n";
34-
res += "Result:\n\n";
35-
res += "```text\n";
34+
res += "```response title=""Response""\n";
3635
res += result + "\n";
37-
res += "```\n";
36+
res += "```";
3837
}
3938
return res;
4039
}

src/Functions/modulo.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -201,8 +201,8 @@ Calculates the remainder when dividing `x` by `y`. Similar to function
201201
`modulo` except that `positiveModulo` always return non-negative number.
202202
)";
203203
FunctionDocumentation::Syntax syntax = "positiveModulo(x, y)";
204-
FunctionDocumentation::Argument argument1 = {"x", "The dividend"};
205-
FunctionDocumentation::Argument argument2 = {"y", "The divisor (modulus)"};
204+
FunctionDocumentation::Argument argument1 = {"x", "The dividend. [`(U)Int*`](/sql-reference/data-types/int-uint)/[`Float32/64`](/sql-reference/data-types/float)."};
205+
FunctionDocumentation::Argument argument2 = {"y", "The divisor (modulus). [`(U)Int*`](/sql-reference/data-types/int-uint)/[`Float32/64`](/sql-reference/data-types/float)."};
206206
FunctionDocumentation::Arguments arguments = {argument1, argument2};
207207
FunctionDocumentation::ReturnedValue returned_value = R"(
208208
Returns the difference between `x` and the nearest integer not greater than

src/Functions/moduloOrNull.cpp

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,25 @@ using FunctionPositiveModuloOrNll = BinaryArithmeticOverloadResolver<PositiveMod
2121

2222
REGISTER_FUNCTION(PositiveModuloOrNull)
2323
{
24-
factory.registerFunction<FunctionPositiveModuloOrNll>(FunctionDocumentation
25-
{
26-
.description = R"(
24+
FunctionDocumentation::Description description = R"(
2725
Calculates the remainder when dividing `a` by `b`. Similar to function `positiveModulo` except that `positiveModuloOrNull` will return NULL
2826
if the right argument is 0.
29-
)",
30-
.examples{{"positiveModuloOrNull", "SELECT positiveModuloOrNull(1, 0);", ""}},
31-
.category = FunctionDocumentation::Category::Arithmetic},
32-
FunctionFactory::Case::Insensitive);
27+
)";
28+
FunctionDocumentation::Syntax syntax = "positiveModulo(x, y)";
29+
FunctionDocumentation::Arguments arguments = {
30+
{"x", "The dividend. [`(U)Int*`](/sql-reference/data-types/int-uint)/[`Float32/64`](/sql-reference/data-types/float)."},
31+
{"x", "The divisor (modulus). [`(U)Int*`](/sql-reference/data-types/int-uint)/[`Float32/64`](/sql-reference/data-types/float)."}
32+
};
33+
FunctionDocumentation::ReturnedValue returned_value = R"(
34+
Returns the difference between `x` and the nearest integer not greater than
35+
`x` divisible by `y`, `null` when the divisor is zero.
36+
)";
37+
FunctionDocumentation::Examples examples = {{"positiveModulo", "SELECT positiveModulo(-1, 10)", "9"}};
38+
FunctionDocumentation::IntroducedIn introduced_in = {22, 11};
39+
FunctionDocumentation::Category categories = FunctionDocumentation::Category::Arithmetic;
40+
FunctionDocumentation documentation = {description, syntax, arguments, returned_value, examples, introduced_in, categories};
41+
42+
factory.registerFunction<FunctionPositiveModuloOrNll>(documentation, FunctionFactory::Case::Insensitive);
3343

3444
factory.registerAlias("positive_modulo_or_null", "positiveModuloOrNull", FunctionFactory::Case::Insensitive);
3545
factory.registerAlias("pmodOrNull", "positiveModuloOrNull", FunctionFactory::Case::Insensitive);

src/Functions/moduloOrZero.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,16 +48,16 @@ Like modulo but returns zero when the divisor is zero, as opposed to an
4848
exception with the modulo function.
4949
)";
5050
FunctionDocumentation::Syntax syntax = "moduloOrZero(a, b)";
51-
FunctionDocumentation::Argument argument1 = {"a", "The dividend"};
52-
FunctionDocumentation::Argument argument2 = {"b", "The divisor (modulus)"};
51+
FunctionDocumentation::Argument argument1 = {"a", "The dividend. [`(U)Int*`](/sql-reference/data-types/int-uint)/[`Float32/64`](/sql-reference/data-types/float)."};
52+
FunctionDocumentation::Argument argument2 = {"b", "The divisor (modulus). [`(U)Int*`](/sql-reference/data-types/int-uint)/[`Float32/64`](/sql-reference/data-types/float)."};
5353
FunctionDocumentation::Arguments arguments = {argument1, argument2};
5454
FunctionDocumentation::ReturnedValue returned_value = "The remainder of a % b, or `0` when the divisor is `0`.";
5555
FunctionDocumentation::Examples examples = {{"", "SELECT moduloOrZero(5, 0)", "0"}};
5656
FunctionDocumentation::IntroducedIn introduced_in = {20, 3};
5757
FunctionDocumentation::Category categories = FunctionDocumentation::Category::Arithmetic;
5858
FunctionDocumentation documentation = {description, syntax, arguments, returned_value, examples, introduced_in, categories};
5959

60-
factory.registerFunction<FunctionModuloOrZero>();
60+
factory.registerFunction<FunctionModuloOrZero>(documentation);
6161
}
6262

6363
}

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
@@ -361,7 +361,6 @@ minSampleSizeContinuous
361361
minSampleSizeConversion
362362
moduloLegacy
363363
moduloOrNull
364-
moduloOrZero
365364
monthName
366365
multiFuzzyMatchAllIndices
367366
multiFuzzyMatchAny

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
@@ -484,7 +484,6 @@ minSampleSizeContinuous
484484
minSampleSizeConversion
485485
moduloLegacy
486486
moduloOrNull
487-
moduloOrZero
488487
monthName
489488
mortonDecode
490489
mortonEncode
@@ -620,7 +619,6 @@ position
620619
positionCaseInsensitive
621620
positionCaseInsensitiveUTF8
622621
positionUTF8
623-
positiveModuloOrNull
624622
pow
625623
printf
626624
proportionsZTest

0 commit comments

Comments
 (0)