diff options
| author | vitya-smirnov <[email protected]> | 2025-10-07 09:34:39 +0300 |
|---|---|---|
| committer | vitya-smirnov <[email protected]> | 2025-10-07 09:52:14 +0300 |
| commit | babe7533f18c11be1f8a195ed2324d2d9a89436a (patch) | |
| tree | 45b7627141bf5a52b45a3d61fd1fbdd564bb8dd9 /yql/essentials/sql/v1/complete/analysis/global/function.cpp | |
| parent | 8fe7cfe254fde2772477a8933a163b5f303716b4 (diff) | |
YQL-20086 sql/v1
commit_hash:55bc611cdaa0d8a0fc3c4c7708ed9f17cc4976cf
Diffstat (limited to 'yql/essentials/sql/v1/complete/analysis/global/function.cpp')
| -rw-r--r-- | yql/essentials/sql/v1/complete/analysis/global/function.cpp | 170 |
1 files changed, 85 insertions, 85 deletions
diff --git a/yql/essentials/sql/v1/complete/analysis/global/function.cpp b/yql/essentials/sql/v1/complete/analysis/global/function.cpp index 510009f7ed8..017d42494ef 100644 --- a/yql/essentials/sql/v1/complete/analysis/global/function.cpp +++ b/yql/essentials/sql/v1/complete/analysis/global/function.cpp @@ -8,105 +8,105 @@ namespace NSQLComplete { - namespace { - - class TVisitor: public TSQLv1NarrowingVisitor { - public: - TVisitor(const TParsedInput& input, const TNamedNodes* nodes) - : TSQLv1NarrowingVisitor(input) - , Nodes_(nodes) - { - } - - std::any visit(antlr4::tree::ParseTree* tree) override { - if (IsEnclosing(tree)) { - return TSQLv1NarrowingVisitor::visit(tree); - } - return {}; - } +namespace { + +class TVisitor: public TSQLv1NarrowingVisitor { +public: + TVisitor(const TParsedInput& input, const TNamedNodes* nodes) + : TSQLv1NarrowingVisitor(input) + , Nodes_(nodes) + { + } - std::any visitTable_ref(SQLv1::Table_refContext* ctx) override { - auto* function = ctx->an_id_expr(); - auto* lparen = ctx->TOKEN_LPAREN(); - if (function == nullptr || lparen == nullptr) { - return {}; - } - if (CursorPosition() <= TextInterval(lparen).b) { - return {}; - } - - TMaybe<TFunctionContext> context = GetFunction(ctx, *Nodes_); - if (!context) { - return {}; - } - - const size_t argN = ArgumentNumber(ctx).GetOrElse(0); - context->ArgumentNumber = argN; - context->Arg0 = (argN != 0) ? context->Arg0 : Nothing(); - context->Arg1 = (argN != 1) ? context->Arg1 : Nothing(); - return *context; - } + std::any visit(antlr4::tree::ParseTree* tree) override { + if (IsEnclosing(tree)) { + return TSQLv1NarrowingVisitor::visit(tree); + } + return {}; + } - private: - TMaybe<size_t> ArgumentNumber(SQLv1::Table_refContext* ctx) const { - for (auto [i, arg] : Enumerate(ctx->table_arg())) { - if (IsEnclosing(arg)) { - return i; - } - } - return Nothing(); - } + std::any visitTable_ref(SQLv1::Table_refContext* ctx) override { + auto* function = ctx->an_id_expr(); + auto* lparen = ctx->TOKEN_LPAREN(); + if (function == nullptr || lparen == nullptr) { + return {}; + } + if (CursorPosition() <= TextInterval(lparen).b) { + return {}; + } - const TNamedNodes* Nodes_; - }; + TMaybe<TFunctionContext> context = GetFunction(ctx, *Nodes_); + if (!context) { + return {}; + } - TMaybe<TString> GetArgument(size_t index, SQLv1::Table_refContext* ctx, const TNamedNodes& nodes) { - auto* table_arg = ctx->table_arg(index); - if (!table_arg) { - return Nothing(); - } + const size_t argN = ArgumentNumber(ctx).GetOrElse(0); + context->ArgumentNumber = argN; + context->Arg0 = (argN != 0) ? context->Arg0 : Nothing(); + context->Arg1 = (argN != 1) ? context->Arg1 : Nothing(); + return *context; + } - auto* named_expr = table_arg->named_expr(); - if (!named_expr) { - return Nothing(); +private: + TMaybe<size_t> ArgumentNumber(SQLv1::Table_refContext* ctx) const { + for (auto [i, arg] : Enumerate(ctx->table_arg())) { + if (IsEnclosing(arg)) { + return i; } - - return ToObjectRef(PartiallyEvaluate(named_expr, nodes)); } + return Nothing(); + } - TMaybe<TClusterContext> GetCluster(SQLv1::Table_refContext* ctx, const TNamedNodes& nodes) { - auto* cluster_expr = ctx->cluster_expr(); - if (!cluster_expr) { - return Nothing(); - } + const TNamedNodes* Nodes_; +}; - return ParseClusterContext(cluster_expr, nodes); - } +TMaybe<TString> GetArgument(size_t index, SQLv1::Table_refContext* ctx, const TNamedNodes& nodes) { + auto* table_arg = ctx->table_arg(index); + if (!table_arg) { + return Nothing(); + } + + auto* named_expr = table_arg->named_expr(); + if (!named_expr) { + return Nothing(); + } - } // namespace + return ToObjectRef(PartiallyEvaluate(named_expr, nodes)); +} - TMaybe<TFunctionContext> EnclosingFunction(TParsedInput input, const TNamedNodes& nodes) { - std::any result = TVisitor(input, &nodes).visit(input.SqlQuery); - if (!result.has_value()) { - return Nothing(); - } - return std::any_cast<TFunctionContext>(result); +TMaybe<TClusterContext> GetCluster(SQLv1::Table_refContext* ctx, const TNamedNodes& nodes) { + auto* cluster_expr = ctx->cluster_expr(); + if (!cluster_expr) { + return Nothing(); } - TMaybe<TFunctionContext> GetFunction(SQLv1::Table_refContext* ctx, const TNamedNodes& nodes) { - auto* function = ctx->an_id_expr(); - auto* lparen = ctx->TOKEN_LPAREN(); - if (function == nullptr || lparen == nullptr) { - return Nothing(); - } + return ParseClusterContext(cluster_expr, nodes); +} - return TFunctionContext{ - .Name = function->getText(), - .ArgumentNumber = 0, - .Arg0 = GetArgument(0, ctx, nodes), - .Arg1 = GetArgument(1, ctx, nodes), - .Cluster = GetCluster(ctx, nodes), - }; +} // namespace + +TMaybe<TFunctionContext> EnclosingFunction(TParsedInput input, const TNamedNodes& nodes) { + std::any result = TVisitor(input, &nodes).visit(input.SqlQuery); + if (!result.has_value()) { + return Nothing(); + } + return std::any_cast<TFunctionContext>(result); +} + +TMaybe<TFunctionContext> GetFunction(SQLv1::Table_refContext* ctx, const TNamedNodes& nodes) { + auto* function = ctx->an_id_expr(); + auto* lparen = ctx->TOKEN_LPAREN(); + if (function == nullptr || lparen == nullptr) { + return Nothing(); } + return TFunctionContext{ + .Name = function->getText(), + .ArgumentNumber = 0, + .Arg0 = GetArgument(0, ctx, nodes), + .Arg1 = GetArgument(1, ctx, nodes), + .Cluster = GetCluster(ctx, nodes), + }; +} + } // namespace NSQLComplete |
