diff options
author | aneporada <aneporada@ydb.tech> | 2023-09-11 11:55:04 +0300 |
---|---|---|
committer | aneporada <aneporada@ydb.tech> | 2023-09-11 12:16:39 +0300 |
commit | f7014dce27f776085607cadfc5fcfc031e4229c1 (patch) | |
tree | 7830590b9a782f69edd806cbc1e7b1ca7e3b74a1 | |
parent | adec17cd3f8aacf90f45ea727c76ae67fd063eec (diff) | |
download | ydb-f7014dce27f776085607cadfc5fcfc031e4229c1.tar.gz |
Fix grammar ambiguity
-rw-r--r-- | ydb/library/yql/sql/v1/SQLv1.g.in | 6 | ||||
-rw-r--r-- | ydb/library/yql/sql/v1/sql_translation.cpp | 32 | ||||
-rw-r--r-- | ydb/library/yql/sql/v1/sql_ut.cpp | 30 |
3 files changed, 11 insertions, 57 deletions
diff --git a/ydb/library/yql/sql/v1/SQLv1.g.in b/ydb/library/yql/sql/v1/SQLv1.g.in index d575395d97..7dca784006 100644 --- a/ydb/library/yql/sql/v1/SQLv1.g.in +++ b/ydb/library/yql/sql/v1/SQLv1.g.in @@ -661,12 +661,10 @@ alter_table_rename_index_to: RENAME INDEX an_id TO an_id; alter_table_add_changefeed: ADD changefeed; alter_table_alter_changefeed: ALTER CHANGEFEED an_id changefeed_alter_settings; alter_table_drop_changefeed: DROP CHANGEFEED an_id; -column_constraint: - NOT? NULL - | DEFAULT expr; -column_schema: an_id_schema type_name_or_bind family_relation? column_constraint*; +column_schema: an_id_schema type_name_or_bind family_relation? opt_column_constraints; family_relation: FAMILY an_id; +opt_column_constraints: (NOT? NULL)? (DEFAULT expr)?; column_order_by_specification: an_id (ASC | DESC)?; table_constraint: diff --git a/ydb/library/yql/sql/v1/sql_translation.cpp b/ydb/library/yql/sql/v1/sql_translation.cpp index e410137e4e..4700fd3b5e 100644 --- a/ydb/library/yql/sql/v1/sql_translation.cpp +++ b/ydb/library/yql/sql/v1/sql_translation.cpp @@ -1198,30 +1198,16 @@ TMaybe<TSourcePtr> TSqlTranslation::AsTableImpl(const TRule_table_ref& node) { TMaybe<TColumnConstraints> ColumnConstraints(const TRule_column_schema& node, TTranslation& ctx) { TNodePtr defaultExpr = nullptr; bool nullable = true; - bool isNullableConstraintDefined = false; - for (size_t idx = 0; idx < node.Block4Size(); idx++) { - const auto &constraint = node.GetBlock4(idx).GetRule_column_constraint1(); - if (constraint.Alt_case() == TRule_column_constraint::kAltColumnConstraint1) { - const bool override = !constraint.GetAlt_column_constraint1().HasBlock1(); - if (isNullableConstraintDefined && nullable != override) { - ctx.Error() << "not null constraint is ambiguous"; - return {}; - } - - nullable = override; - isNullableConstraintDefined = true; - - } else if (constraint.Alt_case() == TRule_column_constraint::kAltColumnConstraint2) { - if (defaultExpr) { - ctx.Error() << "multiple default values are not allowed"; - return {}; - } - TSqlExpression expr(ctx.Context(), ctx.Context().Settings.Mode); - defaultExpr = expr.Build(constraint.GetAlt_column_constraint2().GetRule_expr2()); - if (!defaultExpr) { - return {}; - } + auto constraintsNode = node.GetRule_opt_column_constraints4(); + if (constraintsNode.HasBlock1()) { + nullable = !constraintsNode.GetBlock1().HasBlock1(); + } + if (constraintsNode.HasBlock2()) { + TSqlExpression expr(ctx.Context(), ctx.Context().Settings.Mode); + defaultExpr = expr.Build(constraintsNode.GetBlock2().GetRule_expr2()); + if (!defaultExpr) { + return {}; } } diff --git a/ydb/library/yql/sql/v1/sql_ut.cpp b/ydb/library/yql/sql/v1/sql_ut.cpp index 331e482d19..db82d61e9e 100644 --- a/ydb/library/yql/sql/v1/sql_ut.cpp +++ b/ydb/library/yql/sql/v1/sql_ut.cpp @@ -1918,36 +1918,6 @@ Y_UNIT_TEST_SUITE(SqlParsingOnly) { UNIT_ASSERT(!res.Root); } - Y_UNIT_TEST(DefaultValueColumn4) { - auto res = SqlToYql(R"( use plato; - - CREATE TABLE tableName ( - database_id Utf8, - cloud_id Utf8, - global_id Utf8 DEFAULT Utf8("Data") DEFAULT Utf8("Other"), - PRIMARY KEY (database_id) - ); - )"); - - UNIT_ASSERT_VALUES_EQUAL(Err2Str(res), "<main>:6:45: Error: multiple default values are not allowed\n"); - UNIT_ASSERT(!res.Root); - } - - Y_UNIT_TEST(DefaultValueColumn5) { - auto res = SqlToYql(R"( use plato; - - CREATE TABLE tableName ( - database_id Utf8, - cloud_id Utf8, - global_id Utf8 NULL NOT NULL, - PRIMARY KEY (database_id) - ); - )"); - - UNIT_ASSERT_VALUES_EQUAL(Err2Str(res), "<main>:6:27: Error: not null constraint is ambiguous\n"); - UNIT_ASSERT(!res.Root); - } - Y_UNIT_TEST(DefaultValueColumn) { auto res = SqlToYql(R"( use plato; CREATE TABLE tableName ( |