Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 4 additions & 7 deletions ydb/core/kqp/ut/scheme/kqp_scheme_ut.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6520,8 +6520,7 @@ Y_UNIT_TEST_SUITE(KqpScheme) {
// ALTER RESOURCE POOL
checkDisabled(R"(
ALTER RESOURCE POOL MyResourcePool
SET (CONCURRENT_QUERY_LIMIT = 30),
SET QUEUE_SIZE 100,
SET (CONCURRENT_QUERY_LIMIT = 30, QUEUE_SIZE = 100),
RESET (QUERY_MEMORY_LIMIT_PERCENT_PER_NODE);
)");

Expand Down Expand Up @@ -6558,7 +6557,7 @@ Y_UNIT_TEST_SUITE(KqpScheme) {

result = session.ExecuteSchemeQuery(R"(
ALTER RESOURCE POOL MyResourcePool
SET ANOTHER_LIMIT 5,
SET (ANOTHER_LIMIT = 5),
RESET (SOME_LIMIT);
)").GetValueSync();
UNIT_ASSERT_VALUES_EQUAL(result.GetStatus(), EStatus::GENERIC_ERROR);
Expand Down Expand Up @@ -6671,8 +6670,7 @@ Y_UNIT_TEST_SUITE(KqpScheme) {
{
auto query = R"(
ALTER RESOURCE POOL MyResourcePool
SET (CONCURRENT_QUERY_LIMIT = 30),
SET QUEUE_SIZE 100,
SET (CONCURRENT_QUERY_LIMIT = 30, QUEUE_SIZE = 100),
RESET (QUERY_MEMORY_LIMIT_PERCENT_PER_NODE);
)";
auto result = session.ExecuteSchemeQuery(query).GetValueSync();
Expand Down Expand Up @@ -6701,8 +6699,7 @@ Y_UNIT_TEST_SUITE(KqpScheme) {

auto query = R"(
ALTER RESOURCE POOL MyResourcePool
SET (CONCURRENT_QUERY_LIMIT = 30),
SET QUEUE_SIZE 100,
SET (CONCURRENT_QUERY_LIMIT = 30, QUEUE_SIZE = 100),
RESET (QUERY_MEMORY_LIMIT_PERCENT_PER_NODE);
)";
auto result = session.ExecuteSchemeQuery(query).GetValueSync();
Expand Down
23 changes: 21 additions & 2 deletions ydb/library/yql/sql/v1/SQLv1.g.in
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@ sql_stmt_core:
| alter_backup_collection_stmt
| drop_backup_collection_stmt
| analyze_stmt
| create_resource_pool_classifier_stmt
| alter_resource_pool_classifier_stmt
| drop_resource_pool_classifier_stmt
;

expr:
Expand Down Expand Up @@ -837,13 +840,26 @@ alter_resource_pool_stmt: ALTER RESOURCE POOL object_ref
alter_resource_pool_action (COMMA alter_resource_pool_action)*
;
alter_resource_pool_action:
alter_table_set_table_setting_uncompat
| alter_table_set_table_setting_compat
alter_table_set_table_setting_compat
| alter_table_reset_table_setting
;

drop_resource_pool_stmt: DROP RESOURCE POOL object_ref;

create_resource_pool_classifier_stmt: CREATE RESOURCE POOL CLASSIFIER object_ref
with_table_settings
;

alter_resource_pool_classifier_stmt: ALTER RESOURCE POOL CLASSIFIER object_ref
alter_resource_pool_classifier_action (COMMA alter_resource_pool_classifier_action)*
;
alter_resource_pool_classifier_action:
alter_table_set_table_setting_compat
| alter_table_reset_table_setting
;

drop_resource_pool_classifier_stmt: DROP RESOURCE POOL CLASSIFIER object_ref;

create_replication_stmt: CREATE ASYNC REPLICATION object_ref
FOR replication_target (COMMA replication_target)*
WITH LPAREN replication_settings RPAREN
Expand Down Expand Up @@ -1233,6 +1249,7 @@ keyword_as_compat:
| CASCADE
| CHANGEFEED
| CHECK
| CLASSIFIER
// | COLLATE
| COLLECTION
| COMMIT
Expand Down Expand Up @@ -1447,6 +1464,7 @@ keyword_compat: (
| CASCADE
| CHANGEFEED
| CHECK
| CLASSIFIER
| COLLATE
| COLLECTION
| COMMIT
Expand Down Expand Up @@ -1766,6 +1784,7 @@ CASE: C A S E;
CAST: C A S T;
CHANGEFEED: C H A N G E F E E D;
CHECK: C H E C K;
CLASSIFIER: C L A S S I F I E R;
COLLATE: C O L L A T E;
COLUMN: C O L U M N;
COLUMNS: C O L U M N S;
Expand Down
38 changes: 37 additions & 1 deletion ydb/library/yql/sql/v1/format/sql_format.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1563,6 +1563,39 @@ friend struct TStaticData;
VisitAllFields(TRule_drop_backup_collection_stmt::GetDescriptor(), msg);
}

void VisitCreateResourcePoolClassifier(const TRule_create_resource_pool_classifier_stmt& msg) {
PosFromToken(msg.GetToken1());
NewLine();
VisitAllFields(TRule_create_resource_pool_classifier_stmt::GetDescriptor(), msg);
}

void VisitAlterResourcePoolClassifier(const TRule_alter_resource_pool_classifier_stmt& msg) {
PosFromToken(msg.GetToken1());
NewLine();
VisitToken(msg.GetToken1());
VisitToken(msg.GetToken2());
VisitToken(msg.GetToken3());
VisitToken(msg.GetToken4());
Visit(msg.GetRule_object_ref5());

NewLine();
PushCurrentIndent();
Visit(msg.GetRule_alter_resource_pool_classifier_action6());
for (const auto& action : msg.GetBlock7()) {
Visit(action.GetToken1()); // comma
NewLine();
Visit(action.GetRule_alter_resource_pool_classifier_action2());
}

PopCurrentIndent();
}

void VisitDropResourcePoolClassifier(const TRule_drop_resource_pool_classifier_stmt& msg) {
PosFromToken(msg.GetToken1());
NewLine();
VisitAllFields(TRule_drop_resource_pool_classifier_stmt::GetDescriptor(), msg);
}

void VisitAllFields(const NProtoBuf::Descriptor* descr, const NProtoBuf::Message& msg) {
VisitAllFieldsImpl<TPrettyVisitor, &TPrettyVisitor::Visit>(this, descr, msg);
}
Expand Down Expand Up @@ -2783,7 +2816,10 @@ TStaticData::TStaticData()
{TRule_create_backup_collection_stmt::GetDescriptor(), MakePrettyFunctor(&TPrettyVisitor::VisitCreateBackupCollection)},
{TRule_alter_backup_collection_stmt::GetDescriptor(), MakePrettyFunctor(&TPrettyVisitor::VisitAlterBackupCollection)},
{TRule_drop_backup_collection_stmt::GetDescriptor(), MakePrettyFunctor(&TPrettyVisitor::VisitDropBackupCollection)},
{TRule_analyze_stmt::GetDescriptor(), MakePrettyFunctor(&TPrettyVisitor::VisitAnalyze)}
{TRule_analyze_stmt::GetDescriptor(), MakePrettyFunctor(&TPrettyVisitor::VisitAnalyze)},
{TRule_create_resource_pool_classifier_stmt::GetDescriptor(), MakePrettyFunctor(&TPrettyVisitor::VisitCreateResourcePoolClassifier)},
{TRule_alter_resource_pool_classifier_stmt::GetDescriptor(), MakePrettyFunctor(&TPrettyVisitor::VisitAlterResourcePoolClassifier)},
{TRule_drop_resource_pool_classifier_stmt::GetDescriptor(), MakePrettyFunctor(&TPrettyVisitor::VisitDropResourcePoolClassifier)}
})
, ObfuscatingVisitDispatch({
{TToken::GetDescriptor(), MakeObfuscatingFunctor(&TObfuscatingVisitor::VisitToken)},
Expand Down
22 changes: 20 additions & 2 deletions ydb/library/yql/sql/v1/format/sql_format_ut.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1594,8 +1594,8 @@ FROM Input MATCH_RECOGNIZE (PATTERN (A) DEFINE A AS A);
"CREATE RESOURCE POOL naMe WITH (a = \"b\");\n"},
{"create resource pool eds with (a=\"a\",b=\"b\",c = true)",
"CREATE RESOURCE POOL eds WITH (\n\ta = \"a\",\n\tb = \"b\",\n\tc = TRUE\n);\n"},
{"alTer reSOurcE poOl naMe sEt a tRue, resEt (b, c), seT (x=y, z=false)",
"ALTER RESOURCE POOL naMe\n\tSET a TRUE,\n\tRESET (b, c),\n\tSET (x = y, z = FALSE);\n"},
{"alTer reSOurcE poOl naMe resEt (b, c), seT (x=y, z=false)",
"ALTER RESOURCE POOL naMe\n\tRESET (b, c),\n\tSET (x = y, z = FALSE);\n"},
{"alter resource pool eds reset (a), set (x=y)",
"ALTER RESOURCE POOL eds\n\tRESET (a),\n\tSET (x = y);\n"},
{"dRop reSourCe poOl naMe",
Expand Down Expand Up @@ -1631,4 +1631,22 @@ FROM Input MATCH_RECOGNIZE (PATTERN (A) DEFINE A AS A);
TSetup setup;
setup.Run(cases);
}

Y_UNIT_TEST(ResourcePoolClassifierOperations) {
TCases cases = {
{"creAte reSourCe poOl ClaSsiFIer naMe With (a = \"b\")",
"CREATE RESOURCE POOL CLASSIFIER naMe WITH (a = \"b\");\n"},
{"create resource pool classifier eds with (a=\"a\",b=\"b\",c = true)",
"CREATE RESOURCE POOL CLASSIFIER eds WITH (\n\ta = \"a\",\n\tb = \"b\",\n\tc = TRUE\n);\n"},
{"alTer reSOurcE poOl ClaSsiFIer naMe resEt (b, c), seT (x=y, z=false)",
"ALTER RESOURCE POOL CLASSIFIER naMe\n\tRESET (b, c),\n\tSET (x = y, z = FALSE);\n"},
{"alter resource pool classifier eds reset (a), set (x=y)",
"ALTER RESOURCE POOL CLASSIFIER eds\n\tRESET (a),\n\tSET (x = y);\n"},
{"dRop reSourCe poOl ClaSsiFIer naMe",
"DROP RESOURCE POOL CLASSIFIER naMe;\n"},
};

TSetup setup;
setup.Run(cases);
}
}
3 changes: 3 additions & 0 deletions ydb/library/yql/sql/v1/sql.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,9 @@ bool NeedUseForAllStatements(const TRule_sql_stmt_core::AltCase& subquery) {
case TRule_sql_stmt_core::kAltSqlStmtCore49: // alter backup collection
case TRule_sql_stmt_core::kAltSqlStmtCore50: // drop backup collection
case TRule_sql_stmt_core::kAltSqlStmtCore51: // analyze
case TRule_sql_stmt_core::kAltSqlStmtCore52: // create resource pool classifier
case TRule_sql_stmt_core::kAltSqlStmtCore53: // alter resource pool classifier
case TRule_sql_stmt_core::kAltSqlStmtCore54: // drop resource pool classifier
return false;
}
}
Expand Down
63 changes: 63 additions & 0 deletions ydb/library/yql/sql/v1/sql_query.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1461,6 +1461,69 @@ bool TSqlQuery::Statement(TVector<TNodePtr>& blocks, const TRule_sql_stmt_core&
AddStatementToBlocks(blocks, BuildAnalyze(Ctx.Pos(), tr.Service, tr.Cluster, params, Ctx.Scoped));
break;
}
case TRule_sql_stmt_core::kAltSqlStmtCore52: {
// create_resource_pool_classifier_stmt: CREATE RESOURCE POOL CLASSIFIER name WITH (k=v,...);
auto& node = core.GetAlt_sql_stmt_core52().GetRule_create_resource_pool_classifier_stmt1();
TObjectOperatorContext context(Ctx.Scoped);
if (node.GetRule_object_ref5().HasBlock1()) {
if (!ClusterExpr(node.GetRule_object_ref5().GetBlock1().GetRule_cluster_expr1(),
false, context.ServiceId, context.Cluster)) {
return false;
}
}

const TString& objectId = Id(node.GetRule_object_ref5().GetRule_id_or_at2(), *this).second;
std::map<TString, TDeferredAtom> kv;
if (!ParseResourcePoolClassifierSettings(kv, node.GetRule_with_table_settings6())) {
return false;
}

AddStatementToBlocks(blocks, BuildCreateObjectOperation(Ctx.Pos(), objectId, "RESOURCE_POOL_CLASSIFIER", false, false, std::move(kv), context));
break;
}
case TRule_sql_stmt_core::kAltSqlStmtCore53: {
// alter_resource_pool_classifier_stmt: ALTER RESOURCE POOL CLASSIFIER object_ref alter_resource_pool_classifier_action (COMMA alter_resource_pool_classifier_action)*
Ctx.BodyPart();
const auto& node = core.GetAlt_sql_stmt_core53().GetRule_alter_resource_pool_classifier_stmt1();
TObjectOperatorContext context(Ctx.Scoped);
if (node.GetRule_object_ref5().HasBlock1()) {
if (!ClusterExpr(node.GetRule_object_ref5().GetBlock1().GetRule_cluster_expr1(),
false, context.ServiceId, context.Cluster)) {
return false;
}
}

const TString& objectId = Id(node.GetRule_object_ref5().GetRule_id_or_at2(), *this).second;
std::map<TString, TDeferredAtom> kv;
std::set<TString> toReset;
if (!ParseResourcePoolClassifierSettings(kv, toReset, node.GetRule_alter_resource_pool_classifier_action6())) {
return false;
}

for (const auto& action : node.GetBlock7()) {
if (!ParseResourcePoolClassifierSettings(kv, toReset, action.GetRule_alter_resource_pool_classifier_action2())) {
return false;
}
}

AddStatementToBlocks(blocks, BuildAlterObjectOperation(Ctx.Pos(), objectId, "RESOURCE_POOL_CLASSIFIER", std::move(kv), std::move(toReset), context));
break;
}
case TRule_sql_stmt_core::kAltSqlStmtCore54: {
// drop_resource_pool_classifier_stmt: DROP RESOURCE POOL CLASSIFIER name;
auto& node = core.GetAlt_sql_stmt_core54().GetRule_drop_resource_pool_classifier_stmt1();
TObjectOperatorContext context(Ctx.Scoped);
if (node.GetRule_object_ref5().HasBlock1()) {
if (!ClusterExpr(node.GetRule_object_ref5().GetBlock1().GetRule_cluster_expr1(),
false, context.ServiceId, context.Cluster)) {
return false;
}
}

const TString& objectId = Id(node.GetRule_object_ref5().GetRule_id_or_at2(), *this).second;
AddStatementToBlocks(blocks, BuildDropObjectOperation(Ctx.Pos(), objectId, "RESOURCE_POOL_CLASSIFIER", false, {}, context));
break;
}
case TRule_sql_stmt_core::ALT_NOT_SET:
Ctx.IncrementMonCounter("sql_errors", "UnknownStatement" + internalStatementName);
AltNotImplemented("sql_stmt_core", core);
Expand Down
80 changes: 72 additions & 8 deletions ydb/library/yql/sql/v1/sql_translation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4943,34 +4943,98 @@ bool TSqlTranslation::ParseResourcePoolSettings(std::map<TString, TDeferredAtom>
bool TSqlTranslation::ParseResourcePoolSettings(std::map<TString, TDeferredAtom>& result, std::set<TString>& toReset, const TRule_alter_resource_pool_action& alterAction) {
switch (alterAction.Alt_case()) {
case TRule_alter_resource_pool_action::kAltAlterResourcePoolAction1: {
const auto& action = alterAction.GetAlt_alter_resource_pool_action1().GetRule_alter_table_set_table_setting_uncompat1();
if (!StoreResourcePoolSettingsEntry(IdEx(action.GetRule_an_id2(), *this), &action.GetRule_table_setting_value3(), result)) {
const auto& action = alterAction.GetAlt_alter_resource_pool_action1().GetRule_alter_table_set_table_setting_compat1();
if (!StoreResourcePoolSettingsEntry(action.GetRule_alter_table_setting_entry3(), result)) {
return false;
}
for (const auto& entry : action.GetBlock4()) {
if (!StoreResourcePoolSettingsEntry(entry.GetRule_alter_table_setting_entry2(), result)) {
return false;
}
}
return true;
}
case TRule_alter_resource_pool_action::kAltAlterResourcePoolAction2: {
const auto& action = alterAction.GetAlt_alter_resource_pool_action2().GetRule_alter_table_set_table_setting_compat1();
if (!StoreResourcePoolSettingsEntry(action.GetRule_alter_table_setting_entry3(), result)) {
const auto& action = alterAction.GetAlt_alter_resource_pool_action2().GetRule_alter_table_reset_table_setting1();
const TString firstKey = to_lower(IdEx(action.GetRule_an_id3(), *this).Name);
toReset.insert(firstKey);
for (const auto& key : action.GetBlock4()) {
toReset.insert(to_lower(IdEx(key.GetRule_an_id2(), *this).Name));
}
return true;
}
case TRule_alter_resource_pool_action::ALT_NOT_SET:
Y_ABORT("You should change implementation according to grammar changes");
}
}

bool TSqlTranslation::StoreResourcePoolClassifierSettingsEntry(const TIdentifier& id, const TRule_table_setting_value* value, std::map<TString, TDeferredAtom>& result) {
YQL_ENSURE(value);

const TString key = to_lower(id.Name);
if (result.find(key) != result.end()) {
Ctx.Error() << to_upper(key) << " duplicate keys";
return false;
}

switch (value->Alt_case()) {
case TRule_table_setting_value::kAltTableSettingValue2:
return StoreString(*value, result[key], Ctx, to_upper(key));

case TRule_table_setting_value::kAltTableSettingValue3:
return StoreInt(*value, result[key], Ctx, to_upper(key));

default:
Ctx.Error() << to_upper(key) << " value should be a string literal or integer";
return false;
}

return true;
}

bool TSqlTranslation::StoreResourcePoolClassifierSettingsEntry(const TRule_alter_table_setting_entry& entry, std::map<TString, TDeferredAtom>& result) {
const TIdentifier id = IdEx(entry.GetRule_an_id1(), *this);
return StoreResourcePoolClassifierSettingsEntry(id, &entry.GetRule_table_setting_value3(), result);
}

bool TSqlTranslation::ParseResourcePoolClassifierSettings(std::map<TString, TDeferredAtom>& result, const TRule_with_table_settings& settingsNode) {
const auto& firstEntry = settingsNode.GetRule_table_settings_entry3();
if (!StoreResourcePoolClassifierSettingsEntry(IdEx(firstEntry.GetRule_an_id1(), *this), &firstEntry.GetRule_table_setting_value3(), result)) {
return false;
}
for (const auto& block : settingsNode.GetBlock4()) {
const auto& entry = block.GetRule_table_settings_entry2();
if (!StoreResourcePoolClassifierSettingsEntry(IdEx(entry.GetRule_an_id1(), *this), &entry.GetRule_table_setting_value3(), result)) {
return false;
}
}
return true;
}

bool TSqlTranslation::ParseResourcePoolClassifierSettings(std::map<TString, TDeferredAtom>& result, std::set<TString>& toReset, const TRule_alter_resource_pool_classifier_action& alterAction) {
switch (alterAction.Alt_case()) {
case TRule_alter_resource_pool_classifier_action::kAltAlterResourcePoolClassifierAction1: {
const auto& action = alterAction.GetAlt_alter_resource_pool_classifier_action1().GetRule_alter_table_set_table_setting_compat1();
if (!StoreResourcePoolClassifierSettingsEntry(action.GetRule_alter_table_setting_entry3(), result)) {
return false;
}
for (const auto& entry : action.GetBlock4()) {
if (!StoreResourcePoolSettingsEntry(entry.GetRule_alter_table_setting_entry2(), result)) {
if (!StoreResourcePoolClassifierSettingsEntry(entry.GetRule_alter_table_setting_entry2(), result)) {
return false;
}
}
return true;
}
case TRule_alter_resource_pool_action::kAltAlterResourcePoolAction3: {
const auto& action = alterAction.GetAlt_alter_resource_pool_action3().GetRule_alter_table_reset_table_setting1();
case TRule_alter_resource_pool_classifier_action::kAltAlterResourcePoolClassifierAction2: {
const auto& action = alterAction.GetAlt_alter_resource_pool_classifier_action2().GetRule_alter_table_reset_table_setting1();
const TString firstKey = to_lower(IdEx(action.GetRule_an_id3(), *this).Name);
toReset.insert(firstKey);
for (const auto& key : action.GetBlock4()) {
toReset.insert(to_lower(IdEx(key.GetRule_an_id2(), *this).Name));
}
return true;
}
case TRule_alter_resource_pool_action::ALT_NOT_SET:
case TRule_alter_resource_pool_classifier_action::ALT_NOT_SET:
Y_ABORT("You should change implementation according to grammar changes");
}
}
Expand Down
Loading