diff --git a/src/Common/SettingsChanges.cpp b/src/Common/SettingsChanges.cpp index 52ab23dde9e..0cfa6804e02 100644 --- a/src/Common/SettingsChanges.cpp +++ b/src/Common/SettingsChanges.cpp @@ -36,9 +36,31 @@ String SettingChange::getValueString() const return convertFieldToString(field_value); } -void SettingChange::throwIfASTValue() const +const Field & SettingChange::getFieldValue() const { - if (getASTValue() != nullptr) + throwIfASTValueNotConvertedToField(); + return field_value; +} + +Field & SettingChange::getFieldValue() +{ + throwIfASTValueNotConvertedToField(); + return field_value; +} + +void SettingChange::setFieldValue(const Field & field) +{ + field_value = field; +} + +void SettingChange::setASTValue(const ASTPtr & ast) +{ + ast_value = ast ? ast->clone() : ast; +} + +void SettingChange::throwIfASTValueNotConvertedToField() const +{ + if (getASTValue() != nullptr && field_value == Field{}) throw Exception( ErrorCodes::LOGICAL_ERROR, "AST value of the setting must be converted to Field value"); diff --git a/src/Common/SettingsChanges.h b/src/Common/SettingsChanges.h index e83a7b7a695..d0d72fd725c 100644 --- a/src/Common/SettingsChanges.h +++ b/src/Common/SettingsChanges.h @@ -30,19 +30,19 @@ public: friend bool operator !=(const SettingChange & lhs, const SettingChange & rhs) { return !(lhs == rhs); } - void throwIfASTValue() const; + void throwIfASTValueNotConvertedToField() const; const String & getName() const { return name; } String & getName() { return name; } - const Field & getFieldValue() const { throwIfASTValue(); return field_value; } - Field & getFieldValue() { throwIfASTValue(); return field_value; } + const Field & getFieldValue() const; + Field & getFieldValue(); const ASTPtr & getASTValue() const { return ast_value; } ASTPtr & getASTValue() { return ast_value; } - void setFieldValue(const Field & field) { field_value = field; } - void setASTValue(const ASTPtr & ast) { ast_value = ast->clone(); } + void setFieldValue(const Field & field); + void setASTValue(const ASTPtr & ast); String getValueString() const; }; diff --git a/src/Storages/MergeTree/registerStorageMergeTree.cpp b/src/Storages/MergeTree/registerStorageMergeTree.cpp index 94cd3ddf872..83076851b43 100644 --- a/src/Storages/MergeTree/registerStorageMergeTree.cpp +++ b/src/Storages/MergeTree/registerStorageMergeTree.cpp @@ -616,7 +616,6 @@ static StoragePtr create(const StorageFactory::Arguments & args) const auto & ast_value = assert_cast(*change.getASTValue()); auto value = createDiskFromDiskAST(ast_value, context); change.setFieldValue(value); - change.setASTValue(nullptr); break; } }