Various fixes

This commit is contained in:
Robert Schulze 2023-04-26 20:33:52 +00:00
parent fb39dc3f19
commit d72030b876
No known key found for this signature in database
GPG Key ID: 26703B55FB13728A
2 changed files with 64 additions and 29 deletions

View File

@ -42,27 +42,65 @@ namespace DB
*
* Documentation does not support multiple languages.
* The only available language is English.
*
* TODO: Allow to specify Syntax, Argument(s) and a Returned Value.
* TODO: Organize Examples as a struct of ExampleName, ExampleQuery and ExampleResult.
*/
struct Documentation
{
using Description = std::string;
using Syntax = std::string;
using Argument = std::string;
using Arguments = std::vector<Argument>;
using ReturnedValue = std::string;
using ExampleName = std::string;
using ExampleQuery = std::string;
using Examples = std::map<ExampleName, ExampleQuery>;
using Category = std::string;
using Categories = std::vector<Category>;
using Related = std::string;
Description description;
Examples examples;
Categories categories;
Documentation(Description description_) : description(std::move(description_)) {}
Documentation(Description description_) : description(std::move(description_)) {} /// NOLINT
Documentation(Description description_, Examples examples_) : description(std::move(description_)), examples(std::move(examples_)) {}
Documentation(Description description_, Examples examples_, Categories categories_)
: description(std::move(description_)), examples(std::move(examples_)), categories(std::move(categories_)) {}
/// TODO: Please remove this constructor. Documentation should always be non-empty.
Documentation() {}
Documentation() = default;
std::string examplesAsString() const
{
std::string res;
for (const auto & [example_name, example_query] : examples)
{
res += example_name + ":\n\n";
res += "```sql\n";
res += example_query + "\n";
res += "```\n";
}
return res;
}
std::string categoriesAsString() const
{
if (categories.empty())
return "";
std::string res = categories[0];
for (const auto & category : categories)
res += ", " + category;
return res;
}
};
}

View File

@ -22,26 +22,6 @@ enum class FunctionOrigin : Int8
EXECUTABLE_USER_DEFINED = 2
};
std::string exampleMapToString( const std::map<std::string, std::string> &example )
// in the source, examples for functions are stored in a map. To
// create the documentation, we need to convert the map to a string.
{
std::string stringToReturn;
for (auto iter = example.begin(); iter != example.end(); ++iter){
stringToReturn.append("### ");
stringToReturn.append(iter->first);
stringToReturn.append("\n");
stringToReturn.append("```");
stringToReturn.append("\n");
stringToReturn.append(iter->second);
stringToReturn.append("\n");
stringToReturn.append("```");
stringToReturn.append("\n");
}
return stringToReturn;
}
namespace
{
template <typename Factory>
@ -79,19 +59,32 @@ namespace
if (factory.isAlias(name))
{
res_columns[6]->insertDefault();
res_columns[7]->insert(false);
res_columns[7]->insertDefault();
res_columns[8]->insertDefault();
res_columns[9]->insertDefault();
res_columns[10]->insertDefault();
res_columns[11]->insertDefault();
}
else
{
res_columns[6]->insert(factory.getDocumentation(name).description);
res_columns[7]->insert(exampleMapToString((factory.getDocumentation(name).examples)));
auto documentation = factory.getDocumentation(name);
res_columns[6]->insert(documentation.description);
res_columns[7]->insertDefault();
res_columns[8]->insertDefault();
res_columns[9]->insertDefault();
res_columns[10]->insert(documentation.examplesAsString());
res_columns[11]->insert(documentation.categoriesAsString());
}
}
else
{
{
res_columns[6]->insertDefault();
res_columns[7]->insert(false);
}
res_columns[7]->insertDefault();
res_columns[8]->insertDefault();
res_columns[9]->insertDefault();
res_columns[10]->insertDefault();
res_columns[11]->insertDefault();
}
}
}
@ -115,7 +108,11 @@ NamesAndTypesList StorageSystemFunctions::getNamesAndTypes()
{"create_query", std::make_shared<DataTypeString>()},
{"origin", std::make_shared<DataTypeEnum8>(getOriginEnumsAndValues())},
{"description", std::make_shared<DataTypeString>()},
{"example", std::make_shared<DataTypeString>()},
{"syntax", std::make_shared<DataTypeString>()},
{"arguments", std::make_shared<DataTypeString>()},
{"returned_value", std::make_shared<DataTypeString>()},
{"examples", std::make_shared<DataTypeString>()},
{"categories", std::make_shared<DataTypeString>()}
};
}