Skip to content

Commit 4d92d14

Browse files
authored
Merge pull request ClickHouse#79538 from Blargian/source_docs_categories
Docs: make FunctionDocumentation category enum
2 parents 72bbd26 + 447081d commit 4d92d14

File tree

145 files changed

+528
-345
lines changed

Some content is hidden

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

145 files changed

+528
-345
lines changed

src/Common/FunctionDocumentation.cpp

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,17 @@
11
#include <Common/FunctionDocumentation.h>
22

3+
#include <Common/Exception.h>
4+
5+
#include <unordered_map>
6+
37
namespace DB
48
{
59

10+
namespace ErrorCodes
11+
{
12+
extern const int LOGICAL_ERROR;
13+
}
14+
615
std::string FunctionDocumentation::argumentsAsString() const
716
{
817
std::string res;
@@ -28,4 +37,56 @@ std::string FunctionDocumentation::examplesAsString() const
2837
return res;
2938
}
3039

40+
std::string FunctionDocumentation::categoryAsString() const
41+
{
42+
static const std::unordered_map<Category, std::string> category_to_string = {
43+
{Category::Unknown, ""}, /// Default enum value for default-constructed FunctionDocumentation objects. Be consistent with other default fields (empty).
44+
{Category::Arithmetic, "Arithmetic"},
45+
{Category::Array, "Arrays"},
46+
{Category::Bit, "Bit"},
47+
{Category::Bitmap, "Bitmap"},
48+
{Category::Comparison, "Comparison"},
49+
{Category::Conditional, "Conditional"},
50+
{Category::DateAndTime, "Dates and Times"},
51+
{Category::Dictionary, "Dictionary"},
52+
{Category::Distance, "Distance"},
53+
{Category::EmbeddedDictionary, "Embedded Dictionary"},
54+
{Category::Geo, "Geo"},
55+
{Category::Encoding, "Encoding"},
56+
{Category::Encryption, "Encryption"},
57+
{Category::File, "File"},
58+
{Category::Hash, "Hash"},
59+
{Category::IPAddress, "IP Address"},
60+
{Category::Introspection, "Introspection"},
61+
{Category::JSON, "JSON"},
62+
{Category::Logical, "Logical"},
63+
{Category::MachineLearning, "Machine Learning"},
64+
{Category::Map, "Map"},
65+
{Category::Mathematical, "Mathematical"},
66+
{Category::NLP, "Natural Language Processing"},
67+
{Category::Nullable, "Nullable"},
68+
{Category::Other, "Other"},
69+
{Category::RandomNumber, "Random Number"},
70+
{Category::Rounding, "Rounding"},
71+
{Category::StringReplacement, "String Replacement"},
72+
{Category::StringSearch, "String Search"},
73+
{Category::StringSplitting, "String Splitting"},
74+
{Category::String, "String"},
75+
{Category::TimeSeries, "Time Series"},
76+
{Category::TimeWindow, "Time Window"},
77+
{Category::Tuple, "Tuple"},
78+
{Category::TypeConversion, "Type Conversion"},
79+
{Category::ULID, "ULID"},
80+
{Category::URL, "URL"},
81+
{Category::UUID, "UUID"},
82+
{Category::UniqTheta, "UniqTheta"},
83+
{Category::TableFunction, "Table Functions"}
84+
};
85+
86+
if (auto it = category_to_string.find(category); it != category_to_string.end())
87+
return it->second;
88+
else
89+
throw Exception(ErrorCodes::LOGICAL_ERROR, "Category has no mapping to string");
90+
}
91+
3192
}

src/Common/FunctionDocumentation.h

Lines changed: 59 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -63,20 +63,71 @@ struct FunctionDocumentation
6363
};
6464
using Examples = std::vector<Example>;
6565

66-
using Category = std::string;
66+
enum class Category : uint8_t
67+
{
68+
/// Default category
69+
Unknown,
70+
71+
/// Regular functions
72+
Arithmetic,
73+
Array,
74+
Bit,
75+
Bitmap,
76+
Comparison,
77+
Conditional,
78+
DateAndTime,
79+
Dictionary,
80+
Dynamic,
81+
Distance,
82+
EmbeddedDictionary,
83+
Geo,
84+
Encoding,
85+
Encryption,
86+
File,
87+
Hash,
88+
IPAddress,
89+
Introspection,
90+
JSON,
91+
Logical,
92+
MachineLearning,
93+
Map,
94+
Mathematical,
95+
NLP,
96+
Nullable,
97+
Other,
98+
RandomNumber,
99+
Rounding,
100+
StringReplacement,
101+
StringSearch,
102+
StringSplitting,
103+
String,
104+
TimeSeries,
105+
TimeWindow,
106+
Tuple,
107+
TypeConversion,
108+
ULID,
109+
URL,
110+
UUID,
111+
UniqTheta,
112+
Variant,
113+
114+
/// Table functions
115+
TableFunction
116+
};
67117

68-
using Related = std::string;
118+
using Related = std::vector<std::string>;
69119

70120
/// TODO Fields with {} initialization are optional. We should make all fields non-optional.
71-
Description description; /// E.g. "Returns the position (in bytes, starting at 1) of a substring needle in a string haystack."
72-
Syntax syntax {}; /// E.g. "position(haystack, needle)"
73-
Arguments arguments {}; /// E.g. ["haystack — String in which the search is performed. String.", "needle — Substring to be searched. String."]
74-
ReturnedValue returned_value {}; /// E.g. "Starting position in bytes and counting from 1, if the substring was found."
75-
Examples examples {}; ///
76-
Category category {}; /// E.g. "String Search"
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
77127

78128
std::string argumentsAsString() const;
79129
std::string examplesAsString() const;
130+
std::string categoryAsString() const;
80131
};
81132

82133
}

src/Functions/FunctionGenerateRandomStructure.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -450,7 +450,7 @@ The function returns a value of type String.
450450
{"with specified number of columns", "SELECT generateRandomStructure(3)", "c1 String, c2 Array(Int32), c3 LowCardinality(String)"},
451451
{"with specified seed", "SELECT generateRandomStructure(1, 42)", "c1 UInt128"},
452452
},
453-
.category{"Random Numbers"}
453+
.category = FunctionDocumentation::Category::RandomNumber
454454
});
455455
}
456456

src/Functions/FunctionsCodingULID.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -179,8 +179,9 @@ An optional second argument can be passed to specify a timezone for the timestam
179179
)",
180180
.examples{
181181
{"ulid", "SELECT ULIDStringToDateTime(generateULID())", ""},
182-
{"timezone", "SELECT ULIDStringToDateTime(generateULID(), 'Asia/Istanbul')", ""}},
183-
.category{"ULID"}
182+
{"timezone", "SELECT ULIDStringToDateTime(generateULID(), 'Asia/Istanbul')", ""}
183+
},
184+
.category = FunctionDocumentation::Category::ULID
184185
});
185186
}
186187

src/Functions/FunctionsCodingUUID.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -496,7 +496,7 @@ This function accepts a UUID and returns a FixedString(16) as its binary represe
496496
│ 612f3c40-5d3b-217e-707b-6a546a3d7b29 │ a/<@];!~p{jTj={) │ @</a];!~p{jTj={) │
497497
└──────────────────────────────────────┴──────────────────┴──────────────────┘
498498
)"}},
499-
.category{"UUID"}});
499+
.category = FunctionDocumentation::Category::UUID});
500500

501501

502502
factory.registerFunction<FunctionUUIDv7ToDateTime>(
@@ -509,7 +509,7 @@ An optional second argument can be passed to specify a timezone for the timestam
509509
.examples{
510510
{"uuid","select UUIDv7ToDateTime(generateUUIDv7())", ""},
511511
{"uuid","select generateUUIDv7() as uuid, UUIDv7ToDateTime(uuid), UUIDv7ToDateTime(uuid, 'America/New_York')", ""}},
512-
.category{"UUID"}});
512+
.category = FunctionDocumentation::Category::UUID});
513513
}
514514

515515
}

src/Functions/FunctionsConversion_reg.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ Converts Float32 to BFloat16 with losing the precision.
2626
)",
2727
.examples{
2828
{"typical", "SELECT toBFloat16(12.3::Float32);", "12.3125"}},
29-
.category{"Type Conversion"}});
29+
.category = FunctionDocumentation::Category::TypeConversion});
3030

3131
factory.registerFunction<detail::FunctionToFloat32>();
3232
factory.registerFunction<detail::FunctionToFloat64>();
@@ -89,7 +89,7 @@ Example of a loss of precision:
8989
{"invalid1", "SELECT toBFloat16OrZero('abc');", "0"},
9090
{"invalid2", "SELECT toBFloat16OrZero(' 1');", "0"},
9191
{"precision", "SELECT toBFloat16OrZero('12.3456789');", "12.375"}},
92-
.category{"Type Conversion"}});
92+
.category = FunctionDocumentation::Category::TypeConversion});
9393

9494
factory.registerFunction<detail::FunctionToFloat32OrZero>();
9595
factory.registerFunction<detail::FunctionToFloat64OrZero>();
@@ -142,7 +142,7 @@ Example of a loss of precision:
142142
{"invalid1", "SELECT toBFloat16OrNull('abc');", "NULL"},
143143
{"invalid2", "SELECT toBFloat16OrNull(' 1');", "NULL"},
144144
{"precision", "SELECT toBFloat16OrNull('12.3456789');", "12.375"}},
145-
.category{"Type Conversion"}});
145+
.category = FunctionDocumentation::Category::TypeConversion});
146146

147147
factory.registerFunction<detail::FunctionToFloat32OrNull>();
148148
factory.registerFunction<detail::FunctionToFloat64OrNull>();

0 commit comments

Comments
 (0)