mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-27 01:51:59 +00:00
fixes after review
This commit is contained in:
parent
2306bd74d7
commit
9ccfda73ae
@ -140,14 +140,16 @@ bool getNewValueToCheck(const T & current_settings, SettingChange & change, Fiel
|
||||
|
||||
if (throw_on_failure)
|
||||
new_value = T::castValueUtil(change.name, change.value);
|
||||
|
||||
try
|
||||
else
|
||||
{
|
||||
new_value = T::castValueUtil(change.name, change.value);
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
return false;
|
||||
try
|
||||
{
|
||||
new_value = T::castValueUtil(change.name, change.value);
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/// Setting isn't checked if value has not changed.
|
||||
|
@ -9,7 +9,7 @@
|
||||
// `resolveSetting(full_name)` is used to resolve setting name and choose which class is to be used.
|
||||
// Templated lambda syntax should be used:
|
||||
//
|
||||
// return resolveSetting(name, [] <class T> (std::string_view name, Overload<T>) -> auto
|
||||
// return resolveSetting(name, [] <typename T> (std::string_view name, SettingsType<T>)
|
||||
// {
|
||||
// return T::castValueUtil(name, value); // T will be deduced into `Settings`, `MergeTreeSettings`, ...
|
||||
// });
|
||||
@ -20,27 +20,27 @@ namespace DB
|
||||
|
||||
constexpr std::string_view MERGE_TREE_SETTINGS_PREFIX = "merge_tree_";
|
||||
|
||||
template <class T> struct Overload {};
|
||||
template <typename T> struct SettingsType {};
|
||||
|
||||
// Resolve setting name and call function `f` back with short name and class
|
||||
template <class F>
|
||||
template <typename F>
|
||||
auto resolveSetting(std::string_view full_name, F && f)
|
||||
{
|
||||
if (full_name.starts_with(MERGE_TREE_SETTINGS_PREFIX))
|
||||
{
|
||||
std::string_view short_name = static_cast<std::string_view>(full_name).substr(MERGE_TREE_SETTINGS_PREFIX.size());
|
||||
if (MergeTreeSettings::hasBuiltin(short_name)) // Check is required because `Settings` also contain names starting with 'merge_tree_' prefix
|
||||
return f(short_name, Overload<MergeTreeSettings>());
|
||||
return f(short_name, SettingsType<MergeTreeSettings>());
|
||||
}
|
||||
// NOTE: other setting name resolution rules are to be added here
|
||||
|
||||
// If no rule works - use global namespace
|
||||
return f(full_name, Overload<Settings>());
|
||||
return f(full_name, SettingsType<Settings>());
|
||||
}
|
||||
|
||||
inline Field settingCastValueUtil(std::string_view full_name, const Field & value)
|
||||
{
|
||||
return resolveSetting(full_name, [&] <class T> (std::string_view short_name, Overload<T>)
|
||||
return resolveSetting(full_name, [&] <typename T> (std::string_view short_name, SettingsType<T>)
|
||||
{
|
||||
return T::castValueUtil(short_name, value);
|
||||
});
|
||||
@ -48,7 +48,7 @@ inline Field settingCastValueUtil(std::string_view full_name, const Field & valu
|
||||
|
||||
inline String settingValueToStringUtil(std::string_view full_name, const Field & value)
|
||||
{
|
||||
return resolveSetting(full_name, [&] <class T> (std::string_view short_name, Overload<T>)
|
||||
return resolveSetting(full_name, [&] <typename T> (std::string_view short_name, SettingsType<T>)
|
||||
{
|
||||
return T::valueToStringUtil(short_name, value);
|
||||
});
|
||||
@ -56,7 +56,7 @@ inline String settingValueToStringUtil(std::string_view full_name, const Field &
|
||||
|
||||
inline Field settingStringToValueUtil(std::string_view full_name, const String & str)
|
||||
{
|
||||
return resolveSetting(full_name, [&] <class T> (std::string_view short_name, Overload<T>)
|
||||
return resolveSetting(full_name, [&] <typename T> (std::string_view short_name, SettingsType<T>)
|
||||
{
|
||||
return T::stringToValueUtil(short_name, str);
|
||||
});
|
||||
@ -64,7 +64,7 @@ inline Field settingStringToValueUtil(std::string_view full_name, const String &
|
||||
|
||||
inline bool settingIsBuiltin(std::string_view full_name)
|
||||
{
|
||||
return resolveSetting(full_name, [&] <class T> (std::string_view short_name, Overload<T>)
|
||||
return resolveSetting(full_name, [&] <typename T> (std::string_view short_name, SettingsType<T>)
|
||||
{
|
||||
return T::hasBuiltin(short_name);
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user