mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-10 09:32:06 +00:00
Extract common code
This commit is contained in:
parent
3a8ba689f2
commit
60e5ee84c2
@ -860,12 +860,25 @@ using AliasMap = std::unordered_map<std::string_view, std::string_view>;
|
||||
}; \
|
||||
static constexpr bool allow_custom_settings = ALLOW_CUSTOM_SETTINGS; \
|
||||
\
|
||||
static inline const AliasMap settings_aliases = \
|
||||
static inline const AliasMap aliases_to_settings = \
|
||||
DefineAliases() LIST_OF_SETTINGS_MACRO(ALIAS_TO, ALIAS_FROM); \
|
||||
\
|
||||
using SettingsToAliasesMap = std::unordered_map<std::string_view, std::vector<std::string_view>>; \
|
||||
static inline const SettingsToAliasesMap & settingsToAliases() \
|
||||
{ \
|
||||
static SettingsToAliasesMap setting_to_aliases_mapping = [] \
|
||||
{ \
|
||||
std::unordered_map<std::string_view, std::vector<std::string_view>> map; \
|
||||
for (const auto & [alias, destination] : aliases_to_settings) \
|
||||
map[destination].push_back(alias); \
|
||||
return map; \
|
||||
}(); \
|
||||
return setting_to_aliases_mapping; \
|
||||
} \
|
||||
\
|
||||
static std::string_view resolveName(std::string_view name) \
|
||||
{ \
|
||||
if (auto it = settings_aliases.find(name); it != settings_aliases.end()) \
|
||||
if (auto it = aliases_to_settings.find(name); it != aliases_to_settings.end()) \
|
||||
return it->second; \
|
||||
return name; \
|
||||
} \
|
||||
|
@ -84,17 +84,13 @@ void Settings::dumpToMapColumn(IColumn * column, bool changed_only)
|
||||
|
||||
void Settings::addProgramOptions(boost::program_options::options_description & options)
|
||||
{
|
||||
// we can have multiple aliases to the same setting
|
||||
std::unordered_map<std::string_view, std::vector<std::string_view>> setting_to_alias_mapping;
|
||||
for (const auto & [alias, destination] : SettingsTraits::settings_aliases)
|
||||
setting_to_alias_mapping[destination].push_back(alias);
|
||||
|
||||
const auto & settings_to_aliases = Settings::Traits::settingsToAliases();
|
||||
for (const auto & field : all())
|
||||
{
|
||||
std::string_view name = field.getName();
|
||||
addProgramOption(options, name, field);
|
||||
|
||||
if (auto it = setting_to_alias_mapping.find(name); it != setting_to_alias_mapping.end())
|
||||
if (auto it = settings_to_aliases.find(name); it != settings_to_aliases.end())
|
||||
{
|
||||
for (const auto alias : it->second)
|
||||
addProgramOption(options, alias, field);
|
||||
@ -104,17 +100,13 @@ void Settings::addProgramOptions(boost::program_options::options_description & o
|
||||
|
||||
void Settings::addProgramOptionsAsMultitokens(boost::program_options::options_description & options)
|
||||
{
|
||||
// we can have multiple aliases to the same setting
|
||||
std::unordered_map<std::string_view, std::vector<std::string_view>> setting_to_alias_mapping;
|
||||
for (const auto & [alias, destination] : SettingsTraits::settings_aliases)
|
||||
setting_to_alias_mapping[destination].push_back(alias);
|
||||
|
||||
const auto & settings_to_aliases = Settings::Traits::settingsToAliases();
|
||||
for (const auto & field : all())
|
||||
{
|
||||
std::string_view name = field.getName();
|
||||
addProgramOptionAsMultitoken(options, name, field);
|
||||
|
||||
if (auto it = setting_to_alias_mapping.find(name); it != setting_to_alias_mapping.end())
|
||||
if (auto it = settings_to_aliases.find(name); it != settings_to_aliases.end())
|
||||
{
|
||||
for (const auto alias : it->second)
|
||||
addProgramOptionAsMultitoken(options, alias, field);
|
||||
|
@ -55,11 +55,7 @@ void StorageSystemSettings::fillData(MutableColumns & res_columns, ContextPtr co
|
||||
res_columns[7]->insert(setting.getTypeName());
|
||||
};
|
||||
|
||||
// we can have multiple aliases to the same setting
|
||||
std::unordered_map<std::string_view, std::vector<std::string_view>> setting_to_alias_mapping;
|
||||
for (const auto & [alias, destination] : SettingsTraits::settings_aliases)
|
||||
setting_to_alias_mapping[destination].push_back(alias);
|
||||
|
||||
const auto & settings_to_aliases = Settings::Traits::settingsToAliases();
|
||||
for (const auto & setting : settings.all())
|
||||
{
|
||||
const auto & setting_name = setting.getName();
|
||||
@ -68,7 +64,7 @@ void StorageSystemSettings::fillData(MutableColumns & res_columns, ContextPtr co
|
||||
fill_data_for_setting(setting_name, setting);
|
||||
res_columns[8]->insert("");
|
||||
|
||||
if (auto it = setting_to_alias_mapping.find(setting_name); it != setting_to_alias_mapping.end())
|
||||
if (auto it = settings_to_aliases.find(setting_name); it != settings_to_aliases.end())
|
||||
{
|
||||
for (const auto alias : it->second)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user