mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-10 01:25:21 +00:00
Use references while iterating through settings.
This commit is contained in:
parent
d4266d9619
commit
a804f9499d
@ -232,7 +232,7 @@ private:
|
||||
context.setQueryParameters(query_parameters);
|
||||
|
||||
/// settings and limits could be specified in config file, but passed settings has higher priority
|
||||
for (auto setting : context.getSettingsRef().allUnchanged())
|
||||
for (const auto & setting : context.getSettingsRef().allUnchanged())
|
||||
{
|
||||
const auto & name = setting.getName();
|
||||
if (config().has(name))
|
||||
@ -2252,7 +2252,7 @@ public:
|
||||
|
||||
/// Copy settings-related program options to config.
|
||||
/// TODO: Is this code necessary?
|
||||
for (auto setting : context.getSettingsRef().all())
|
||||
for (const auto & setting : context.getSettingsRef().all())
|
||||
{
|
||||
const auto & name = setting.getName();
|
||||
if (options.count(name))
|
||||
|
@ -223,7 +223,7 @@ void checkForUserSettingsAtTopLevel(const Poco::Util::AbstractConfiguration & co
|
||||
return;
|
||||
|
||||
Settings settings;
|
||||
for (auto setting : settings.all())
|
||||
for (const auto & setting : settings.all())
|
||||
{
|
||||
const auto & name = setting.getName();
|
||||
if (config.has(name))
|
||||
|
@ -104,13 +104,10 @@ public:
|
||||
|
||||
private:
|
||||
friend class BaseSettings;
|
||||
SettingFieldRef(const typename Traits::Data & data_, const typename Traits::Accessor & accessor_, size_t index_) : data(&data_), accessor(&accessor_), index(index_) {}
|
||||
SettingFieldRef(const CustomSettingMap::mapped_type & custom_setting_);
|
||||
|
||||
const typename Traits::Data * data = nullptr;
|
||||
const typename Traits::Accessor * accessor = nullptr;
|
||||
size_t index = 0;
|
||||
std::conditional_t<Traits::allow_custom_settings, const CustomSettingMap::mapped_type*, boost::blank> custom_setting = {};
|
||||
const BaseSettings * settings;
|
||||
const typename Traits::Accessor * accessor;
|
||||
size_t index;
|
||||
std::conditional_t<Traits::allow_custom_settings, const CustomSettingMap::mapped_type*, boost::blank> custom_setting;
|
||||
};
|
||||
|
||||
enum SkipFlags
|
||||
@ -128,7 +125,7 @@ public:
|
||||
public:
|
||||
Iterator & operator++();
|
||||
Iterator operator++(int);
|
||||
SettingFieldRef operator *() const;
|
||||
const SettingFieldRef & operator *() const { return field_ref; }
|
||||
|
||||
bool operator ==(const Iterator & other) const;
|
||||
bool operator !=(const Iterator & other) const { return !(*this == other); }
|
||||
@ -137,10 +134,9 @@ public:
|
||||
friend class BaseSettings;
|
||||
Iterator(const BaseSettings & settings_, const typename Traits::Accessor & accessor_, SkipFlags skip_flags_);
|
||||
void doSkip();
|
||||
void setPointerToCustomSetting();
|
||||
|
||||
const BaseSettings * settings = nullptr;
|
||||
const typename Traits::Accessor * accessor = nullptr;
|
||||
size_t index;
|
||||
SettingFieldRef field_ref;
|
||||
std::conditional_t<Traits::allow_custom_settings, CustomSettingMap::const_iterator, boost::blank> custom_settings_iterator;
|
||||
SkipFlags skip_flags;
|
||||
};
|
||||
@ -557,13 +553,20 @@ const SettingFieldCustom * BaseSettings<Traits_>::tryGetCustomSetting(const std:
|
||||
|
||||
template <typename Traits_>
|
||||
BaseSettings<Traits_>::Iterator::Iterator(const BaseSettings & settings_, const typename Traits::Accessor & accessor_, SkipFlags skip_flags_)
|
||||
: settings(&settings_), accessor(&accessor_), skip_flags(skip_flags_)
|
||||
: skip_flags(skip_flags_)
|
||||
{
|
||||
field_ref.settings = &settings_;
|
||||
field_ref.accessor = &accessor_;
|
||||
auto & index = field_ref.index;
|
||||
|
||||
if (skip_flags == SKIP_ALL)
|
||||
{
|
||||
index = accessor->size();
|
||||
index = accessor_.size();
|
||||
if constexpr (Traits::allow_custom_settings)
|
||||
custom_settings_iterator = settings->custom_settings_map.end();
|
||||
{
|
||||
custom_settings_iterator = settings_.custom_settings_map.end();
|
||||
field_ref.custom_setting = nullptr;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
@ -575,25 +578,28 @@ BaseSettings<Traits_>::Iterator::Iterator(const BaseSettings & settings_, const
|
||||
}
|
||||
|
||||
if (skip_flags & SKIP_BUILTIN)
|
||||
index = accessor->size();
|
||||
index = accessor_.size();
|
||||
else
|
||||
index = 0;
|
||||
|
||||
if constexpr (Traits::allow_custom_settings)
|
||||
{
|
||||
if (skip_flags & SKIP_CUSTOM)
|
||||
custom_settings_iterator = settings->custom_settings_map.end();
|
||||
custom_settings_iterator = settings_.custom_settings_map.end();
|
||||
else
|
||||
custom_settings_iterator = settings->custom_settings_map.begin();
|
||||
custom_settings_iterator = settings_.custom_settings_map.begin();
|
||||
}
|
||||
|
||||
doSkip();
|
||||
setPointerToCustomSetting();
|
||||
}
|
||||
|
||||
template <typename Traits_>
|
||||
typename BaseSettings<Traits_>::Iterator & BaseSettings<Traits_>::Iterator::operator++()
|
||||
{
|
||||
if (index != accessor->size())
|
||||
const auto & accessor = *field_ref.accessor;
|
||||
auto & index = field_ref.index;
|
||||
if (index != accessor.size())
|
||||
++index;
|
||||
else
|
||||
{
|
||||
@ -601,6 +607,7 @@ typename BaseSettings<Traits_>::Iterator & BaseSettings<Traits_>::Iterator::oper
|
||||
++custom_settings_iterator;
|
||||
}
|
||||
doSkip();
|
||||
setPointerToCustomSetting();
|
||||
return *this;
|
||||
}
|
||||
|
||||
@ -612,32 +619,39 @@ typename BaseSettings<Traits_>::Iterator BaseSettings<Traits_>::Iterator::operat
|
||||
return res;
|
||||
}
|
||||
|
||||
template <typename Traits_>
|
||||
typename BaseSettings<Traits_>::SettingFieldRef BaseSettings<Traits_>::Iterator::operator*() const
|
||||
{
|
||||
if constexpr (Traits::allow_custom_settings)
|
||||
{
|
||||
if (index == accessor->size())
|
||||
return {custom_settings_iterator->second};
|
||||
}
|
||||
return {*settings, *accessor, index};
|
||||
}
|
||||
|
||||
template <typename Traits_>
|
||||
void BaseSettings<Traits_>::Iterator::doSkip()
|
||||
{
|
||||
const auto & accessor = *field_ref.accessor;
|
||||
const auto & settings = *field_ref.settings;
|
||||
auto & index = field_ref.index;
|
||||
if (skip_flags & SKIP_CHANGED)
|
||||
{
|
||||
while ((index != accessor->size()) && accessor->isValueChanged(*settings, index))
|
||||
while ((index != accessor.size()) && accessor.isValueChanged(settings, index))
|
||||
++index;
|
||||
}
|
||||
else if (skip_flags & SKIP_UNCHANGED)
|
||||
{
|
||||
while ((index != accessor->size()) && !accessor->isValueChanged(*settings, index))
|
||||
while ((index != accessor.size()) && !accessor.isValueChanged(settings, index))
|
||||
++index;
|
||||
}
|
||||
}
|
||||
|
||||
template <typename Traits_>
|
||||
void BaseSettings<Traits_>::Iterator::setPointerToCustomSetting()
|
||||
{
|
||||
if constexpr (Traits::allow_custom_settings)
|
||||
{
|
||||
const auto & accessor = *field_ref.accessor;
|
||||
const auto & settings = *field_ref.settings;
|
||||
const auto & index = field_ref.index;
|
||||
if ((index == accessor.size()) && (custom_settings_iterator != settings.custom_settings_map.end()))
|
||||
field_ref.custom_setting = &custom_settings_iterator->second;
|
||||
else
|
||||
field_ref.custom_setting = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
template <typename Traits_>
|
||||
bool BaseSettings<Traits_>::Iterator::operator ==(const typename BaseSettings<Traits_>::Iterator & other) const
|
||||
{
|
||||
@ -646,14 +660,7 @@ bool BaseSettings<Traits_>::Iterator::operator ==(const typename BaseSettings<Tr
|
||||
if (custom_settings_iterator != other.custom_settings_iterator)
|
||||
return false;
|
||||
}
|
||||
return ((index == other.index) && (settings == other.settings));
|
||||
}
|
||||
|
||||
template <typename Traits_>
|
||||
BaseSettings<Traits_>::SettingFieldRef::SettingFieldRef(const CustomSettingMap::mapped_type & custom_setting_)
|
||||
{
|
||||
if constexpr (Traits_::allow_custom_settings)
|
||||
custom_setting = &custom_setting_;
|
||||
return ((field_ref.index == other.field_ref.index) && (field_ref.settings == other.field_ref.settings));
|
||||
}
|
||||
|
||||
template <typename Traits_>
|
||||
@ -675,7 +682,7 @@ Field BaseSettings<Traits_>::SettingFieldRef::getValue() const
|
||||
if (custom_setting)
|
||||
return static_cast<Field>(custom_setting->second);
|
||||
}
|
||||
return accessor->getValue(*data, index);
|
||||
return accessor->getValue(*settings, index);
|
||||
}
|
||||
|
||||
template <typename Traits_>
|
||||
@ -686,7 +693,7 @@ String BaseSettings<Traits_>::SettingFieldRef::getValueString() const
|
||||
if (custom_setting)
|
||||
return custom_setting->second.toString();
|
||||
}
|
||||
return accessor->getValueString(*data, index);
|
||||
return accessor->getValueString(*settings, index);
|
||||
}
|
||||
|
||||
template <typename Traits_>
|
||||
@ -697,7 +704,7 @@ bool BaseSettings<Traits_>::SettingFieldRef::isValueChanged() const
|
||||
if (custom_setting)
|
||||
return true;
|
||||
}
|
||||
return accessor->isValueChanged(*data, index);
|
||||
return accessor->isValueChanged(*settings, index);
|
||||
}
|
||||
|
||||
template <typename Traits_>
|
||||
|
@ -65,7 +65,7 @@ void Settings::dumpToArrayColumns(IColumn * column_names_, IColumn * column_valu
|
||||
|
||||
size_t count = 0;
|
||||
|
||||
for (auto setting : all(changed_only ? SKIP_UNCHANGED : SKIP_NONE))
|
||||
for (const auto & setting : all(changed_only ? SKIP_UNCHANGED : SKIP_NONE))
|
||||
{
|
||||
if (column_names)
|
||||
{
|
||||
@ -95,7 +95,7 @@ void Settings::dumpToArrayColumns(IColumn * column_names_, IColumn * column_valu
|
||||
|
||||
void Settings::addProgramOptions(boost::program_options::options_description & options)
|
||||
{
|
||||
for (auto field : all())
|
||||
for (const auto & field : all())
|
||||
{
|
||||
const std::string_view name = field.getName();
|
||||
auto on_program_option
|
||||
|
@ -169,7 +169,7 @@ SettingsChanges StorageKafka::createSettingsAdjustments()
|
||||
if (!schema_name.empty())
|
||||
result.emplace_back("format_schema", schema_name);
|
||||
|
||||
for (auto setting : *kafka_settings)
|
||||
for (const auto & setting : *kafka_settings)
|
||||
{
|
||||
const auto & name = setting.getName();
|
||||
if (name.find("kafka_") == std::string::npos)
|
||||
|
@ -20,7 +20,7 @@ NamesAndTypesList SystemMergeTreeSettings::getNamesAndTypes()
|
||||
|
||||
void SystemMergeTreeSettings::fillData(MutableColumns & res_columns, const Context & context, const SelectQueryInfo &) const
|
||||
{
|
||||
for (auto setting : context.getMergeTreeSettings().all())
|
||||
for (const auto & setting : context.getMergeTreeSettings().all())
|
||||
{
|
||||
res_columns[0]->insert(setting.getName());
|
||||
res_columns[1]->insert(setting.getValueString());
|
||||
|
@ -30,7 +30,7 @@ void StorageSystemSettings::fillData(MutableColumns & res_columns, const Context
|
||||
{
|
||||
const Settings & settings = context.getSettingsRef();
|
||||
auto settings_constraints = context.getSettingsConstraints();
|
||||
for (auto setting : settings.all())
|
||||
for (const auto & setting : settings.all())
|
||||
{
|
||||
const auto & setting_name = setting.getName();
|
||||
res_columns[0]->insert(setting_name);
|
||||
|
Loading…
Reference in New Issue
Block a user