提交 90602b86 编写于 作者: V Vitaly Baranov

Make SettingsChanges a class.

上级 d152e84a
#include <Access/EnabledSettings.h>
#include <Common/SettingsChanges.h>
namespace DB
......
......@@ -2,7 +2,6 @@
#include <Core/Types.h>
#include <Core/UUID.h>
#include <Common/SettingsChanges.h>
#include <Access/SettingsConstraints.h>
#include <Access/SettingsProfileElement.h>
#include <boost/container/flat_set.hpp>
......
#include <Access/SettingsConstraints.h>
#include <Core/Settings.h>
#include <Common/FieldVisitors.h>
#include <Common/SettingsChanges.h>
#include <IO/WriteHelpers.h>
#include <Poco/Util/AbstractConfiguration.h>
......
#pragma once
#include <Core/Field.h>
#include <Common/SettingsChanges.h>
#include <common/StringRef.h>
#include <unordered_map>
......@@ -18,6 +17,8 @@ namespace Util
namespace DB
{
struct Settings;
struct SettingChange;
class SettingsChanges;
/** Checks if specified changes of settings are allowed or not.
* If the changes are not allowed (i.e. violates some constraints) this class throws an exception.
......
......@@ -4,6 +4,7 @@
#include <Access/SettingsProfile.h>
#include <Parsers/ASTSettingsProfileElement.h>
#include <Core/Settings.h>
#include <Common/SettingsChanges.h>
#include <IO/ReadHelpers.h>
#include <IO/WriteHelpers.h>
......
......@@ -9,8 +9,7 @@
namespace DB
{
struct Settings;
struct SettingChange;
using SettingsChanges = std::vector<SettingChange>;
class SettingsChanges;
class SettingsConstraints;
class ASTSettingsProfileElement;
class ASTSettingsProfileElements;
......
......@@ -2,6 +2,7 @@
#include <Access/AccessControlManager.h>
#include <Access/SettingsProfile.h>
#include <Core/Settings.h>
#include <Common/SettingsChanges.h>
#include <Common/quoteString.h>
#include <boost/range/adaptor/map.hpp>
#include <boost/range/algorithm_ext/push_back.hpp>
......
#include <Common/SettingsChanges.h>
namespace DB
{
namespace
{
SettingChange * find(SettingsChanges & changes, const std::string_view & name)
{
auto it = std::find_if(changes.begin(), changes.end(), [&name](const SettingChange & change) { return change.name == name; });
if (it == changes.end())
return nullptr;
return &*it;
}
const SettingChange * find(const SettingsChanges & changes, const std::string_view & name)
{
auto it = std::find_if(changes.begin(), changes.end(), [&name](const SettingChange & change) { return change.name == name; });
if (it == changes.end())
return nullptr;
return &*it;
}
}
bool SettingsChanges::tryGet(const std::string_view & name, Field & out_value) const
{
const auto * change = find(*this, name);
if (!change)
return false;
out_value = change->value;
return true;
}
const Field * SettingsChanges::tryGet(const std::string_view & name) const
{
const auto * change = find(*this, name);
if (!change)
return nullptr;
return &change->value;
}
Field * SettingsChanges::tryGet(const std::string_view & name)
{
auto * change = find(*this, name);
if (!change)
return nullptr;
return &change->value;
}
}
......@@ -5,21 +5,28 @@
namespace DB
{
struct SettingChange
{
String name;
Field value;
SettingChange() {}
SettingChange(const String & name_, const Field value_)
: name(name_)
, value(value_) {}
SettingChange() {}
SettingChange(const std::string_view & name_, const Field & value_) : name(name_), value(value_) {}
SettingChange(const std::string_view & name_, Field && value_) : name(name_), value(std::move(value_)) {}
friend bool operator ==(const SettingChange & lhs, const SettingChange & rhs) { return (lhs.name == rhs.name) && (lhs.value == rhs.value); }
friend bool operator !=(const SettingChange & lhs, const SettingChange & rhs) { return !(lhs == rhs); }
};
using SettingsChanges = std::vector<SettingChange>;
class SettingsChanges : public std::vector<SettingChange>
{
public:
using std::vector<SettingChange>::vector;
bool tryGet(const std::string_view & name, Field & out_value) const;
const Field * tryGet(const std::string_view & name) const;
Field * tryGet(const std::string_view & name);
};
}
......@@ -75,6 +75,7 @@ SRCS(
RWLock.cpp
SensitiveDataMasker.cpp
setThreadName.cpp
SettingsChanges.cpp
SharedLibrary.cpp
ShellCommand.cpp
StackTrace.cpp
......
......@@ -14,7 +14,7 @@ namespace DB
class Field;
struct SettingChange;
using SettingsChanges = std::vector<SettingChange>;
class SettingsChanges;
class ReadBuffer;
class WriteBuffer;
enum class SettingsBinaryFormat;
......
......@@ -8,7 +8,7 @@ namespace DB
class ASTSelectQuery;
struct SettingChange;
using SettingsChanges = std::vector<SettingChange>;
class SettingsChanges;
/// Pushdown SETTINGS clause that goes after FORMAT to the SELECT query:
/// (since settings after FORMAT parsed separatelly not in the ParserSelectQuery but in ParserQueryWithOutput)
......
......@@ -37,8 +37,6 @@ using StorageActionBlockType = size_t;
class ASTCreateQuery;
struct Settings;
struct SettingChange;
using SettingsChanges = std::vector<SettingChange>;
class AlterCommands;
class MutationCommands;
......
......@@ -5,6 +5,7 @@
#include <Storages/Kafka/Buffer_fwd.h>
#include <Storages/Kafka/KafkaSettings.h>
#include <Interpreters/Context.h>
#include <Common/SettingsChanges.h>
#include <Poco/Semaphore.h>
#include <ext/shared_ptr_helper.h>
......
......@@ -1472,24 +1472,22 @@ void MergeTreeData::checkAlterIsPossible(const AlterCommands & commands, const S
const auto & new_changes = new_metadata.settings_changes->as<const ASTSetQuery &>().changes;
for (const auto & changed_setting : new_changes)
{
if (MergeTreeSettings::findIndex(changed_setting.name) == MergeTreeSettings::npos)
throw Exception{"Storage '" + getName() + "' doesn't have setting '" + changed_setting.name + "'",
const auto & setting_name = changed_setting.name;
const auto & new_value = changed_setting.value;
if (MergeTreeSettings::findIndex(setting_name) == MergeTreeSettings::npos)
throw Exception{"Storage '" + getName() + "' doesn't have setting '" + setting_name + "'",
ErrorCodes::UNKNOWN_SETTING};
auto comparator = [&changed_setting](const auto & change) { return change.name == changed_setting.name; };
const Field * current_value = current_changes.tryGet(setting_name);
auto current_setting_it
= std::find_if(current_changes.begin(), current_changes.end(), comparator);
if ((current_setting_it == current_changes.end() || *current_setting_it != changed_setting)
&& MergeTreeSettings::isReadonlySetting(changed_setting.name))
if ((!current_value || *current_value != new_value)
&& MergeTreeSettings::isReadonlySetting(setting_name))
{
throw Exception{"Setting '" + changed_setting.name + "' is readonly for storage '" + getName() + "'",
throw Exception{"Setting '" + setting_name + "' is readonly for storage '" + getName() + "'",
ErrorCodes::READONLY_SETTING};
}
if (current_setting_it == current_changes.end()
&& MergeTreeSettings::isPartFormatSetting(changed_setting.name))
if (!current_value && MergeTreeSettings::isPartFormatSetting(setting_name))
{
MergeTreeSettings copy = *getSettings();
copy.applyChange(changed_setting);
......@@ -1498,8 +1496,8 @@ void MergeTreeData::checkAlterIsPossible(const AlterCommands & commands, const S
throw Exception("Can't change settings. Reason: " + reason, ErrorCodes::NOT_IMPLEMENTED);
}
if (changed_setting.name == "storage_policy")
checkStoragePolicy(global_context.getStoragePolicy(changed_setting.value.safeGet<String>()));
if (setting_name == "storage_policy")
checkStoragePolicy(global_context.getStoragePolicy(new_value.safeGet<String>()));
}
}
......
......@@ -2,7 +2,6 @@
#include <Core/Defines.h>
#include <Core/SettingsCollection.h>
#include <Common/SettingsChanges.h>
namespace Poco
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册