aboutsummaryrefslogtreecommitdiffstats
path: root/yql/essentials/sql/v1/query.cpp
diff options
context:
space:
mode:
authorflown4qqqq <flown4qqqq@yandex-team.com>2025-01-24 00:47:07 +0300
committerflown4qqqq <flown4qqqq@yandex-team.com>2025-01-24 01:01:16 +0300
commitbf896a57c7a7ffb14ba93068a4c3efeab50dfb36 (patch)
tree38715f12c0ddf2192da62ab1a41f119c0293e1e2 /yql/essentials/sql/v1/query.cpp
parente0834724754ae9e26fd14e27027e69cc22d1939f (diff)
downloadydb-bf896a57c7a7ffb14ba93068a4c3efeab50dfb36.tar.gz
Add option 'HASH' into CREATE USER
Need for: <https://github.com/ydb-platform/ydb-rfc/blob/main/backup_fstek.md> ``` CREATE USER my_user HASH ' {"hash": "p4ffeMugohqyBwyckYCK1TjJfz3LIHbKiGL+t+oEhzw=", "salt": "U+tzBtgo06EBQCjlARA6Jg==", "type": "argon2id" }' ``` commit_hash:a0c695c2e2f7f794e5c4db978fe33a7bfea59e2c
Diffstat (limited to 'yql/essentials/sql/v1/query.cpp')
-rw-r--r--yql/essentials/sql/v1/query.cpp166
1 files changed, 81 insertions, 85 deletions
diff --git a/yql/essentials/sql/v1/query.cpp b/yql/essentials/sql/v1/query.cpp
index a1323972c4..8ed6827cf3 100644
--- a/yql/essentials/sql/v1/query.cpp
+++ b/yql/essentials/sql/v1/query.cpp
@@ -842,7 +842,7 @@ TNodePtr BuildTableKeys(TPosition pos, const TString& service, const TDeferredAt
return new TPrepTableKeys(pos, service, cluster, func, args);
}
-class TInputOptions final: public TAstListNode {
+class TInputOptions final : public TAstListNode {
public:
TInputOptions(TPosition pos, const TTableHints& hints)
: TAstListNode(pos)
@@ -889,7 +889,7 @@ TNodePtr BuildInputOptions(TPosition pos, const TTableHints& hints) {
return new TInputOptions(pos, hints);
}
-class TIntoTableOptions: public TAstListNode {
+class TIntoTableOptions : public TAstListNode {
public:
TIntoTableOptions(TPosition pos, const TVector<TString>& columns, const TTableHints& hints)
: TAstListNode(pos)
@@ -944,7 +944,7 @@ TNodePtr BuildIntoTableOptions(TPosition pos, const TVector<TString>& eraseColum
return new TIntoTableOptions(pos, eraseColumns, hints);
}
-class TInputTablesNode final: public TAstListNode {
+class TInputTablesNode final : public TAstListNode {
public:
TInputTablesNode(TPosition pos, const TTableList& tables, bool inSubquery, TScopedStatePtr scoped)
: TAstListNode(pos)
@@ -1000,7 +1000,7 @@ TNodePtr BuildInputTables(TPosition pos, const TTableList& tables, bool inSubque
return new TInputTablesNode(pos, tables, inSubquery, scoped);
}
-class TCreateTableNode final: public TAstListNode {
+class TCreateTableNode final : public TAstListNode {
public:
TCreateTableNode(TPosition pos, const TTableRef& tr, bool existingOk, bool replaceIfExists, const TCreateTableParameters& params, TSourcePtr values, TScopedStatePtr scoped)
: TAstListNode(pos)
@@ -1314,7 +1314,7 @@ TNodePtr BuildCreateTable(TPosition pos, const TTableRef& tr, bool existingOk, b
return new TCreateTableNode(pos, tr, existingOk, replaceIfExists, params, std::move(values), scoped);
}
-class TAlterTableNode final: public TAstListNode {
+class TAlterTableNode final : public TAstListNode {
public:
TAlterTableNode(TPosition pos, const TTableRef& tr, const TAlterTableParameters& params, TScopedStatePtr scoped)
: TAstListNode(pos)
@@ -1544,7 +1544,7 @@ TNodePtr BuildAlterTable(TPosition pos, const TTableRef& tr, const TAlterTablePa
return new TAlterTableNode(pos, tr, params, scoped);
}
-class TDropTableNode final: public TAstListNode {
+class TDropTableNode final : public TAstListNode {
public:
TDropTableNode(TPosition pos, const TTableRef& tr, bool missingOk, ETableType tableType, TScopedStatePtr scoped)
: TAstListNode(pos)
@@ -1633,7 +1633,7 @@ static INode::TPtr CreateConsumerDesc(const TTopicConsumerDescription& desc, con
);
}
-class TCreateTopicNode final: public TAstListNode {
+class TCreateTopicNode final : public TAstListNode {
public:
TCreateTopicNode(TPosition pos, const TTopicRef& tr, const TCreateTopicParameters& params, TScopedStatePtr scoped)
: TAstListNode(pos)
@@ -1725,7 +1725,7 @@ TNodePtr BuildCreateTopic(
return new TCreateTopicNode(pos, tr, params, scoped);
}
-class TAlterTopicNode final: public TAstListNode {
+class TAlterTopicNode final : public TAstListNode {
public:
TAlterTopicNode(TPosition pos, const TTopicRef& tr, const TAlterTopicParameters& params, TScopedStatePtr scoped)
: TAstListNode(pos)
@@ -1847,7 +1847,7 @@ TNodePtr BuildAlterTopic(
return new TAlterTopicNode(pos, tr, params, scoped);
}
-class TDropTopicNode final: public TAstListNode {
+class TDropTopicNode final : public TAstListNode {
public:
TDropTopicNode(TPosition pos, const TTopicRef& tr, const TDropTopicParameters& params, TScopedStatePtr scoped)
: TAstListNode(pos)
@@ -1895,37 +1895,47 @@ TNodePtr BuildDropTopic(TPosition pos, const TTopicRef& tr, const TDropTopicPara
return new TDropTopicNode(pos, tr, params, scoped);
}
-class TCreateRole final: public TAstListNode {
+class TControlUser final : public TAstListNode {
public:
- TCreateRole(TPosition pos, bool isUser, const TString& service, const TDeferredAtom& cluster, const TDeferredAtom& name, const TMaybe<TRoleParameters>& params, TScopedStatePtr scoped)
+ TControlUser(TPosition pos, const TString& service, const TDeferredAtom& cluster, const TDeferredAtom& name, const TMaybe<TUserParameters>& params, TScopedStatePtr scoped, bool IsCreateUser)
: TAstListNode(pos)
- , IsUser(isUser)
, Service(service)
, Cluster(cluster)
, Name(name)
, Params(params)
, Scoped(scoped)
+ , IsCreateUser(IsCreateUser)
{
FakeSource = BuildFakeSource(pos);
scoped->UseCluster(service, cluster);
}
- bool DoInit(TContext& ctx, ISource* src) override {
- Y_UNUSED(src);
+ bool DoInit(TContext& ctx, ISource*) override {
auto name = Name.Build();
TNodePtr password;
- if (Params && Params->Password) {
- password = Params->Password->Build();
+ TNodePtr hash;
+
+ if (Params) {
+ if (Params->Password) {
+ password = Params->Password->Build();
+ } else if (Params->Hash) {
+ hash = Params->Hash->Build();
+ }
}
+
TNodePtr cluster = Scoped->WrapCluster(Cluster, ctx);
- if (!name->Init(ctx, FakeSource.Get()) || !cluster->Init(ctx, FakeSource.Get())) {
- return false;
- }
- if (password && !password->Init(ctx, FakeSource.Get())) {
+ if (!name->Init(ctx, FakeSource.Get())
+ || !cluster->Init(ctx, FakeSource.Get())
+ || password && !password->Init(ctx, FakeSource.Get())
+ || hash && !hash->Init(ctx, FakeSource.Get())
+ )
+ {
return false;
}
+ auto options = Y(Q(Y(Q("mode"), Q(IsCreateUser ? "createUser" : "alterUser")))) ;
+
TVector<TNodePtr> roles;
if (Params && !Params->Roles.empty()) {
for (auto& item : Params->Roles) {
@@ -1934,9 +1944,10 @@ public:
return false;
}
}
+
+ options = L(options, Q(Y(Q("roles"), Q(new TAstListNodeImpl(Pos, std::move(roles))))));
}
- auto options = Y(Q(Y(Q("mode"), Q(IsUser ? "createUser" : "createGroup"))));
if (Params) {
if (Params->IsPasswordEncrypted) {
options = L(options, Q(Y(Q("passwordEncrypted"))));
@@ -1944,17 +1955,15 @@ public:
if (Params->Password) {
options = L(options, Q(Y(Q("password"), password)));
+ } else if (Params->Hash) {
+ options = L(options, Q(Y(Q("hash"), hash)));
} else {
options = L(options, Q(Y(Q("nullPassword"))));
}
- if (!Params->Roles.empty()) {
- options = L(options, Q(Y(Q("roles"), Q(new TAstListNodeImpl(Pos, std::move(roles))))));
- }
-
- if (Params->CanLogin == TRoleParameters::ETypeOfLogin::Login) {
+ if (Params->CanLogin.has_value() && Params->CanLogin.value() || !Params->CanLogin.has_value() && IsCreateUser) {
options = L(options, Q(Y(Q("login"))));
- } else if (Params->CanLogin == TRoleParameters::ETypeOfLogin::NoLogin) {
+ } else {
options = L(options, Q(Y(Q("noLogin"))));
}
}
@@ -1971,29 +1980,31 @@ public:
TPtr DoClone() const final {
return {};
}
+
private:
- const bool IsUser;
const TString Service;
TDeferredAtom Cluster;
TDeferredAtom Name;
- const TMaybe<TRoleParameters> Params;
+ const TMaybe<TUserParameters> Params;
TScopedStatePtr Scoped;
TSourcePtr FakeSource;
+ bool IsCreateUser;
};
-TNodePtr BuildCreateUser(TPosition pos, const TString& service, const TDeferredAtom& cluster, const TDeferredAtom& name, const TMaybe<TRoleParameters>& params, TScopedStatePtr scoped) {
- bool isUser = true;
- return new TCreateRole(pos, isUser, service, cluster, name, params, scoped);
-}
-
-TNodePtr BuildCreateGroup(TPosition pos, const TString& service, const TDeferredAtom& cluster, const TDeferredAtom& name, const TMaybe<TRoleParameters>& params, TScopedStatePtr scoped) {
- bool isUser = false;
- return new TCreateRole(pos, isUser, service, cluster, name, params, scoped);
+TNodePtr BuildControlUser( TPosition pos,
+ const TString& service,
+ const TDeferredAtom& cluster,
+ const TDeferredAtom& name,
+ const TMaybe<TUserParameters>& params,
+ TScopedStatePtr scoped,
+ bool isCreateUser)
+{
+ return new TControlUser(pos, service, cluster, name, params, scoped, isCreateUser);
}
-class TAlterUser final: public TAstListNode {
+class TCreateGroup final : public TAstListNode {
public:
- TAlterUser(TPosition pos, const TString& service, const TDeferredAtom& cluster, const TDeferredAtom& name, const TRoleParameters& params, TScopedStatePtr scoped)
+ TCreateGroup(TPosition pos, const TString& service, const TDeferredAtom& cluster, const TDeferredAtom& name, const TMaybe<TCreateGroupParameters>& params, TScopedStatePtr scoped)
: TAstListNode(pos)
, Service(service)
, Cluster(cluster)
@@ -2005,42 +2016,26 @@ public:
scoped->UseCluster(service, cluster);
}
- bool DoInit(TContext& ctx, ISource* src) override {
- Y_UNUSED(src);
- auto name = Name.Build();
- TNodePtr password;
- if (Params.Password) {
- password = Params.Password->Build();
- }
- TNodePtr cluster = Scoped->WrapCluster(Cluster, ctx);
-
- if (!name->Init(ctx, FakeSource.Get()) || !cluster->Init(ctx, FakeSource.Get())) {
- return false;
- }
- if (password && !password->Init(ctx, FakeSource.Get())) {
- return false;
- }
+ bool DoInit(TContext& ctx, ISource*) override {
+ auto options = Y(Q(Y(Q("mode"), Q("createGroup"))));
- auto options = Y(Q(Y(Q("mode"), Q("alterUser"))));
- if (Params.IsPasswordEncrypted) {
- options = L(options, Q(Y(Q("passwordEncrypted"))));
- }
+ TVector<TNodePtr> roles;
+ if (Params && !Params->Roles.empty()) {
+ for (auto& item : Params->Roles) {
+ roles.push_back(item.Build());
+ if (!roles.back()->Init(ctx, FakeSource.Get())) {
+ return false;
+ }
+ }
- if (Params.Password) {
- options = L(options, Q(Y(Q("password"), password)));
- } else {
- options = L(options, Q(Y(Q("nullPassword"))));
+ options = L(options, Q(Y(Q("roles"), Q(new TAstListNodeImpl(Pos, std::move(roles))))));
}
- if (Params.CanLogin == TRoleParameters::ETypeOfLogin::Login) {
- options = L(options, Q(Y(Q("login"))));
- } else if (Params.CanLogin == TRoleParameters::ETypeOfLogin::NoLogin) {
- options = L(options, Q(Y(Q("noLogin"))));
- }
+ TNodePtr cluster = Scoped->WrapCluster(Cluster, ctx);
Add("block", Q(Y(
Y("let", "sink", Y("DataSink", BuildQuotedAtom(Pos, Service), cluster)),
- Y("let", "world", Y(TString(WriteName), "world", "sink", Y("Key", Q(Y(Q("role"), Y("String", name)))), Y("Void"), Q(options))),
+ Y("let", "world", Y(TString(WriteName), "world", "sink", Y("Key", Q(Y(Q("role"), Y("String", Name.Build())))), Y("Void"), Q(options))),
Y("return", ctx.PragmaAutoCommit ? Y(TString(CommitName), "world", "sink") : AstNode("world"))
)));
@@ -2050,20 +2045,21 @@ public:
TPtr DoClone() const final {
return {};
}
+
private:
const TString Service;
TDeferredAtom Cluster;
TDeferredAtom Name;
- const TRoleParameters Params;
+ const TMaybe<TCreateGroupParameters> Params;
TScopedStatePtr Scoped;
TSourcePtr FakeSource;
};
-TNodePtr BuildAlterUser(TPosition pos, const TString& service, const TDeferredAtom& cluster, const TDeferredAtom& name, const TRoleParameters& params, TScopedStatePtr scoped) {
- return new TAlterUser(pos, service, cluster, name, params, scoped);
+TNodePtr BuildCreateGroup(TPosition pos, const TString& service, const TDeferredAtom& cluster, const TDeferredAtom& name, const TMaybe<TCreateGroupParameters>& params, TScopedStatePtr scoped) {
+ return new TCreateGroup(pos, service, cluster, name, params, scoped);
}
-class TAlterSequence final: public TAstListNode {
+class TAlterSequence final : public TAstListNode {
public:
TAlterSequence(TPosition pos, const TString& service, const TDeferredAtom& cluster, const TString& id, const TSequenceParameters& params, TScopedStatePtr scoped)
: TAstListNode(pos)
@@ -2167,7 +2163,7 @@ TNodePtr BuildAlterSequence(TPosition pos, const TString& service, const TDeferr
return new TAlterSequence(pos, service, cluster, id, params, scoped);
}
-class TRenameRole final: public TAstListNode {
+class TRenameRole final : public TAstListNode {
public:
TRenameRole(TPosition pos, bool isUser, const TString& service, const TDeferredAtom& cluster, const TDeferredAtom& name, const TDeferredAtom& newName, TScopedStatePtr scoped)
: TAstListNode(pos)
@@ -2230,7 +2226,7 @@ TNodePtr BuildRenameGroup(TPosition pos, const TString& service, const TDeferred
return new TRenameRole(pos, isUser, service, cluster, name, newName, scoped);
}
-class TAlterGroup final: public TAstListNode {
+class TAlterGroup final : public TAstListNode {
public:
TAlterGroup(TPosition pos, const TString& service, const TDeferredAtom& cluster, const TDeferredAtom& name, const TVector<TDeferredAtom>& toChange, bool isDrop, TScopedStatePtr scoped)
: TAstListNode(pos)
@@ -2293,7 +2289,7 @@ TNodePtr BuildAlterGroup(TPosition pos, const TString& service, const TDeferredA
return new TAlterGroup(pos, service, cluster, name, toChange, isDrop, scoped);
}
-class TDropRoles final: public TAstListNode {
+class TDropRoles final : public TAstListNode {
public:
TDropRoles(TPosition pos, const TString& service, const TDeferredAtom& cluster, const TVector<TDeferredAtom>& toDrop, bool isUser, bool missingOk, TScopedStatePtr scoped)
: TAstListNode(pos)
@@ -2517,7 +2513,7 @@ private:
}; // TAsyncReplication
-class TCreateAsyncReplication final: public TAsyncReplication {
+class TCreateAsyncReplication final : public TAsyncReplication {
public:
explicit TCreateAsyncReplication(TPosition pos, const TString& id,
std::vector<std::pair<TString, TString>>&& targets,
@@ -2571,7 +2567,7 @@ TNodePtr BuildCreateAsyncReplication(TPosition pos, const TString& id,
return new TCreateAsyncReplication(pos, id, std::move(targets), std::move(settings), context);
}
-class TDropAsyncReplication final: public TAsyncReplication {
+class TDropAsyncReplication final : public TAsyncReplication {
public:
explicit TDropAsyncReplication(TPosition pos, const TString& id, bool cascade, const TObjectOperatorContext& context)
: TAsyncReplication(pos, id, cascade ? "dropCascade" : "drop", context)
@@ -2589,7 +2585,7 @@ TNodePtr BuildDropAsyncReplication(TPosition pos, const TString& id, bool cascad
return new TDropAsyncReplication(pos, id, cascade, context);
}
-class TAlterAsyncReplication final: public TAsyncReplication {
+class TAlterAsyncReplication final : public TAsyncReplication {
public:
explicit TAlterAsyncReplication(TPosition pos, const TString& id,
std::map<TString, TNodePtr>&& settings,
@@ -2805,7 +2801,7 @@ static const TMap<EWriteColumnMode, TString> columnModeToStrMapKikimr {
{EWriteColumnMode::DeleteOn, "delete_on"},
};
-class TWriteTableNode final: public TAstListNode {
+class TWriteTableNode final : public TAstListNode {
public:
TWriteTableNode(TPosition pos, const TString& label, const TTableRef& table, EWriteColumnMode mode,
TNodePtr options, TScopedStatePtr scoped)
@@ -2876,7 +2872,7 @@ TNodePtr BuildWriteTable(TPosition pos, const TString& label, const TTableRef& t
return new TWriteTableNode(pos, label, table, mode, std::move(options), scoped);
}
-class TClustersSinkOperationBase: public TAstListNode {
+class TClustersSinkOperationBase : public TAstListNode {
protected:
TClustersSinkOperationBase(TPosition pos)
: TAstListNode(pos)
@@ -2936,7 +2932,7 @@ TNodePtr BuildRollbackClusters(TPosition pos) {
return new TRollbackClustersNode(pos);
}
-class TWriteResultNode final: public TAstListNode {
+class TWriteResultNode final : public TAstListNode {
public:
TWriteResultNode(TPosition pos, const TString& label, TNodePtr settings)
: TAstListNode(pos)
@@ -2972,7 +2968,7 @@ TNodePtr BuildWriteResult(TPosition pos, const TString& label, TNodePtr settings
return new TWriteResultNode(pos, label, settings);
}
-class TYqlProgramNode: public TAstListNode {
+class TYqlProgramNode : public TAstListNode {
public:
TYqlProgramNode(TPosition pos, const TVector<TNodePtr>& blocks, bool topLevel, TScopedStatePtr scoped, bool useSeq)
: TAstListNode(pos)
@@ -3310,7 +3306,7 @@ TNodePtr BuildQuery(TPosition pos, const TVector<TNodePtr>& blocks, bool topLeve
return new TYqlProgramNode(pos, blocks, topLevel, scoped, useSeq);
}
-class TPragmaNode final: public INode {
+class TPragmaNode final : public INode {
public:
TPragmaNode(TPosition pos, const TString& prefix, const TString& name, const TVector<TDeferredAtom>& values, bool valueDefault)
: INode(pos)
@@ -3394,7 +3390,7 @@ TNodePtr BuildPragma(TPosition pos, const TString& prefix, const TString& name,
return new TPragmaNode(pos, prefix, name, values, valueDefault);
}
-class TSqlLambda final: public TAstListNode {
+class TSqlLambda final : public TAstListNode {
public:
TSqlLambda(TPosition pos, TVector<TString>&& args, TVector<TNodePtr>&& exprSeq)
: TAstListNode(pos)
@@ -3553,7 +3549,7 @@ TNodePtr BuildWorldForNode(TPosition pos, TNodePtr list, TNodePtr bodyNode, TNod
return new TWorldFor(pos, list, bodyNode, elseNode, isEvaluate, isParallel);
}
-class TAnalyzeNode final: public TAstListNode {
+class TAnalyzeNode final : public TAstListNode {
public:
TAnalyzeNode(TPosition pos, const TString& service, const TDeferredAtom& cluster, const TAnalyzeParams& params, TScopedStatePtr scoped)
: TAstListNode(pos)