Skip to content

Commit 199aeea

Browse files
author
flown4qqqq
committed
Change the text of error for create user with password.
commit_hash:6631b600dda026c616983f0b08daa912beb0f5db
1 parent 247abd1 commit 199aeea

File tree

4 files changed

+78
-20
lines changed

4 files changed

+78
-20
lines changed

yql/essentials/sql/v1/SQLv1.g.in

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -845,8 +845,9 @@ role_name: an_id_or_type | bind_parameter;
845845
user_option: authentication_option | login_option;
846846

847847
authentication_option: password_option | hash_option;
848-
password_option: ENCRYPTED? PASSWORD expr;
849-
hash_option: HASH expr;
848+
password_option: ENCRYPTED? PASSWORD password_value;
849+
password_value: STRING_VALUE | NULL;
850+
hash_option: HASH STRING_VALUE;
850851
login_option: LOGIN | NOLOGIN;
851852

852853
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)?;

yql/essentials/sql/v1/SQLv1Antlr4.g.in

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -844,8 +844,9 @@ role_name: an_id_or_type | bind_parameter;
844844
user_option: authentication_option | login_option;
845845

846846
authentication_option: password_option | hash_option;
847-
password_option: ENCRYPTED? PASSWORD expr;
848-
hash_option: HASH expr;
847+
password_option: ENCRYPTED? PASSWORD password_value;
848+
password_value: STRING_VALUE | NULL;
849+
hash_option: HASH STRING_VALUE;
849850
login_option: LOGIN | NOLOGIN;
850851

851852
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)?;

yql/essentials/sql/v1/sql_translation.cpp

Lines changed: 25 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3819,35 +3819,44 @@ bool TSqlTranslation::RoleNameClause(const TRule_role_name& node, TDeferredAtom&
38193819
}
38203820

38213821
bool TSqlTranslation::PasswordParameter(const TRule_password_option& passwordOption, TUserParameters& result) {
3822-
// password_option: ENCRYPTED? PASSWORD expr;
3823-
TSqlExpression expr(Ctx, Mode);
3824-
TNodePtr password = expr.Build(passwordOption.GetRule_expr3());
3825-
if (!password) {
3826-
Error() << "Couldn't parse the password";
3827-
return false;
3822+
// password_option: ENCRYPTED? PASSWORD password_value;
3823+
// password_value: STRING_VALUE | NULL;
3824+
3825+
const auto& token = passwordOption.GetRule_password_value3().GetToken1();
3826+
TString stringValue(Ctx.Token(token));
3827+
3828+
if (to_lower(stringValue) == "null") {
3829+
// result.Password = default value
3830+
} else {
3831+
auto password = StringContent(Ctx, Ctx.Pos(), stringValue);
3832+
3833+
if (!password) {
3834+
Error() << "Password should be enclosed into quotation marks.";
3835+
return false;
3836+
}
3837+
3838+
result.Password = TDeferredAtom(Ctx.Pos(), std::move(password->Content));
38283839
}
38293840

38303841
result.IsPasswordEncrypted = passwordOption.HasBlock1();
3831-
if (!password->IsNull()) {
3832-
result.Password = MakeAtomFromExpression(Ctx.Pos(), Ctx, password);
3833-
}
38343842

38353843
return true;
38363844
}
38373845

38383846
bool TSqlTranslation::HashParameter(const TRule_hash_option& hashOption, TUserParameters& result) {
3839-
// hash_option: HASH expr;
3840-
TSqlExpression expr(Ctx, Mode);
3841-
TNodePtr hash = expr.Build(hashOption.GetRule_expr2());
3847+
// hash_option: HASH STRING_VALUE;
3848+
3849+
const auto& token = hashOption.GetToken2();
3850+
TString stringValue(Ctx.Token(token));
3851+
3852+
auto hash = StringContent(Ctx, Ctx.Pos(), stringValue);
38423853

38433854
if (!hash) {
3844-
Error() << "Couldn't parse the hash of password";
3855+
Error() << "Hash should be enclosed into quotation marks.";
38453856
return false;
38463857
}
38473858

3848-
if (!hash->IsNull()) {
3849-
result.Hash = MakeAtomFromExpression(Ctx.Pos(), Ctx, hash);
3850-
}
3859+
result.Hash = TDeferredAtom(Ctx.Pos(), std::move(hash->Content));
38513860

38523861
return true;
38533862
}

yql/essentials/sql/v1/sql_ut_common.h

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -571,6 +571,53 @@ Y_UNIT_TEST_SUITE(SqlParsingOnly) {
571571
UNIT_ASSERT(reqAlterUser.IsOk());
572572
}
573573

574+
Y_UNIT_TEST(CreateUserQoutas) {
575+
{
576+
auto req = SqlToYql(R"(
577+
use plato;
578+
CREATE USER user1 PASSWORD passwd;
579+
)");
580+
581+
#if ANTLR_VER == 3
582+
TString error = "<main>:3:43: Error: Unexpected token 'passwd' : unexpected input : nothing is expected here\n\n";
583+
#else
584+
TString error = "<main>:3:43: Error: mismatched input 'passwd' expecting {NULL, STRING_VALUE}\n";
585+
#endif
586+
UNIT_ASSERT_VALUES_EQUAL(Err2Str(req), error);
587+
UNIT_ASSERT(!req.Root);
588+
}
589+
590+
{
591+
auto req = SqlToYql(R"(
592+
use plato;
593+
CREATE USER user2 PASSWORD NULL;
594+
)");
595+
596+
UNIT_ASSERT(req.Root);
597+
}
598+
599+
{
600+
auto req = SqlToYql(R"(
601+
use plato;
602+
CREATE USER user3 PASSWORD '';
603+
)");
604+
605+
UNIT_ASSERT(req.Root);
606+
}
607+
608+
609+
{
610+
auto req = SqlToYql(R"(
611+
use plato;
612+
CREATE USER user1 PASSWORD 'password1';
613+
CREATE USER user2 PASSWORD 'password2';
614+
CREATE USER user3;
615+
)");
616+
617+
UNIT_ASSERT(req.Root);
618+
}
619+
}
620+
574621
Y_UNIT_TEST(JoinWithoutConcreteColumns) {
575622
NYql::TAstParseResult res = SqlToYql(
576623
" use plato;"

0 commit comments

Comments
 (0)