2020-08-08 18:55:14 +00:00
|
|
|
#include <Parsers/formatSettingName.h>
|
|
|
|
#include <Common/StringUtils/StringUtils.h>
|
|
|
|
#include <Common/quoteString.h>
|
2021-10-02 07:13:14 +00:00
|
|
|
#include <base/find_symbols.h>
|
2020-11-09 16:05:40 +00:00
|
|
|
#include <IO/Operators.h>
|
2020-08-08 18:55:14 +00:00
|
|
|
|
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
2020-11-09 16:05:40 +00:00
|
|
|
void formatSettingName(const String & setting_name, WriteBuffer & out)
|
2020-08-08 18:55:14 +00:00
|
|
|
{
|
|
|
|
if (isValidIdentifier(setting_name))
|
|
|
|
{
|
|
|
|
out << setting_name;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::vector<std::string_view> parts;
|
|
|
|
splitInto<'.'>(parts, setting_name);
|
|
|
|
bool all_parts_are_identifiers = std::all_of(parts.begin(), parts.end(), isValidIdentifier);
|
|
|
|
if (all_parts_are_identifiers && !parts.empty())
|
|
|
|
{
|
|
|
|
bool need_dot = false;
|
|
|
|
for (const auto & part : parts)
|
|
|
|
{
|
|
|
|
if (std::exchange(need_dot, true))
|
|
|
|
out << ".";
|
|
|
|
out << part;
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
out << backQuote(setting_name);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|