Skip to content

Commit d0f4b42

Browse files
authored
Merge pull request ClickHouse#79839 from rschu1ze/introduced_in
`storage.functions`: Add field `introduced_in`
2 parents 9d83d9f + 9233e38 commit d0f4b42

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+1294
-71
lines changed

docs/en/operations/system-tables/functions.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ Columns:
2020
- `arguments`, ([String](../../sql-reference/data-types/string.md)) - What arguments does the function take.
2121
- `returned_value`, ([String](../../sql-reference/data-types/string.md)) - What does the function return.
2222
- `examples`, ([String](../../sql-reference/data-types/string.md)) - Example usage of the function.
23+
- `introduced_in`, ([String](../../sql-reference/data-types/string.md)) - ClickHouse version in which the function was first introduced.
2324
- `categories`, ([String](../../sql-reference/data-types/string.md)) - The category of the function.
2425

2526
**Example**

src/Common/FunctionDocumentation.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ namespace ErrorCodes
1212
extern const int LOGICAL_ERROR;
1313
}
1414

15+
VersionNumber VERSION_UNKNOWN = {0};
16+
1517
std::string FunctionDocumentation::argumentsAsString() const
1618
{
1719
std::string res;
@@ -37,6 +39,14 @@ std::string FunctionDocumentation::examplesAsString() const
3739
return res;
3840
}
3941

42+
std::string FunctionDocumentation::introducedInAsString() const
43+
{
44+
if (introduced_in == FunctionDocumentation::VERSION_UNKNOWN)
45+
return ""; /// we could show "unknown" here but for consistency with other fields return the empty string
46+
else
47+
return introduced_in.toString();
48+
}
49+
4050
std::string FunctionDocumentation::categoryAsString() const
4151
{
4252
static const std::unordered_map<Category, std::string> category_to_string = {

src/Common/FunctionDocumentation.h

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#pragma once
22

3-
#include <set>
3+
#include <Common/VersionNumber.h>
44
#include <string>
55
#include <vector>
66

@@ -63,6 +63,9 @@ struct FunctionDocumentation
6363
};
6464
using Examples = std::vector<Example>;
6565

66+
using IntroducedIn = VersionNumber;
67+
static constexpr VersionNumber VERSION_UNKNOWN;
68+
6669
enum class Category : uint8_t
6770
{
6871
/// Default category
@@ -118,15 +121,17 @@ struct FunctionDocumentation
118121
using Related = std::vector<std::string>;
119122

120123
/// TODO Fields with {} initialization are optional. We should make all fields non-optional.
121-
Description description; /// E.g. "Returns the position (in bytes, starting at 1) of a substring needle in a string haystack."
122-
Syntax syntax {}; /// E.g. "position(haystack, needle)"
123-
Arguments arguments {}; /// E.g. ["haystack — String in which the search is performed. String.", "needle — Substring to be searched. String."]
124-
ReturnedValue returned_value {}; /// E.g. "Starting position in bytes and counting from 1, if the substring was found."
125-
Examples examples {}; ///
126-
Category category; /// E.g. Category::DatesAndTimes
124+
Description description; /// E.g. "Returns the position (in bytes, starting at 1) of a substring needle in a string haystack."
125+
Syntax syntax {}; /// E.g. "position(haystack, needle)"
126+
Arguments arguments {}; /// E.g. ["haystack — String in which the search is performed. String.", "needle — Substring to be searched. String."]
127+
ReturnedValue returned_value {}; /// E.g. "Starting position in bytes and counting from 1, if the substring was found."
128+
Examples examples {}; ///
129+
IntroducedIn introduced_in {VERSION_UNKNOWN}; /// E.g. {25, 5}
130+
Category category; /// E.g. Category::DatesAndTimes
127131

128132
std::string argumentsAsString() const;
129133
std::string examplesAsString() const;
134+
std::string introducedInAsString() const;
130135
std::string categoryAsString() const;
131136
};
132137

src/Common/VersionNumber.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ std::string VersionNumber::toString() const
3232
int VersionNumber::compare(const VersionNumber & rhs) const
3333
{
3434
size_t min = std::min(components.size(), rhs.components.size());
35+
3536
for (size_t i = 0; i < min; ++i)
3637
{
3738
if (auto d = components[i] - rhs.components[i])
@@ -42,6 +43,7 @@ int VersionNumber::compare(const VersionNumber & rhs) const
4243
{
4344
return components[min] >= 0 ? 1 : -1;
4445
}
46+
4547
if (rhs.components.size() > min)
4648
{
4749
return -rhs.components[min] > 0 ? 1 : -1;

src/Common/VersionNumber.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ struct VersionNumber
1313
{
1414
explicit VersionNumber() = default;
1515

16-
VersionNumber(const std::initializer_list<Int64> & init) : components(init) {}
16+
constexpr VersionNumber(const std::initializer_list<Int64> & init) : components(init) {}
1717
explicit VersionNumber(Int64 major, Int64 minor = 0, Int64 patch = 0) : components{major, minor, patch} { }
1818

1919
/// Parse version number from string.

src/Functions/abs.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,9 @@ REGISTER_FUNCTION(Abs)
5656
FunctionDocumentation::Arguments argument = {{"x", "Value to get the absolute value of"}};
5757
FunctionDocumentation::ReturnedValue returned_value = "The absolute value of `x`";
5858
FunctionDocumentation::Examples examples = {{"", "SELECT abs(-0.5)", "0.5"}};
59+
FunctionDocumentation::IntroducedIn introduced_in = {1, 1};
5960
FunctionDocumentation::Category categories = FunctionDocumentation::Category::Arithmetic;
60-
FunctionDocumentation documentation = {description, syntax, argument, returned_value, examples, categories};
61+
FunctionDocumentation documentation = {description, syntax, argument, returned_value, examples, introduced_in, categories};
6162

6263
factory.registerFunction<FunctionAbs>(documentation, FunctionFactory::Case::Insensitive);
6364
}

src/Functions/array/arrayNormalizedGini.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -406,10 +406,11 @@ REGISTER_FUNCTION(NormalizedGini)
406406
= {{"Example",
407407
"SELECT arrayNormalizedGini([0.9, 0.3, 0.8, 0.7],[6, 1, 0, 2]);",
408408
"(0.18055555555555558,0.2638888888888889,0.6842105263157896)"}};
409+
FunctionDocumentation::IntroducedIn doc_introduced_in = {25, 1};
409410
FunctionDocumentation::Category doc_category = FunctionDocumentation::Category::Array;
410411

411412
factory.registerFunction<FunctionArrayNormalizedGini>(
412-
{doc_description, doc_syntax, doc_arguments, doc_returned_value, doc_examples, doc_category}, FunctionFactory::Case::Sensitive);
413+
{doc_description, doc_syntax, doc_arguments, doc_returned_value, doc_examples, doc_introduced_in, doc_category}, FunctionFactory::Case::Sensitive);
413414
}
414415

415416
}

src/Functions/base64Decode.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,10 @@ REGISTER_FUNCTION(Base64Decode)
1313
FunctionDocumentation::Arguments arguments = {{"encoded", "String column or constant. If the string is not a valid Base64-encoded value, an exception is thrown."}};
1414
FunctionDocumentation::ReturnedValue returned_value = "A string containing the decoded value of the argument.";
1515
FunctionDocumentation::Examples examples = {{"Example", "SELECT base64Decode('Y2xpY2tob3VzZQ==')", "clickhouse"}};
16+
FunctionDocumentation::IntroducedIn introduced_in = {18, 16};
1617
FunctionDocumentation::Category category = FunctionDocumentation::Category::Encoding;
1718

18-
factory.registerFunction<FunctionBase64Conversion<Base64Decode<Base64Variant::Normal>>>({description, syntax, arguments, returned_value, examples, category});
19+
factory.registerFunction<FunctionBase64Conversion<Base64Decode<Base64Variant::Normal>>>({description, syntax, arguments, returned_value, examples, introduced_in, category});
1920

2021
/// MySQL compatibility alias.
2122
factory.registerAlias("FROM_BASE64", "base64Decode", FunctionFactory::Case::Insensitive);

src/Functions/base64Encode.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,10 @@ REGISTER_FUNCTION(Base64Encode)
1313
FunctionDocumentation::Arguments arguments = {{"plaintext", "String column or constant."}};
1414
FunctionDocumentation::ReturnedValue returned_value = "A string containing the encoded value of the argument.";
1515
FunctionDocumentation::Examples examples = {{"Example", "SELECT base64Encode('clickhouse')", "Y2xpY2tob3VzZQ=="}};
16+
FunctionDocumentation::IntroducedIn introduced_in = {18, 16};
1617
FunctionDocumentation::Category category = FunctionDocumentation::Category::String;
1718

18-
factory.registerFunction<FunctionBase64Conversion<Base64Encode<Base64Variant::Normal>>>({description, syntax, arguments, returned_value, examples, category});
19+
factory.registerFunction<FunctionBase64Conversion<Base64Encode<Base64Variant::Normal>>>({description, syntax, arguments, returned_value, examples, introduced_in, category});
1920

2021
/// MySQL compatibility alias.
2122
factory.registerAlias("TO_BASE64", "base64Encode", FunctionFactory::Case::Insensitive);

src/Functions/base64URLDecode.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,10 @@ REGISTER_FUNCTION(Base64URLDecode)
1313
FunctionDocumentation::Arguments arguments = {{"encodedURL", "String column or constant. If the string is not a valid Base64-encoded value, an exception is thrown."}};
1414
FunctionDocumentation::ReturnedValue returned_value = "A string containing the decoded value of the argument.";
1515
FunctionDocumentation::Examples examples = {{"Example", "SELECT base64URLDecode('aHR0cDovL2NsaWNraG91c2UuY29t')", "https://clickhouse.com"}};
16+
FunctionDocumentation::IntroducedIn introduced_in = {24, 6};
1617
FunctionDocumentation::Category category = FunctionDocumentation::Category::Encoding;
1718

18-
factory.registerFunction<FunctionBase64Conversion<Base64Decode<Base64Variant::URL>>>({description, syntax, arguments, returned_value, examples, category});
19+
factory.registerFunction<FunctionBase64Conversion<Base64Decode<Base64Variant::URL>>>({description, syntax, arguments, returned_value, examples, introduced_in, category});
1920
}
2021

2122
}

0 commit comments

Comments
 (0)