fix tests

This commit is contained in:
pufit 2024-11-20 01:25:11 -05:00
parent 026aa8b2ee
commit ebb19cd9b5
6 changed files with 94 additions and 112 deletions

View File

@ -131,20 +131,12 @@ bool ASTSettingsProfileElements::empty() const
size_t ASTSettingsProfileElements::getNumberOfSettings() const
{
size_t count = 0;
for (const auto & element : elements)
if (!element->setting_name.empty())
++count;
return count;
return std::count_if(elements.begin(), elements.end(), [](const auto & element){ return !element->setting_name.empty(); });
}
size_t ASTSettingsProfileElements::getNumberOfProfiles() const
{
size_t count = 0;
for (const auto & element : elements)
if (!element->parent_profile.empty())
++count;
return count;
return std::count_if(elements.begin(), elements.end(), [](const auto & element){ return !element->parent_profile.empty(); });
}

View File

@ -307,53 +307,43 @@ bool ParserAlterSettingsProfileElements::parseImpl(Pos & pos, ASTPtr & node, Exp
else
{
/// new style: "MODIFY SETTINGS ..., ADD PROFILES ..., DROP PROFILES ..., DROP SETTINGS ..."
std::string_view mode;
std::string_view submode;
std::string_view action;
std::string_view target;
auto parse_element = [&]
{
if (ParserKeyword{Keyword::ADD}.ignore(pos, expected))
{
mode = "ADD";
submode = "";
}
action = "ADD";
else if (ParserKeyword{Keyword::DROP}.ignore(pos, expected))
{
mode = "DROP";
submode = "";
}
action = "DROP";
else if (ParserKeyword{Keyword::MODIFY}.ignore(pos, expected))
{
mode = "MODIFY";
submode = "";
}
action = "MODIFY";
if (!mode.empty())
if (!action.empty())
{
if (ParserKeyword{Keyword::ALL_PROFILES}.ignore(pos, expected))
submode = "ALL PROFILES";
target = "ALL PROFILES";
else if (ParserKeyword{Keyword::ALL_SETTINGS}.ignore(pos, expected))
submode = "ALL SETTINGS";
target = "ALL SETTINGS";
else if (ParserKeyword{Keyword::PROFILES}.ignore(pos, expected) || ParserKeyword{Keyword::PROFILE}.ignore(pos, expected))
submode = "PROFILES";
target = "PROFILES";
else if (ParserKeyword{Keyword::SETTINGS}.ignore(pos, expected) || ParserKeyword{Keyword::SETTING}.ignore(pos, expected))
submode = "SETTINGS";
target = "SETTINGS";
else
return false;
}
if (submode.empty())
return false;
if (submode == "PROFILES")
if (target == "PROFILES")
{
auto element = std::make_shared<ASTSettingsProfileElement>();
if (!parseProfileNameOrID(pos, expected, /* id_mode= */ false, element->parent_profile))
return false;
if (mode == "ADD")
if (action == "ADD")
{
add_settings.push_back(element);
return true;
}
if (mode == "DROP")
if (action == "DROP")
{
drop_settings.push_back(element);
return true;
@ -361,20 +351,20 @@ bool ParserAlterSettingsProfileElements::parseImpl(Pos & pos, ASTPtr & node, Exp
return false;
}
if (submode == "SETTINGS")
if (target == "SETTINGS")
{
auto element = std::make_shared<ASTSettingsProfileElement>();
if (mode == "ADD" || mode == "MODIFY")
if (action == "ADD" || action == "MODIFY")
{
if (!parseSettingNameWithValueOrConstraints(pos, expected, element->setting_name, element->value, element->min_value, element->max_value, element->writability))
return false;
if (mode == "ADD")
if (action == "ADD")
add_settings.push_back(element);
else
modify_settings.push_back(element);
return true;
}
if (mode == "DROP")
if (action == "DROP")
{
ASTPtr name_ast;
if (!ParserCompoundIdentifier{}.parse(pos, name_ast, expected))
@ -386,13 +376,13 @@ bool ParserAlterSettingsProfileElements::parseImpl(Pos & pos, ASTPtr & node, Exp
return false;
}
if (mode == "DROP" && submode == "ALL PROFILES")
if (action == "DROP" && target == "ALL PROFILES")
{
drop_all_profiles = true;
return true;
}
if (mode == "DROP" && submode == "ALL SETTINGS")
if (action == "DROP" && target == "ALL SETTINGS")
{
drop_all_settings = true;
return true;

View File

@ -49,7 +49,7 @@ CREATE SETTINGS PROFILE `s4_01294` TO r1_01294
CREATE SETTINGS PROFILE `s1_01294` SETTINGS readonly = 1
CREATE SETTINGS PROFILE `s2_01294` SETTINGS readonly CONST
CREATE SETTINGS PROFILE `s3_01294` SETTINGS INHERIT `readonly`
CREATE SETTINGS PROFILE `s4_01294` SETTINGS INHERIT `readonly`, INHERIT `readonly`
CREATE SETTINGS PROFILE `s4_01294` SETTINGS INHERIT `readonly`
CREATE SETTINGS PROFILE `s5_01294` SETTINGS INHERIT `readonly`, readonly = 1
CREATE SETTINGS PROFILE `s6_01294` SETTINGS INHERIT `readonly`, readonly CONST
-- system.settings_profiles

View File

@ -1,21 +1,21 @@
CREATE USER test_user
CREATE USER test_user SETTINGS PROFILE profile_a
CREATE USER test_user SETTINGS PROFILE profile_a, PROFILE profile_b
CREATE USER test_user SETTINGS PROFILE profile_b, PROFILE profile_a, PROFILE profile_c
CREATE USER test_user SETTINGS PROFILE profile_a, PROFILE profile_d
CREATE USER test_user SETTINGS PROFILE profile_e
CREATE USER test_user
CREATE USER test_user IDENTIFIED WITH no_password
CREATE USER test_user IDENTIFIED WITH no_password SETTINGS PROFILE `profile_a`
CREATE USER test_user IDENTIFIED WITH no_password SETTINGS PROFILE `profile_a`, PROFILE `profile_b`
CREATE USER test_user IDENTIFIED WITH no_password SETTINGS PROFILE `profile_b`, PROFILE `profile_a`, PROFILE `profile_c`
CREATE USER test_user IDENTIFIED WITH no_password SETTINGS PROFILE `profile_a`, PROFILE `profile_d`
CREATE USER test_user IDENTIFIED WITH no_password SETTINGS PROFILE `profile_e`
CREATE USER test_user IDENTIFIED WITH no_password
CREATE ROLE test_role
CREATE ROLE test_role SETTINGS PROFILE profile_a
CREATE ROLE test_role SETTINGS PROFILE profile_a, PROFILE profile_b
CREATE ROLE test_role SETTINGS PROFILE profile_b, PROFILE profile_a, PROFILE profile_c
CREATE ROLE test_role SETTINGS PROFILE profile_a, PROFILE profile_d
CREATE ROLE test_role SETTINGS PROFILE profile_e
CREATE ROLE test_role SETTINGS PROFILE `profile_a`
CREATE ROLE test_role SETTINGS PROFILE `profile_a`, PROFILE `profile_b`
CREATE ROLE test_role SETTINGS PROFILE `profile_b`, PROFILE `profile_a`, PROFILE `profile_c`
CREATE ROLE test_role SETTINGS PROFILE `profile_a`, PROFILE `profile_d`
CREATE ROLE test_role SETTINGS PROFILE `profile_e`
CREATE ROLE test_role
CREATE SETTINGS PROFILE test_profile
CREATE SETTINGS PROFILE test_profile SETTINGS INHERIT profile_a
CREATE SETTINGS PROFILE test_profile SETTINGS INHERIT profile_a, INHERIT profile_b
CREATE SETTINGS PROFILE test_profile SETTINGS INHERIT profile_b, INHERIT profile_a, INHERIT profile_c
CREATE SETTINGS PROFILE test_profile SETTINGS INHERIT profile_a, INHERIT profile_d
CREATE SETTINGS PROFILE test_profile SETTINGS INHERIT profile_e
CREATE SETTINGS PROFILE test_profile SETTINGS INHERIT `profile_a`
CREATE SETTINGS PROFILE test_profile SETTINGS INHERIT `profile_a`, INHERIT `profile_b`
CREATE SETTINGS PROFILE test_profile SETTINGS INHERIT `profile_b`, INHERIT `profile_a`, INHERIT `profile_c`
CREATE SETTINGS PROFILE test_profile SETTINGS INHERIT `profile_a`, INHERIT `profile_d`
CREATE SETTINGS PROFILE test_profile SETTINGS INHERIT `profile_e`
CREATE SETTINGS PROFILE test_profile

View File

@ -1,39 +1,39 @@
CREATE USER test_user
CREATE USER test_user SETTINGS PROFILE profile_a, PROFILE profile_b, custom_x = 123, custom_y = 56.5, custom_w = \'www\'
CREATE USER test_user
CREATE USER test_user SETTINGS PROFILE profile_a, PROFILE profile_b, custom_x = 123, custom_y = 56.5, custom_w = \'www\'
CREATE USER test_user
CREATE USER test_user SETTINGS PROFILE profile_a, PROFILE profile_b, custom_x = 123, custom_y = 56.5, custom_w = \'www\'
CREATE USER test_user
CREATE USER test_user SETTINGS PROFILE profile_a, PROFILE profile_b, custom_x = 123, custom_y = 56.5, custom_w = \'www\'
CREATE USER test_user
CREATE USER test_user SETTINGS custom_x = 123, custom_t = 7, custom_s = \'str\'
CREATE USER test_user SETTINGS PROFILE profile_a, custom_x = 123, custom_t = 7, custom_s = \'str\'
CREATE USER test_user SETTINGS PROFILE profile_b, PROFILE profile_a, custom_x = 321, custom_s = \'str\' CONST
CREATE USER test_user
CREATE USER test_user IDENTIFIED WITH no_password
CREATE USER test_user IDENTIFIED WITH no_password SETTINGS PROFILE `profile_a`, PROFILE `profile_b`, custom_x = 123, custom_y = 56.5, custom_w = \'www\'
CREATE USER test_user IDENTIFIED WITH no_password
CREATE USER test_user IDENTIFIED WITH no_password SETTINGS PROFILE `profile_a`, PROFILE `profile_b`, custom_x = 123, custom_y = 56.5, custom_w = \'www\'
CREATE USER test_user IDENTIFIED WITH no_password
CREATE USER test_user IDENTIFIED WITH no_password SETTINGS PROFILE `profile_a`, PROFILE `profile_b`, custom_x = 123, custom_y = 56.5, custom_w = \'www\'
CREATE USER test_user IDENTIFIED WITH no_password
CREATE USER test_user IDENTIFIED WITH no_password SETTINGS PROFILE `profile_a`, PROFILE `profile_b`, custom_x = 123, custom_y = 56.5, custom_w = \'www\'
CREATE USER test_user IDENTIFIED WITH no_password
CREATE USER test_user IDENTIFIED WITH no_password SETTINGS custom_x = 123, custom_t = 7, custom_s = \'str\'
CREATE USER test_user IDENTIFIED WITH no_password SETTINGS PROFILE `profile_a`, custom_x = 123, custom_t = 7, custom_s = \'str\'
CREATE USER test_user IDENTIFIED WITH no_password SETTINGS PROFILE `profile_b`, PROFILE `profile_a`, custom_x = 321, custom_s = \'str\' CONST
CREATE USER test_user IDENTIFIED WITH no_password
CREATE ROLE test_role
CREATE ROLE test_role SETTINGS PROFILE profile_a, PROFILE profile_b, custom_x = 123, custom_y = 56.5, custom_w = \'www\'
CREATE ROLE test_role SETTINGS PROFILE `profile_a`, PROFILE `profile_b`, custom_x = 123, custom_y = 56.5, custom_w = \'www\'
CREATE ROLE test_role
CREATE ROLE test_role SETTINGS PROFILE profile_a, PROFILE profile_b, custom_x = 123, custom_y = 56.5, custom_w = \'www\'
CREATE ROLE test_role SETTINGS PROFILE `profile_a`, PROFILE `profile_b`, custom_x = 123, custom_y = 56.5, custom_w = \'www\'
CREATE ROLE test_role
CREATE ROLE test_role SETTINGS PROFILE profile_a, PROFILE profile_b, custom_x = 123, custom_y = 56.5, custom_w = \'www\'
CREATE ROLE test_role SETTINGS PROFILE `profile_a`, PROFILE `profile_b`, custom_x = 123, custom_y = 56.5, custom_w = \'www\'
CREATE ROLE test_role
CREATE ROLE test_role SETTINGS PROFILE profile_a, PROFILE profile_b, custom_x = 123, custom_y = 56.5, custom_w = \'www\'
CREATE ROLE test_role SETTINGS PROFILE `profile_a`, PROFILE `profile_b`, custom_x = 123, custom_y = 56.5, custom_w = \'www\'
CREATE ROLE test_role
CREATE ROLE test_role SETTINGS custom_x = 123, custom_t = 7, custom_s = \'str\'
CREATE ROLE test_role SETTINGS PROFILE profile_a, custom_x = 123, custom_t = 7, custom_s = \'str\'
CREATE ROLE test_role SETTINGS PROFILE profile_b, PROFILE profile_a, custom_x = 321, custom_s = \'str\' CONST
CREATE ROLE test_role SETTINGS PROFILE `profile_a`, custom_x = 123, custom_t = 7, custom_s = \'str\'
CREATE ROLE test_role SETTINGS PROFILE `profile_b`, PROFILE `profile_a`, custom_x = 321, custom_s = \'str\' CONST
CREATE ROLE test_role
CREATE SETTINGS PROFILE test_profile
CREATE SETTINGS PROFILE test_profile SETTINGS INHERIT profile_a, INHERIT profile_b, custom_x = 123, custom_y = 56.5, custom_w = \'www\'
CREATE SETTINGS PROFILE test_profile SETTINGS INHERIT `profile_a`, INHERIT `profile_b`, custom_x = 123, custom_y = 56.5, custom_w = \'www\'
CREATE SETTINGS PROFILE test_profile
CREATE SETTINGS PROFILE test_profile SETTINGS INHERIT profile_a, INHERIT profile_b, custom_x = 123, custom_y = 56.5, custom_w = \'www\'
CREATE SETTINGS PROFILE test_profile SETTINGS INHERIT `profile_a`, INHERIT `profile_b`, custom_x = 123, custom_y = 56.5, custom_w = \'www\'
CREATE SETTINGS PROFILE test_profile
CREATE SETTINGS PROFILE test_profile SETTINGS INHERIT profile_a, INHERIT profile_b, custom_x = 123, custom_y = 56.5, custom_w = \'www\'
CREATE SETTINGS PROFILE test_profile SETTINGS INHERIT `profile_a`, INHERIT `profile_b`, custom_x = 123, custom_y = 56.5, custom_w = \'www\'
CREATE SETTINGS PROFILE test_profile
CREATE SETTINGS PROFILE test_profile SETTINGS INHERIT profile_a, INHERIT profile_b, custom_x = 123, custom_y = 56.5, custom_w = \'www\'
CREATE SETTINGS PROFILE test_profile SETTINGS INHERIT `profile_a`, INHERIT `profile_b`, custom_x = 123, custom_y = 56.5, custom_w = \'www\'
CREATE SETTINGS PROFILE test_profile
CREATE SETTINGS PROFILE test_profile SETTINGS custom_x = 123, custom_t = 7, custom_s = \'str\'
CREATE SETTINGS PROFILE test_profile SETTINGS INHERIT profile_a, custom_x = 123, custom_t = 7, custom_s = \'str\'
CREATE SETTINGS PROFILE test_profile SETTINGS INHERIT profile_b, INHERIT profile_a, custom_x = 321, custom_s = \'str\' CONST
CREATE SETTINGS PROFILE test_profile SETTINGS INHERIT `profile_a`, custom_x = 123, custom_t = 7, custom_s = \'str\'
CREATE SETTINGS PROFILE test_profile SETTINGS INHERIT `profile_b`, INHERIT `profile_a`, custom_x = 321, custom_s = \'str\' CONST
CREATE SETTINGS PROFILE test_profile

View File

@ -1,17 +1,17 @@
CREATE USER test_user
CREATE USER test_user SETTINGS custom_a = 100
CREATE USER test_user SETTINGS custom_a = 100, custom_b = 200
CREATE USER test_user SETTINGS custom_a = 100, custom_b = 300, custom_c = 400
CREATE USER test_user SETTINGS custom_b = 300, custom_c = 400, custom_d = 500
CREATE USER test_user SETTINGS custom_b = 300, custom_c = 400, custom_d = 500, custom_e = 600 MIN 0 MAX 1000
CREATE USER test_user SETTINGS custom_b = 300, custom_c = 400, custom_d = 500, custom_e = 600 MIN 0 MAX 2000
CREATE USER test_user SETTINGS custom_b = 300, custom_c = 400, custom_d = 500, custom_e = 600 MIN 500 MAX 2000
CREATE USER test_user SETTINGS custom_b = 300, custom_c = 400, custom_d = 500, custom_e = 700 MIN 500 MAX 2000
CREATE USER test_user SETTINGS custom_b = 300, custom_c = 400, custom_d = 500, custom_e = 800 MIN 150
CREATE USER test_user SETTINGS custom_c = 400, custom_d = 500
CREATE USER test_user SETTINGS custom_c = 400, custom_d = 500, custom_x = 1, custom_y = 2
CREATE USER test_user SETTINGS custom_z = 3
CREATE USER test_user
CREATE USER test_user IDENTIFIED WITH no_password
CREATE USER test_user IDENTIFIED WITH no_password SETTINGS custom_a = 100
CREATE USER test_user IDENTIFIED WITH no_password SETTINGS custom_a = 100, custom_b = 200
CREATE USER test_user IDENTIFIED WITH no_password SETTINGS custom_a = 100, custom_b = 300, custom_c = 400
CREATE USER test_user IDENTIFIED WITH no_password SETTINGS custom_b = 300, custom_c = 400, custom_d = 500
CREATE USER test_user IDENTIFIED WITH no_password SETTINGS custom_b = 300, custom_c = 400, custom_d = 500, custom_e = 600 MIN 0 MAX 1000
CREATE USER test_user IDENTIFIED WITH no_password SETTINGS custom_b = 300, custom_c = 400, custom_d = 500, custom_e = 600 MIN 0 MAX 2000
CREATE USER test_user IDENTIFIED WITH no_password SETTINGS custom_b = 300, custom_c = 400, custom_d = 500, custom_e = 600 MIN 500 MAX 2000
CREATE USER test_user IDENTIFIED WITH no_password SETTINGS custom_b = 300, custom_c = 400, custom_d = 500, custom_e = 700 MIN 500 MAX 2000
CREATE USER test_user IDENTIFIED WITH no_password SETTINGS custom_b = 300, custom_c = 400, custom_d = 500, custom_e = 800 MIN 150
CREATE USER test_user IDENTIFIED WITH no_password SETTINGS custom_c = 400, custom_d = 500
CREATE USER test_user IDENTIFIED WITH no_password SETTINGS custom_c = 400, custom_d = 500, custom_x = 1, custom_y = 2
CREATE USER test_user IDENTIFIED WITH no_password SETTINGS custom_z = 3
CREATE USER test_user IDENTIFIED WITH no_password
CREATE ROLE test_role
CREATE ROLE test_role SETTINGS custom_a = 100
CREATE ROLE test_role SETTINGS custom_a = 100, custom_b = 200
@ -26,17 +26,17 @@ CREATE ROLE test_role SETTINGS custom_c = 400, custom_d = 500
CREATE ROLE test_role SETTINGS custom_c = 400, custom_d = 500, custom_x = 1, custom_y = 2
CREATE ROLE test_role SETTINGS custom_z = 3
CREATE ROLE test_role
CREATE SETTINGS PROFILE test_profile
CREATE SETTINGS PROFILE test_profile SETTINGS custom_a = 100
CREATE SETTINGS PROFILE test_profile SETTINGS custom_a = 100, custom_b = 200
CREATE SETTINGS PROFILE test_profile SETTINGS custom_a = 100, custom_b = 300, custom_c = 400
CREATE SETTINGS PROFILE test_profile SETTINGS custom_b = 300, custom_c = 400, custom_d = 500
CREATE SETTINGS PROFILE test_profile SETTINGS custom_b = 300, custom_c = 400, custom_d = 500, custom_e = 600 MIN 0 MAX 1000
CREATE SETTINGS PROFILE test_profile SETTINGS custom_b = 300, custom_c = 400, custom_d = 500, custom_e = 600 MIN 0 MAX 2000
CREATE SETTINGS PROFILE test_profile SETTINGS custom_b = 300, custom_c = 400, custom_d = 500, custom_e = 600 MIN 500 MAX 2000
CREATE SETTINGS PROFILE test_profile SETTINGS custom_b = 300, custom_c = 400, custom_d = 500, custom_e = 700 MIN 500 MAX 2000
CREATE SETTINGS PROFILE test_profile SETTINGS custom_b = 300, custom_c = 400, custom_d = 500, custom_e = 800 MIN 150
CREATE SETTINGS PROFILE test_profile SETTINGS custom_c = 400, custom_d = 500
CREATE SETTINGS PROFILE test_profile SETTINGS custom_c = 400, custom_d = 500, custom_x = 1, custom_y = 2
CREATE SETTINGS PROFILE test_profile SETTINGS custom_z = 3
CREATE SETTINGS PROFILE test_profile
CREATE SETTINGS PROFILE `test_profile`
CREATE SETTINGS PROFILE `test_profile` SETTINGS custom_a = 100
CREATE SETTINGS PROFILE `test_profile` SETTINGS custom_a = 100, custom_b = 200
CREATE SETTINGS PROFILE `test_profile` SETTINGS custom_a = 100, custom_b = 300, custom_c = 400
CREATE SETTINGS PROFILE `test_profile` SETTINGS custom_b = 300, custom_c = 400, custom_d = 500
CREATE SETTINGS PROFILE `test_profile` SETTINGS custom_b = 300, custom_c = 400, custom_d = 500, custom_e = 600 MIN 0 MAX 1000
CREATE SETTINGS PROFILE `test_profile` SETTINGS custom_b = 300, custom_c = 400, custom_d = 500, custom_e = 600 MIN 0 MAX 2000
CREATE SETTINGS PROFILE `test_profile` SETTINGS custom_b = 300, custom_c = 400, custom_d = 500, custom_e = 600 MIN 500 MAX 2000
CREATE SETTINGS PROFILE `test_profile` SETTINGS custom_b = 300, custom_c = 400, custom_d = 500, custom_e = 700 MIN 500 MAX 2000
CREATE SETTINGS PROFILE `test_profile` SETTINGS custom_b = 300, custom_c = 400, custom_d = 500, custom_e = 800 MIN 150
CREATE SETTINGS PROFILE `test_profile` SETTINGS custom_c = 400, custom_d = 500
CREATE SETTINGS PROFILE `test_profile` SETTINGS custom_c = 400, custom_d = 500, custom_x = 1, custom_y = 2
CREATE SETTINGS PROFILE `test_profile` SETTINGS custom_z = 3
CREATE SETTINGS PROFILE `test_profile`