diff options
author | vitya-smirnov <[email protected]> | 2025-08-04 12:34:52 +0300 |
---|---|---|
committer | vitya-smirnov <[email protected]> | 2025-08-04 12:47:13 +0300 |
commit | 2193f20a163ea765183f000e8d4e1902a96fed71 (patch) | |
tree | 953970cf094d61a2808c7ffa30ef5b8d1b09f6c9 /yql/essentials/sql/v1/complete/analysis/global/named_node.cpp | |
parent | b775b25ed665fee10e5af9a506a151f761cad219 (diff) |
YQL-19747: Partially concat and resolve symbols
- Migrated GetId to a Partial Evaluation function.
- Centeralized named expressions collection.
- Centeralized query parameters resolution.
- Supported symbols resolution and concatenation.
- Migrated USE and Columns Syntesis on the evaluation.
commit_hash:fafedc4330bcd4a7ab607ae1d5f2691a2f5a60f2
Diffstat (limited to 'yql/essentials/sql/v1/complete/analysis/global/named_node.cpp')
-rw-r--r-- | yql/essentials/sql/v1/complete/analysis/global/named_node.cpp | 70 |
1 files changed, 60 insertions, 10 deletions
diff --git a/yql/essentials/sql/v1/complete/analysis/global/named_node.cpp b/yql/essentials/sql/v1/complete/analysis/global/named_node.cpp index 57223e73405..792bd3b04cc 100644 --- a/yql/essentials/sql/v1/complete/analysis/global/named_node.cpp +++ b/yql/essentials/sql/v1/complete/analysis/global/named_node.cpp @@ -14,9 +14,10 @@ namespace NSQLComplete { class TVisitor: public TSQLv1NarrowingVisitor { public: - TVisitor(const TParsedInput& input, THashSet<TString>* names) + TVisitor(const TParsedInput& input, TNamedNodes* names, const TEnvironment* env) : TSQLv1NarrowingVisitor(input) , Names_(names) + , Env_(env) { } @@ -32,7 +33,26 @@ namespace NSQLComplete { } std::any visitDeclare_stmt(SQLv1::Declare_stmtContext* ctx) override { - VisitNullable(ctx->bind_parameter()); + auto* parameter = ctx->bind_parameter(); + if (!parameter) { + return {}; + } + + TMaybe<std::string> id = GetName(parameter); + if (id.Empty() || id == "_") { + return {}; + } + + id->insert(0, "$"); + const NYT::TNode* node = Env_->Parameters.FindPtr(*id); + id->erase(0, 1); + + if (node) { + (*Names_)[*id] = *node; + } else { + (*Names_)[*id] = std::monostate(); + } + return {}; } @@ -53,8 +73,37 @@ namespace NSQLComplete { std::any visitNamed_nodes_stmt(SQLv1::Named_nodes_stmtContext* ctx) override { VisitNullable(ctx->bind_parameter_list()); if (IsEnclosing(ctx)) { - return visitChildren(ctx); + visitChildren(ctx); + } + + auto* list = ctx->bind_parameter_list(); + if (!list) { + return {}; + } + + auto parameters = list->bind_parameter(); + if (parameters.size() != 1) { + return {}; + } + + auto* parameter = parameters[0]; + if (!parameter) { + return {}; } + + TMaybe<std::string> id = GetName(parameter); + if (id.Empty() || id == "_") { + return {}; + } + + if (auto* expr = ctx->expr()) { + (*Names_)[std::move(*id)] = expr; + } else if (auto* subselect = ctx->subselect_stmt()) { + (*Names_)[std::move(*id)] = subselect; + } else { + (*Names_)[std::move(*id)] = std::monostate(); + } + return {}; } @@ -85,12 +134,12 @@ namespace NSQLComplete { return {}; } - TMaybe<std::string> id = GetId(ctx); + TMaybe<std::string> id = GetName(ctx); if (id.Empty() || id == "_") { return {}; } - Names_->emplace(std::move(*id)); + (*Names_)[std::move(*id)] = std::monostate(); return {}; } @@ -102,15 +151,16 @@ namespace NSQLComplete { visit(tree); } - THashSet<TString>* Names_; + TNamedNodes* Names_; + const TEnvironment* Env_; }; } // namespace - TVector<TString> CollectNamedNodes(TParsedInput input) { - THashSet<TString> names; - TVisitor(input, &names).visit(input.SqlQuery); - return TVector<TString>(begin(names), end(names)); + TNamedNodes CollectNamedNodes(TParsedInput input, const TEnvironment& env) { + TNamedNodes names; + TVisitor(input, &names, &env).visit(input.SqlQuery); + return names; } } // namespace NSQLComplete |