From 7f4d37b99e25e931918580a353dba7eed11407ee Mon Sep 17 00:00:00 2001 From: Innokentii Mokin Date: Mon, 21 Oct 2024 15:38:40 +0700 Subject: [PATCH] Align create backup collection entries grammar with corresponding topics grammar (#10580) --- ydb/library/yql/sql/v1/SQLv1.g.in | 5 ++-- ydb/library/yql/sql/v1/SQLv1Antlr4.g.in | 5 ++-- ydb/library/yql/sql/v1/format/sql_format_ut.h | 8 ++--- ydb/library/yql/sql/v1/sql_query.cpp | 18 ++++++++---- ydb/library/yql/sql/v1/sql_ut.cpp | 27 +++++++---------- ydb/library/yql/sql/v1/sql_ut_antlr4.cpp | 29 ++++++++----------- 6 files changed, 46 insertions(+), 46 deletions(-) diff --git a/ydb/library/yql/sql/v1/SQLv1.g.in b/ydb/library/yql/sql/v1/SQLv1.g.in index f9fd24ef8a9d..46f907409530 100644 --- a/ydb/library/yql/sql/v1/SQLv1.g.in +++ b/ydb/library/yql/sql/v1/SQLv1.g.in @@ -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)*; diff --git a/ydb/library/yql/sql/v1/SQLv1Antlr4.g.in b/ydb/library/yql/sql/v1/SQLv1Antlr4.g.in index 912ec5e4391b..3758c6f69c17 100644 --- a/ydb/library/yql/sql/v1/SQLv1Antlr4.g.in +++ b/ydb/library/yql/sql/v1/SQLv1Antlr4.g.in @@ -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)*; diff --git a/ydb/library/yql/sql/v1/format/sql_format_ut.h b/ydb/library/yql/sql/v1/format/sql_format_ut.h index 609fdd1a95ae..951bf4279898 100644 --- a/ydb/library/yql/sql/v1/format/sql_format_ut.h +++ b/ydb/library/yql/sql/v1/format/sql_format_ut.h @@ -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", diff --git a/ydb/library/yql/sql/v1/sql_query.cpp b/ydb/library/yql/sql/v1/sql_query.cpp index 664458a7ba55..36a348867315 100644 --- a/ydb/library/yql/sql/v1/sql_query.cpp +++ b/ydb/library/yql/sql/v1/sql_query.cpp @@ -1388,16 +1388,24 @@ bool TSqlQuery::Statement(TVector& blocks, const TRule_sql_stmt_core& } std::map kv; - if (!ParseBackupCollectionSettings(kv, node.GetRule_backup_collection_settings5())) { + if (!ParseBackupCollectionSettings(kv, node.GetRule_backup_collection_settings6())) { return false; } bool database = false; TVector 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; } } diff --git a/ydb/library/yql/sql/v1/sql_ut.cpp b/ydb/library/yql/sql/v1/sql_ut.cpp index ce51a739696e..b6b209a9bbe0 100644 --- a/ydb/library/yql/sql/v1/sql_ut.cpp +++ b/ydb/library/yql/sql/v1/sql_ut.cpp @@ -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()); @@ -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()); @@ -7110,18 +7110,13 @@ Y_UNIT_TEST_SUITE(BackupCollection) { ExpectFailWithError(R"sql( USE plato; - CREATE BACKUP COLLECTION TestCollection TABLE; - )sql" , "
:3:56: Error: Unexpected token 'TABLE' : syntax error...\n\n"); - - ExpectFailWithError(R"sql( - USE plato; - CREATE BACKUP COLLECTION TestCollection DATABASE `test`; - )sql" , "
:3:56: Error: Unexpected token 'DATABASE' : syntax error...\n\n"); + CREATE BACKUP COLLECTION TABLE TestCollection; + )sql" , "
:3:47: Error: Unexpected token 'TestCollection' : syntax error...\n\n"); ExpectFailWithError(R"sql( USE plato; - CREATE BACKUP COLLECTION TestCollection DATABASE, TABLE `test`; - )sql" , "
:3:56: Error: Unexpected token 'DATABASE' : syntax error...\n\n"); + CREATE BACKUP COLLECTION DATABASE `test` TestCollection; + )sql" , "
:3:50: Error: Unexpected token '`test`' : syntax error...\n\n"); ExpectFailWithError(R"sql( USE plato; diff --git a/ydb/library/yql/sql/v1/sql_ut_antlr4.cpp b/ydb/library/yql/sql/v1/sql_ut_antlr4.cpp index c753b2ea3ff4..95620865d4d6 100644 --- a/ydb/library/yql/sql/v1/sql_ut_antlr4.cpp +++ b/ydb/library/yql/sql/v1/sql_ut_antlr4.cpp @@ -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()); @@ -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()); @@ -7103,22 +7103,17 @@ Y_UNIT_TEST_SUITE(BackupCollection) { ExpectFailWithError(R"sql( USE plato; CREATE BACKUP COLLECTION TestCollection; - )sql" , "
:3:55: Error: mismatched input ';' expecting WITH\n"); - - ExpectFailWithError(R"sql( - USE plato; - CREATE BACKUP COLLECTION TestCollection TABLE; - )sql" , "
:3:56: Error: mismatched input 'TABLE' expecting WITH\n"); + )sql" , "
:3:55: Error: mismatched input ';' expecting {'(', DATABASE, WITH}\n"); ExpectFailWithError(R"sql( USE plato; - CREATE BACKUP COLLECTION TestCollection DATABASE `test`; - )sql" , "
:3:56: Error: mismatched input 'DATABASE' expecting WITH\n"); + CREATE BACKUP COLLECTION TABLE TestCollection; + )sql" , "
:3:47: Error: mismatched input 'TestCollection' expecting {'(', DATABASE, WITH}\n"); ExpectFailWithError(R"sql( USE plato; - CREATE BACKUP COLLECTION TestCollection DATABASE, TABLE `test`; - )sql" , "
:3:56: Error: mismatched input 'DATABASE' expecting WITH\n"); + CREATE BACKUP COLLECTION DATABASE `test` TestCollection; + )sql" , "
:3:50: Error: mismatched input '`test`' expecting {'(', DATABASE, WITH}\n"); ExpectFailWithError(R"sql( USE plato;