diff options
author | areredify <areredify@yandex-team.com> | 2023-11-02 14:48:43 +0300 |
---|---|---|
committer | areredify <areredify@yandex-team.com> | 2023-11-02 16:14:30 +0300 |
commit | 7bb2ef5057a017f193e0c790e16dac7e78891c26 (patch) | |
tree | 1f4d3043dc4ce895ccdf0ed825e705fcab63b850 | |
parent | 5e305fbb63daa7aba667d6d3a519237b97808278 (diff) | |
download | ydb-7bb2ef5057a017f193e0c790e16dac7e78891c26.tar.gz |
add trailing comma to CREATE TABLE
add an optional trailing comma to create table entries in CREATE TABLE
-rw-r--r-- | ydb/library/yql/sql/v1/SQLv1.g.in | 2 | ||||
-rw-r--r-- | ydb/library/yql/sql/v1/format/sql_format.cpp | 13 | ||||
-rw-r--r-- | ydb/library/yql/sql/v1/format/sql_format_ut.cpp | 11 | ||||
-rw-r--r-- | ydb/library/yql/sql/v1/sql_query.cpp | 18 | ||||
-rw-r--r-- | ydb/library/yql/sql/v1/sql_ut.cpp | 5 |
5 files changed, 34 insertions, 15 deletions
diff --git a/ydb/library/yql/sql/v1/SQLv1.g.in b/ydb/library/yql/sql/v1/SQLv1.g.in index 4cce86125a..d23bf0f090 100644 --- a/ydb/library/yql/sql/v1/SQLv1.g.in +++ b/ydb/library/yql/sql/v1/SQLv1.g.in @@ -602,7 +602,7 @@ object_features: object_feature | LPAREN object_feature (COMMA object_feature)* object_type_ref: an_id_or_type; -create_table_stmt: CREATE (TABLE | TABLESTORE | EXTERNAL TABLE) simple_table_ref LPAREN create_table_entry (COMMA create_table_entry)* RPAREN +create_table_stmt: CREATE (TABLE | TABLESTORE | EXTERNAL TABLE) simple_table_ref LPAREN create_table_entry (COMMA create_table_entry)* COMMA? RPAREN table_inherits? table_partition_by? with_table_settings? diff --git a/ydb/library/yql/sql/v1/format/sql_format.cpp b/ydb/library/yql/sql/v1/format/sql_format.cpp index c56742d966..a018f38310 100644 --- a/ydb/library/yql/sql/v1/format/sql_format.cpp +++ b/ydb/library/yql/sql/v1/format/sql_format.cpp @@ -651,14 +651,13 @@ private: NewLine(); Visit(b.GetRule_create_table_entry2()); } + if (msg.HasBlock7()) { + Visit(msg.GetBlock7()); + } PopCurrentIndent(); NewLine(); - Visit(msg.GetToken7()); - if (msg.HasBlock8()) { - NewLine(); - Visit(msg.GetBlock8()); - } + Visit(msg.GetToken8()); if (msg.HasBlock9()) { NewLine(); Visit(msg.GetBlock9()); @@ -671,6 +670,10 @@ private: NewLine(); Visit(msg.GetBlock11()); } + if (msg.HasBlock12()) { + NewLine(); + Visit(msg.GetBlock12()); + } } void VisitDropTable(const TRule_drop_table_stmt& msg) { diff --git a/ydb/library/yql/sql/v1/format/sql_format_ut.cpp b/ydb/library/yql/sql/v1/format/sql_format_ut.cpp index fbb205bb16..1699dbf9b5 100644 --- a/ydb/library/yql/sql/v1/format/sql_format_ut.cpp +++ b/ydb/library/yql/sql/v1/format/sql_format_ut.cpp @@ -1329,4 +1329,15 @@ FROM Input MATCH_RECOGNIZE (PATTERN (A) DEFINE A AS A); TSetup setup; setup.Run(cases); } + + Y_UNIT_TEST(CreateTableTrailingComma) { + TCases cases = { + {"CREATE TABLE tableName (Key Uint32, PRIMARY KEY (Key),);", + "CREATE TABLE tableName (\n\tKey Uint32,\n\tPRIMARY KEY (Key),\n);\n\n"}, + {"CREATE TABLE tableName (Key Uint32,);", + "CREATE TABLE tableName (\n\tKey Uint32,\n);\n\n"}, + }; + TSetup setup; + setup.Run(cases); + } } diff --git a/ydb/library/yql/sql/v1/sql_query.cpp b/ydb/library/yql/sql/v1/sql_query.cpp index 95765885d1..b2f18df5f5 100644 --- a/ydb/library/yql/sql/v1/sql_query.cpp +++ b/ydb/library/yql/sql/v1/sql_query.cpp @@ -177,33 +177,33 @@ bool TSqlQuery::Statement(TVector<TNodePtr>& blocks, const TRule_sql_stmt_core& } } - if (rule.HasBlock8()) { - Context().Error(GetPos(rule.GetBlock8().GetRule_table_inherits1().GetToken1())) + if (rule.HasBlock9()) { + Context().Error(GetPos(rule.GetBlock9().GetRule_table_inherits1().GetToken1())) << "INHERITS clause is not supported yet"; return false; } - if (rule.HasBlock9()) { + if (rule.HasBlock10()) { if (tableType == ETableType::TableStore) { - Context().Error(GetPos(rule.GetBlock9().GetRule_table_partition_by1().GetToken1())) + Context().Error(GetPos(rule.GetBlock10().GetRule_table_partition_by1().GetToken1())) << "PARTITION BY is not supported for TABLESTORE"; return false; } - const auto list = rule.GetBlock9().GetRule_table_partition_by1().GetRule_pure_column_list4(); + const auto list = rule.GetBlock10().GetRule_table_partition_by1().GetRule_pure_column_list4(); params.PartitionByColumns.push_back(IdEx(list.GetRule_an_id2(), *this)); for (auto& node : list.GetBlock3()) { params.PartitionByColumns.push_back(IdEx(node.GetRule_an_id2(), *this)); } } - if (rule.HasBlock10()) { - if (!CreateTableSettings(rule.GetBlock10().GetRule_with_table_settings1(), params)) { + if (rule.HasBlock11()) { + if (!CreateTableSettings(rule.GetBlock11().GetRule_with_table_settings1(), params)) { return false; } } - if (rule.HasBlock11()) { - Context().Error(GetPos(rule.GetBlock11().GetRule_table_tablestore1().GetToken1())) + if (rule.HasBlock12()) { + Context().Error(GetPos(rule.GetBlock12().GetRule_table_tablestore1().GetToken1())) << "TABLESTORE clause is not supported yet"; return false; } diff --git a/ydb/library/yql/sql/v1/sql_ut.cpp b/ydb/library/yql/sql/v1/sql_ut.cpp index 22da243ec8..1b807cd41e 100644 --- a/ydb/library/yql/sql/v1/sql_ut.cpp +++ b/ydb/library/yql/sql/v1/sql_ut.cpp @@ -2432,6 +2432,11 @@ Y_UNIT_TEST_SUITE(SqlParsingOnly) { Y_UNIT_TEST(AutoSampleWorksWithSubquery) { UNIT_ASSERT(SqlToYql("select * from (select * from plato.Input) sample 0.2").IsOk()); } + + Y_UNIT_TEST(CreateTableTrailingComma) { + UNIT_ASSERT(SqlToYql("USE plato; CREATE TABLE tableName (Key Uint32, PRIMARY KEY (Key),);").IsOk()); + UNIT_ASSERT(SqlToYql("USE plato; CREATE TABLE tableName (Key Uint32,);").IsOk()); + } } Y_UNIT_TEST_SUITE(ExternalFunction) { |