Skip to content

Commit 3788681

Browse files
committed
Done
1 parent 7d73a2b commit 3788681

File tree

3 files changed

+50
-15
lines changed

3 files changed

+50
-15
lines changed

ydb/library/yql/sql/v1/query.cpp

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3352,7 +3352,7 @@ class TAlterBackupCollectionNode
33523352
, Params(params)
33533353
{}
33543354

3355-
virtual INode::TPtr FillOptions(TContext&, INode::TPtr options) const final {
3355+
virtual INode::TPtr FillOptions(TContext& ctx, INode::TPtr options) const final {
33563356
options->Add(Q(Y(Q("mode"), Q("alter"))));
33573357

33583358
auto settings = Y();
@@ -3363,19 +3363,23 @@ class TAlterBackupCollectionNode
33633363

33643364
auto resetSettings = Y();
33653365
for (auto& key : Params.SettingsToReset) {
3366-
resetSettings->Add(Q(BuildQuotedAtom(Pos, key)));
3366+
resetSettings->Add(BuildQuotedAtom(Pos, key));
33673367
}
33683368
options->Add(Q(Y(Q("resetSettings"), Q(resetSettings))));
33693369

3370-
// auto entries = Y();
3371-
// if (Params.Database) {
3372-
// entries->Add(Q(Y(Q(Y(Q("type"), Q("database"))))));
3373-
// }
3374-
// for (auto& table : Params.Tables) {
3375-
// auto path = ctx.GetPrefixedPath(ServiceId, Cluster, table);
3376-
// entries->Add(Q(Y(Q(Y(Q("type"), Q("table"))), Q(Y(Q("path"), path)))));
3377-
// }
3378-
// options->Add(Q(Y(Q("entries"), Q(entries))));
3370+
auto entries = Y();
3371+
if (Params.Database != TAlterBackupCollectionParameters::EDatabase::Unchanged) {
3372+
entries->Add(Q(Y(Q(Y(Q("type"), Q("database"))), Q(Y(Q("action"), Q(Params.Database == TAlterBackupCollectionParameters::EDatabase::Add ? "add" : "drop"))))));
3373+
}
3374+
for (auto& table : Params.TablesToAdd) {
3375+
auto path = ctx.GetPrefixedPath(ServiceId, Cluster, table);
3376+
entries->Add(Q(Y(Q(Y(Q("type"), Q("table"))), Q(Y(Q("path"), path)), Q(Y(Q("action"), Q("add"))))));
3377+
}
3378+
for (auto& table : Params.TablesToDrop) {
3379+
auto path = ctx.GetPrefixedPath(ServiceId, Cluster, table);
3380+
entries->Add(Q(Y(Q(Y(Q("type"), Q("table"))), Q(Y(Q("path"), path)), Q(Y(Q("action"), Q("drop"))))));
3381+
}
3382+
options->Add(Q(Y(Q("alterEntries"), Q(entries))));
33793383

33803384
return options;
33813385
}

ydb/library/yql/sql/v1/sql_query.cpp

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1427,7 +1427,7 @@ bool TSqlQuery::Statement(TVector<TNodePtr>& blocks, const TRule_sql_stmt_core&
14271427
std::set<TString> toReset;
14281428

14291429
bool addDatabase = false;
1430-
bool removeDatabase = false;
1430+
bool dropDatabase = false;
14311431
TVector<TDeferredAtom> addTables;
14321432
TVector<TDeferredAtom> removeTables;
14331433

@@ -1441,7 +1441,7 @@ bool TSqlQuery::Statement(TVector<TNodePtr>& blocks, const TRule_sql_stmt_core&
14411441
case TRule_alter_backup_collection_stmt_TBlock3::kAlt2: {
14421442
if (!ParseBackupCollectionEntries(
14431443
addDatabase,
1444-
removeDatabase,
1444+
dropDatabase,
14451445
addTables,
14461446
removeTables,
14471447
node.GetBlock3().GetAlt2().GetRule_alter_backup_collection_entries1()))
@@ -1453,14 +1453,20 @@ bool TSqlQuery::Statement(TVector<TNodePtr>& blocks, const TRule_sql_stmt_core&
14531453
case TRule_alter_backup_collection_stmt_TBlock3::ALT_NOT_SET: {} // do nothing
14541454
}
14551455

1456+
auto database = addDatabase ?
1457+
TAlterBackupCollectionParameters::EDatabase::Add :
1458+
dropDatabase ?
1459+
TAlterBackupCollectionParameters::EDatabase::Drop :
1460+
TAlterBackupCollectionParameters::EDatabase::Unchanged;
1461+
14561462
const TString& objectId = Id(node.GetRule_backup_collection2().GetRule_object_ref3().GetRule_id_or_at2(), *this).second;
14571463
AddStatementToBlocks(blocks,
14581464
BuildAlterBackupCollection(Ctx.Pos(),
14591465
BuildTablePath(Ctx.GetPrefixPath(context.ServiceId, context.Cluster), objectId),
14601466
TAlterBackupCollectionParameters {
14611467
.Settings = std::move(kv),
14621468
.SettingsToReset = std::move(toReset),
1463-
.Database = TAlterBackupCollectionParameters::EDatabase::Unchanged,
1469+
.Database = database,
14641470
.TablesToAdd = addTables,
14651471
.TablesToDrop = removeTables,
14661472
.MissingOk = false,

ydb/library/yql/sql/v1/sql_ut.cpp

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7161,7 +7161,32 @@ Y_UNIT_TEST_SUITE(BackupCollection) {
71617161
UNIT_ASSERT_VALUES_UNEQUAL(TString::npos, line.find(R"#('"TestCollection")#"));
71627162
UNIT_ASSERT_STRING_CONTAINS(line, R"#(('mode 'alter))#");
71637163
UNIT_ASSERT_STRING_CONTAINS(line, R"#('('settings '('('"storage" '"remote") '('"tag1" '"123"))))#");
7164-
// UNIT_ASSERT_STRING_CONTAINS(line, R"#('('resetSettings '('"tag2" '"tag3")))#");
7164+
UNIT_ASSERT_STRING_CONTAINS(line, R"#('('resetSettings '('"tag2" '"tag3")))#");
7165+
}
7166+
};
7167+
7168+
TWordCountHive elementStat = { {TString("Write"), 0} };
7169+
VerifyProgram(res, elementStat, verifyLine);
7170+
7171+
UNIT_ASSERT_VALUES_EQUAL(1, elementStat["Write"]);
7172+
}
7173+
7174+
Y_UNIT_TEST(AlterBackupCollectionEntries) {
7175+
NYql::TAstParseResult res = SqlToYql(R"sql(
7176+
USE plato;
7177+
ALTER BACKUP COLLECTION TestCollection
7178+
DROP TABLE `test`,
7179+
ADD DATABASE;
7180+
)sql");
7181+
UNIT_ASSERT_C(res.Root, res.Issues.ToString());
7182+
7183+
TVerifyLineFunc verifyLine = [](const TString& word, const TString& line) {
7184+
if (word == "Write") {
7185+
UNIT_ASSERT_VALUES_UNEQUAL(TString::npos, line.find(R"#('"TestCollection")#"));
7186+
UNIT_ASSERT_STRING_CONTAINS(line, R"#(('mode 'alter))#");
7187+
UNIT_ASSERT_STRING_CONTAINS(line, R"#('alterEntries)#");
7188+
UNIT_ASSERT_STRING_CONTAINS(line, R"#('('('type 'table) '('path '"test") '('action 'drop)))#");
7189+
UNIT_ASSERT_STRING_CONTAINS(line, R"#('('('type 'database) '('action 'add)))#");
71657190
}
71667191
};
71677192

0 commit comments

Comments
 (0)