diff options
author | flown4qqqq <flown4qqqq@yandex-team.com> | 2025-03-02 00:52:13 +0300 |
---|---|---|
committer | flown4qqqq <flown4qqqq@yandex-team.com> | 2025-03-02 01:16:41 +0300 |
commit | 199aeeaa8d7db8a474c4ea12634114b8fd17d079 (patch) | |
tree | 2e464bc34aeddaa1e037d730f33b8a03e6d8e86e /yql | |
parent | 247abd10e4b384dda8303047190443af033df23f (diff) | |
download | ydb-199aeeaa8d7db8a474c4ea12634114b8fd17d079.tar.gz |
Change the text of error for create user with password.
commit_hash:6631b600dda026c616983f0b08daa912beb0f5db
Diffstat (limited to 'yql')
-rw-r--r-- | yql/essentials/sql/v1/SQLv1.g.in | 5 | ||||
-rw-r--r-- | yql/essentials/sql/v1/SQLv1Antlr4.g.in | 5 | ||||
-rw-r--r-- | yql/essentials/sql/v1/sql_translation.cpp | 41 | ||||
-rw-r--r-- | yql/essentials/sql/v1/sql_ut_common.h | 47 |
4 files changed, 78 insertions, 20 deletions
diff --git a/yql/essentials/sql/v1/SQLv1.g.in b/yql/essentials/sql/v1/SQLv1.g.in index 1d7dca5185..dbec682803 100644 --- a/yql/essentials/sql/v1/SQLv1.g.in +++ b/yql/essentials/sql/v1/SQLv1.g.in @@ -845,8 +845,9 @@ role_name: an_id_or_type | bind_parameter; user_option: authentication_option | login_option; authentication_option: password_option | hash_option; -password_option: ENCRYPTED? PASSWORD expr; -hash_option: HASH expr; +password_option: ENCRYPTED? PASSWORD password_value; +password_value: STRING_VALUE | NULL; +hash_option: HASH STRING_VALUE; login_option: LOGIN | NOLOGIN; grant_permissions_stmt: GRANT permission_name_target ON an_id_schema (COMMA an_id_schema)* TO role_name (COMMA role_name)* COMMA? (WITH GRANT OPTION)?; diff --git a/yql/essentials/sql/v1/SQLv1Antlr4.g.in b/yql/essentials/sql/v1/SQLv1Antlr4.g.in index 8aff2bb89a..fb92a68f9a 100644 --- a/yql/essentials/sql/v1/SQLv1Antlr4.g.in +++ b/yql/essentials/sql/v1/SQLv1Antlr4.g.in @@ -844,8 +844,9 @@ role_name: an_id_or_type | bind_parameter; user_option: authentication_option | login_option; authentication_option: password_option | hash_option; -password_option: ENCRYPTED? PASSWORD expr; -hash_option: HASH expr; +password_option: ENCRYPTED? PASSWORD password_value; +password_value: STRING_VALUE | NULL; +hash_option: HASH STRING_VALUE; login_option: LOGIN | NOLOGIN; grant_permissions_stmt: GRANT permission_name_target ON an_id_schema (COMMA an_id_schema)* TO role_name (COMMA role_name)* COMMA? (WITH GRANT OPTION)?; diff --git a/yql/essentials/sql/v1/sql_translation.cpp b/yql/essentials/sql/v1/sql_translation.cpp index 71dfafb3c4..af492431c8 100644 --- a/yql/essentials/sql/v1/sql_translation.cpp +++ b/yql/essentials/sql/v1/sql_translation.cpp @@ -3819,35 +3819,44 @@ bool TSqlTranslation::RoleNameClause(const TRule_role_name& node, TDeferredAtom& } bool TSqlTranslation::PasswordParameter(const TRule_password_option& passwordOption, TUserParameters& result) { - // password_option: ENCRYPTED? PASSWORD expr; - TSqlExpression expr(Ctx, Mode); - TNodePtr password = expr.Build(passwordOption.GetRule_expr3()); - if (!password) { - Error() << "Couldn't parse the password"; - return false; + // password_option: ENCRYPTED? PASSWORD password_value; + // password_value: STRING_VALUE | NULL; + + const auto& token = passwordOption.GetRule_password_value3().GetToken1(); + TString stringValue(Ctx.Token(token)); + + if (to_lower(stringValue) == "null") { + // result.Password = default value + } else { + auto password = StringContent(Ctx, Ctx.Pos(), stringValue); + + if (!password) { + Error() << "Password should be enclosed into quotation marks."; + return false; + } + + result.Password = TDeferredAtom(Ctx.Pos(), std::move(password->Content)); } result.IsPasswordEncrypted = passwordOption.HasBlock1(); - if (!password->IsNull()) { - result.Password = MakeAtomFromExpression(Ctx.Pos(), Ctx, password); - } return true; } bool TSqlTranslation::HashParameter(const TRule_hash_option& hashOption, TUserParameters& result) { - // hash_option: HASH expr; - TSqlExpression expr(Ctx, Mode); - TNodePtr hash = expr.Build(hashOption.GetRule_expr2()); + // hash_option: HASH STRING_VALUE; + + const auto& token = hashOption.GetToken2(); + TString stringValue(Ctx.Token(token)); + + auto hash = StringContent(Ctx, Ctx.Pos(), stringValue); if (!hash) { - Error() << "Couldn't parse the hash of password"; + Error() << "Hash should be enclosed into quotation marks."; return false; } - if (!hash->IsNull()) { - result.Hash = MakeAtomFromExpression(Ctx.Pos(), Ctx, hash); - } + result.Hash = TDeferredAtom(Ctx.Pos(), std::move(hash->Content)); return true; } diff --git a/yql/essentials/sql/v1/sql_ut_common.h b/yql/essentials/sql/v1/sql_ut_common.h index 407cc31121..325b439b25 100644 --- a/yql/essentials/sql/v1/sql_ut_common.h +++ b/yql/essentials/sql/v1/sql_ut_common.h @@ -571,6 +571,53 @@ Y_UNIT_TEST_SUITE(SqlParsingOnly) { UNIT_ASSERT(reqAlterUser.IsOk()); } + Y_UNIT_TEST(CreateUserQoutas) { + { + auto req = SqlToYql(R"( + use plato; + CREATE USER user1 PASSWORD passwd; + )"); + +#if ANTLR_VER == 3 + TString error = "<main>:3:43: Error: Unexpected token 'passwd' : unexpected input : nothing is expected here\n\n"; +#else + TString error = "<main>:3:43: Error: mismatched input 'passwd' expecting {NULL, STRING_VALUE}\n"; +#endif + UNIT_ASSERT_VALUES_EQUAL(Err2Str(req), error); + UNIT_ASSERT(!req.Root); + } + + { + auto req = SqlToYql(R"( + use plato; + CREATE USER user2 PASSWORD NULL; + )"); + + UNIT_ASSERT(req.Root); + } + + { + auto req = SqlToYql(R"( + use plato; + CREATE USER user3 PASSWORD ''; + )"); + + UNIT_ASSERT(req.Root); + } + + + { + auto req = SqlToYql(R"( + use plato; + CREATE USER user1 PASSWORD 'password1'; + CREATE USER user2 PASSWORD 'password2'; + CREATE USER user3; + )"); + + UNIT_ASSERT(req.Root); + } + } + Y_UNIT_TEST(JoinWithoutConcreteColumns) { NYql::TAstParseResult res = SqlToYql( " use plato;" |