Skip to content

Commit

Permalink
Align create backup collection entries grammar with corresponding top…
Browse files Browse the repository at this point in the history
…ics grammar (#10580)
  • Loading branch information
Enjection authored Oct 21, 2024
1 parent 3fb6997 commit 7f4d37b
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 46 deletions.
5 changes: 3 additions & 2 deletions ydb/library/yql/sql/v1/SQLv1.g.in
Original file line number Diff line number Diff line change
Expand Up @@ -653,11 +653,12 @@ create_table_entry:
| an_id_schema
;

create_backup_collection_stmt: CREATE backup_collection WITH LPAREN backup_collection_settings RPAREN database_or_table_list?;
create_backup_collection_stmt: CREATE backup_collection create_backup_collection_entries? WITH LPAREN backup_collection_settings RPAREN;
alter_backup_collection_stmt: ALTER backup_collection (alter_backup_collection_actions | alter_backup_collection_entries);
drop_backup_collection_stmt: DROP backup_collection;

database_or_table_list: DATABASE | table_list;
create_backup_collection_entries: DATABASE | create_backup_collection_entries_many;
create_backup_collection_entries_many: LPAREN table_list RPAREN;
table_list: TABLE an_id_table (COMMA TABLE an_id_table)*;

alter_backup_collection_actions: alter_backup_collection_action (COMMA alter_backup_collection_action)*;
Expand Down
5 changes: 3 additions & 2 deletions ydb/library/yql/sql/v1/SQLv1Antlr4.g.in
Original file line number Diff line number Diff line change
Expand Up @@ -652,11 +652,12 @@ create_table_entry:
| an_id_schema
;

create_backup_collection_stmt: CREATE backup_collection WITH LPAREN backup_collection_settings RPAREN database_or_table_list?;
create_backup_collection_stmt: CREATE backup_collection create_backup_collection_entries? WITH LPAREN backup_collection_settings RPAREN;
alter_backup_collection_stmt: ALTER backup_collection (alter_backup_collection_actions | alter_backup_collection_entries);
drop_backup_collection_stmt: DROP backup_collection;

database_or_table_list: DATABASE | table_list;
create_backup_collection_entries: DATABASE | create_backup_collection_entries_many;
create_backup_collection_entries_many: LPAREN table_list RPAREN;
table_list: TABLE an_id_table (COMMA TABLE an_id_table)*;

alter_backup_collection_actions: alter_backup_collection_action (COMMA alter_backup_collection_action)*;
Expand Down
8 changes: 4 additions & 4 deletions ydb/library/yql/sql/v1/format/sql_format_ut.h
Original file line number Diff line number Diff line change
Expand Up @@ -1579,10 +1579,10 @@ Y_UNIT_TEST(BackupCollectionOperations) {
TCases cases = {
{"creAte BackuP colLection `-naMe` wIth (a = \"b\")",
"CREATE BACKUP COLLECTION `-naMe` WITH (a = \"b\");\n"},
{"creAte BackuP colLection `-naMe` wIth (a = \"b\") DATabase",
"CREATE BACKUP COLLECTION `-naMe` WITH (a = \"b\") DATABASE;\n"},
{"creAte BackuP colLection `-naMe` wIth (a = \"b\") tabLe `tbl1` , TablE `tbl2`",
"CREATE BACKUP COLLECTION `-naMe` WITH (a = \"b\") TABLE `tbl1`, TABLE `tbl2`;\n"},
{"creAte BackuP colLection `-naMe` DATabase wIth (a = \"b\")",
"CREATE BACKUP COLLECTION `-naMe` DATABASE WITH (a = \"b\");\n"},
{"creAte BackuP colLection `-naMe` ( tabLe `tbl1` , TablE `tbl2`) wIth (a = \"b\")",
"CREATE BACKUP COLLECTION `-naMe` (TABLE `tbl1`, TABLE `tbl2`) WITH (a = \"b\");\n"},
{"alTer bACKuP coLLECTION naMe resEt (b, c), seT (x=y, z=false)",
"ALTER BACKUP COLLECTION naMe\n\tRESET (b, c),\n\tSET (x = y, z = FALSE);\n"},
{"alTer bACKuP coLLECTION naMe aDD DATAbase",
Expand Down
18 changes: 13 additions & 5 deletions ydb/library/yql/sql/v1/sql_query.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1388,16 +1388,24 @@ bool TSqlQuery::Statement(TVector<TNodePtr>& blocks, const TRule_sql_stmt_core&
}

std::map<TString, TDeferredAtom> kv;
if (!ParseBackupCollectionSettings(kv, node.GetRule_backup_collection_settings5())) {
if (!ParseBackupCollectionSettings(kv, node.GetRule_backup_collection_settings6())) {
return false;
}

bool database = false;
TVector<TDeferredAtom> tables;
if (node.HasBlock7()) {
database = node.GetBlock7().GetRule_database_or_table_list1().has_alt_database_or_table_list1();
if (node.GetBlock7().GetRule_database_or_table_list1().has_alt_database_or_table_list2()) {
if (!ParseBackupCollectionTables(tables, node.GetBlock7().GetRule_database_or_table_list1().alt_database_or_table_list2().rule_table_list1())) {
if (node.HasBlock3()) {
database = node.GetBlock3().GetRule_create_backup_collection_entries1().has_alt_create_backup_collection_entries1();
if (node.GetBlock3().GetRule_create_backup_collection_entries1().has_alt_create_backup_collection_entries2()) {
if (!ParseBackupCollectionTables(
tables,
node
.GetBlock3()
.GetRule_create_backup_collection_entries1()
.alt_create_backup_collection_entries2()
.GetRule_create_backup_collection_entries_many1()
.GetRule_table_list2()))
{
return false;
}
}
Expand Down
27 changes: 11 additions & 16 deletions ydb/library/yql/sql/v1/sql_ut.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7051,11 +7051,10 @@ Y_UNIT_TEST_SUITE(BackupCollection) {
Y_UNIT_TEST(CreateBackupCollectionWithDatabase) {
NYql::TAstParseResult res = SqlToYql(R"sql(
USE plato;
CREATE BACKUP COLLECTION TestCollection WITH (
CREATE BACKUP COLLECTION TestCollection DATABASE WITH (
STORAGE="local",
TAG="test" -- for testing purposes, not a real thing
)
DATABASE;
);
)sql");
UNIT_ASSERT_C(res.Root, res.Issues.ToString());

Expand All @@ -7077,12 +7076,13 @@ Y_UNIT_TEST_SUITE(BackupCollection) {
Y_UNIT_TEST(CreateBackupCollectionWithTables) {
NYql::TAstParseResult res = SqlToYql(R"sql(
USE plato;
CREATE BACKUP COLLECTION TestCollection WITH (
CREATE BACKUP COLLECTION TestCollection (
TABLE someTable,
TABLE `prefix/anotherTable`
) WITH (
STORAGE="local",
TAG="test" -- for testing purposes, not a real thing
)
TABLE someTable,
TABLE `prefix/anotherTable`;
);
)sql");
UNIT_ASSERT_C(res.Root, res.Issues.ToString());

Expand Down Expand Up @@ -7110,18 +7110,13 @@ Y_UNIT_TEST_SUITE(BackupCollection) {

ExpectFailWithError(R"sql(
USE plato;
CREATE BACKUP COLLECTION TestCollection TABLE;
)sql" , "<main>:3:56: Error: Unexpected token 'TABLE' : syntax error...\n\n");

ExpectFailWithError(R"sql(
USE plato;
CREATE BACKUP COLLECTION TestCollection DATABASE `test`;
)sql" , "<main>:3:56: Error: Unexpected token 'DATABASE' : syntax error...\n\n");
CREATE BACKUP COLLECTION TABLE TestCollection;
)sql" , "<main>:3:47: Error: Unexpected token 'TestCollection' : syntax error...\n\n");

ExpectFailWithError(R"sql(
USE plato;
CREATE BACKUP COLLECTION TestCollection DATABASE, TABLE `test`;
)sql" , "<main>:3:56: Error: Unexpected token 'DATABASE' : syntax error...\n\n");
CREATE BACKUP COLLECTION DATABASE `test` TestCollection;
)sql" , "<main>:3:50: Error: Unexpected token '`test`' : syntax error...\n\n");

ExpectFailWithError(R"sql(
USE plato;
Expand Down
29 changes: 12 additions & 17 deletions ydb/library/yql/sql/v1/sql_ut_antlr4.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7048,11 +7048,10 @@ Y_UNIT_TEST_SUITE(BackupCollection) {
Y_UNIT_TEST(CreateBackupCollectionWithDatabase) {
NYql::TAstParseResult res = SqlToYql(R"sql(
USE plato;
CREATE BACKUP COLLECTION TestCollection WITH (
CREATE BACKUP COLLECTION TestCollection DATABASE WITH (
STORAGE="local",
TAG="test" -- for testing purposes, not a real thing
)
DATABASE;
);
)sql");
UNIT_ASSERT_C(res.Root, res.Issues.ToString());

Expand All @@ -7074,12 +7073,13 @@ Y_UNIT_TEST_SUITE(BackupCollection) {
Y_UNIT_TEST(CreateBackupCollectionWithTables) {
NYql::TAstParseResult res = SqlToYql(R"sql(
USE plato;
CREATE BACKUP COLLECTION TestCollection WITH (
CREATE BACKUP COLLECTION TestCollection (
TABLE someTable,
TABLE `prefix/anotherTable`
) WITH (
STORAGE="local",
TAG="test" -- for testing purposes, not a real thing
)
TABLE someTable,
TABLE `prefix/anotherTable`;
);
)sql");
UNIT_ASSERT_C(res.Root, res.Issues.ToString());

Expand All @@ -7103,22 +7103,17 @@ Y_UNIT_TEST_SUITE(BackupCollection) {
ExpectFailWithError(R"sql(
USE plato;
CREATE BACKUP COLLECTION TestCollection;
)sql" , "<main>:3:55: Error: mismatched input ';' expecting WITH\n");

ExpectFailWithError(R"sql(
USE plato;
CREATE BACKUP COLLECTION TestCollection TABLE;
)sql" , "<main>:3:56: Error: mismatched input 'TABLE' expecting WITH\n");
)sql" , "<main>:3:55: Error: mismatched input ';' expecting {'(', DATABASE, WITH}\n");

ExpectFailWithError(R"sql(
USE plato;
CREATE BACKUP COLLECTION TestCollection DATABASE `test`;
)sql" , "<main>:3:56: Error: mismatched input 'DATABASE' expecting WITH\n");
CREATE BACKUP COLLECTION TABLE TestCollection;
)sql" , "<main>:3:47: Error: mismatched input 'TestCollection' expecting {'(', DATABASE, WITH}\n");

ExpectFailWithError(R"sql(
USE plato;
CREATE BACKUP COLLECTION TestCollection DATABASE, TABLE `test`;
)sql" , "<main>:3:56: Error: mismatched input 'DATABASE' expecting WITH\n");
CREATE BACKUP COLLECTION DATABASE `test` TestCollection;
)sql" , "<main>:3:50: Error: mismatched input '`test`' expecting {'(', DATABASE, WITH}\n");

ExpectFailWithError(R"sql(
USE plato;
Expand Down

0 comments on commit 7f4d37b

Please sign in to comment.