mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-10 09:32:06 +00:00
Merge pull request #44411 from thevar1able/fix-settings-constraints
Fix settings constraints
This commit is contained in:
commit
93375fc3e5
@ -75,6 +75,10 @@ void SettingsProfileElement::init(const ASTSettingsProfileElement & ast, const A
|
||||
}
|
||||
}
|
||||
|
||||
bool SettingsProfileElement::isConstraint() const
|
||||
{
|
||||
return this->writability || !this->min_value.isNull() || !this->max_value.isNull();
|
||||
}
|
||||
|
||||
std::shared_ptr<ASTSettingsProfileElement> SettingsProfileElement::toAST() const
|
||||
{
|
||||
@ -213,7 +217,7 @@ SettingsConstraints SettingsProfileElements::toSettingsConstraints(const AccessC
|
||||
{
|
||||
SettingsConstraints res{access_control};
|
||||
for (const auto & elem : *this)
|
||||
if (!elem.setting_name.empty() && elem.setting_name != ALLOW_BACKUP_SETTING_NAME)
|
||||
if (!elem.setting_name.empty() && elem.isConstraint() && elem.setting_name != ALLOW_BACKUP_SETTING_NAME)
|
||||
res.set(
|
||||
elem.setting_name,
|
||||
elem.min_value,
|
||||
|
@ -44,6 +44,8 @@ struct SettingsProfileElement
|
||||
std::shared_ptr<ASTSettingsProfileElement> toAST() const;
|
||||
std::shared_ptr<ASTSettingsProfileElement> toASTWithNames(const AccessControl & access_control) const;
|
||||
|
||||
bool isConstraint() const;
|
||||
|
||||
private:
|
||||
void init(const ASTSettingsProfileElement & ast, const AccessControl * access_control);
|
||||
};
|
||||
|
@ -0,0 +1,22 @@
|
||||
<clickhouse>
|
||||
<profiles>
|
||||
<default>
|
||||
<constraints>
|
||||
<log_queries>
|
||||
<readonly>1</readonly>
|
||||
</log_queries>
|
||||
</constraints>
|
||||
<log_queries>1</log_queries>
|
||||
</default>
|
||||
</profiles>
|
||||
<users>
|
||||
<test_profile_settings_and_constraints_order>
|
||||
<password></password>
|
||||
<networks>
|
||||
<ip>::/0</ip>
|
||||
</networks>
|
||||
<profile>default</profile>
|
||||
<quota>default</quota>
|
||||
</test_profile_settings_and_constraints_order>
|
||||
</users>
|
||||
</clickhouse>
|
@ -0,0 +1,22 @@
|
||||
<clickhouse>
|
||||
<profiles>
|
||||
<default>
|
||||
<log_queries>1</log_queries>
|
||||
<constraints>
|
||||
<log_queries>
|
||||
<readonly>1</readonly>
|
||||
</log_queries>
|
||||
</constraints>
|
||||
</default>
|
||||
</profiles>
|
||||
<users>
|
||||
<test_profile_settings_and_constraints_order>
|
||||
<password/>
|
||||
<networks>
|
||||
<ip>::/0</ip>
|
||||
</networks>
|
||||
<profile>default</profile>
|
||||
<quota>default</quota>
|
||||
</test_profile_settings_and_constraints_order>
|
||||
</users>
|
||||
</clickhouse>
|
@ -0,0 +1,40 @@
|
||||
import pytest
|
||||
|
||||
from helpers.client import QueryRuntimeException
|
||||
from helpers.cluster import ClickHouseCluster
|
||||
from helpers.test_tools import TSV
|
||||
|
||||
cluster = ClickHouseCluster(__file__)
|
||||
node1 = cluster.add_instance("node1", user_configs=["configs/constraints_first.xml"])
|
||||
node2 = cluster.add_instance("node2", user_configs=["configs/constraints_last.xml"])
|
||||
|
||||
|
||||
@pytest.fixture(scope="module")
|
||||
def started_cluster():
|
||||
try:
|
||||
cluster.start()
|
||||
|
||||
yield cluster
|
||||
|
||||
finally:
|
||||
cluster.shutdown()
|
||||
|
||||
|
||||
def test_profile_settings_and_constraints_order(started_cluster):
|
||||
query = "SELECT name, readonly FROM system.settings WHERE name == 'log_queries'"
|
||||
expected = """\
|
||||
log_queries 1"""
|
||||
|
||||
settings = node1.query(
|
||||
query,
|
||||
user="test_profile_settings_and_constraints_order",
|
||||
)
|
||||
|
||||
assert TSV(settings) == TSV(expected)
|
||||
|
||||
settings = node2.query(
|
||||
query,
|
||||
user="test_profile_settings_and_constraints_order",
|
||||
)
|
||||
|
||||
assert TSV(settings) == TSV(expected)
|
Loading…
Reference in New Issue
Block a user