summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authoraneporada <[email protected]>2022-08-16 13:02:08 +0300
committeraneporada <[email protected]>2022-08-16 13:02:08 +0300
commit5b0b0165840f7441cd939b8e93416fd80891cb5e (patch)
tree3da693a8005a0b4f0894953740199a9888888409
parent50d4ea46ebb20bcfc369eebb40b9c7e36170cd91 (diff)
[] Fix world dependencies for immediate subqueries after IN
-rw-r--r--ydb/library/yql/sql/v1/context.cpp15
-rw-r--r--ydb/library/yql/sql/v1/context.h6
-rw-r--r--ydb/library/yql/sql/v1/sql.cpp16
3 files changed, 35 insertions, 2 deletions
diff --git a/ydb/library/yql/sql/v1/context.cpp b/ydb/library/yql/sql/v1/context.cpp
index 71c8d02a461..5ec69a5662a 100644
--- a/ydb/library/yql/sql/v1/context.cpp
+++ b/ydb/library/yql/sql/v1/context.cpp
@@ -140,6 +140,21 @@ TString TContext::MakeName(const TString& name) {
return str;
}
+void TContext::PushCurrentBlocks(TBlocks* blocks) {
+ YQL_ENSURE(blocks);
+ CurrentBlocks.push_back(blocks);
+}
+
+void TContext::PopCurrentBlocks() {
+ YQL_ENSURE(!CurrentBlocks.empty());
+ CurrentBlocks.pop_back();
+}
+
+TBlocks& TContext::GetCurrentBlocks() const {
+ YQL_ENSURE(!CurrentBlocks.empty());
+ return *CurrentBlocks.back();
+}
+
IOutputStream& TContext::Error(NYql::TIssueCode code) {
return Error(Pos(), code);
}
diff --git a/ydb/library/yql/sql/v1/context.h b/ydb/library/yql/sql/v1/context.h
index bfddf56c12d..bd1ff59f300 100644
--- a/ydb/library/yql/sql/v1/context.h
+++ b/ydb/library/yql/sql/v1/context.h
@@ -89,7 +89,10 @@ namespace NSQLTranslationV1 {
const NYql::TPosition& Pos() const;
- void ClearBlockScope();
+ void PushCurrentBlocks(TBlocks* blocks);
+ void PopCurrentBlocks();
+ TBlocks& GetCurrentBlocks() const;
+
TString MakeName(const TString& name);
IOutputStream& Error(NYql::TIssueCode code = NYql::TIssuesIds::DEFAULT_ERROR);
@@ -207,6 +210,7 @@ namespace NSQLTranslationV1 {
EColumnRefState ColumnReferenceState = EColumnRefState::Deny;
EColumnRefState TopLevelColumnReferenceState = EColumnRefState::Deny;
TString NoColumnErrorContext = "in current scope";
+ TVector<TBlocks*> CurrentBlocks;
public:
THashMap<TString, TNodePtr> Variables;
diff --git a/ydb/library/yql/sql/v1/sql.cpp b/ydb/library/yql/sql/v1/sql.cpp
index f966e1e61eb..1db7f5f41ab 100644
--- a/ydb/library/yql/sql/v1/sql.cpp
+++ b/ydb/library/yql/sql/v1/sql.cpp
@@ -31,6 +31,7 @@
#include <util/charset/wide.h>
#include <util/generic/array_ref.h>
+#include <util/generic/scope.h>
#include <util/generic/set.h>
#include <util/generic/ylimits.h>
#include <util/string/ascii.h>
@@ -4866,7 +4867,12 @@ TMaybe<TExprOrIdent> TSqlExpression::InAtomExpr(const TRule_in_atom_expr& node,
return {};
}
Ctx.IncrementMonCounter("sql_features", "InSubquery");
- result.Expr = BuildSelectResult(pos, std::move(source), false, Mode == NSQLTranslation::ESqlMode::SUBQUERY, Ctx.Scoped);
+ const auto alias = Ctx.MakeName("subquerynode");
+ const auto ref = Ctx.MakeName("subquery");
+ auto& blocks = Ctx.GetCurrentBlocks();
+ blocks.push_back(BuildSubquery(std::move(source), alias, Mode == NSQLTranslation::ESqlMode::SUBQUERY, -1, Ctx.Scoped));
+ blocks.back()->SetLabel(ref);
+ result.Expr = BuildSubqueryRef(blocks.back(), ref, -1);
break;
}
case TRule_in_atom_expr::kAltInAtomExpr8: {
@@ -10160,6 +10166,10 @@ TNodePtr TSqlQuery::Build(const TSQLv1ParserAST& ast) {
const auto& query = ast.GetRule_sql_query();
TVector<TNodePtr> blocks;
+ Ctx.PushCurrentBlocks(&blocks);
+ Y_DEFER {
+ Ctx.PopCurrentBlocks();
+ };
if (query.Alt_case() == TRule_sql_query::kAltSqlQuery1) {
const auto& statements = query.GetAlt_sql_query1().GetRule_sql_stmt_list1();
if (!Statement(blocks, statements.GetRule_sql_stmt2().GetRule_sql_stmt_core2())) {
@@ -10196,6 +10206,10 @@ TNodePtr TSqlQuery::Build(const TSQLv1ParserAST& ast) {
bool TSqlTranslation::DefineActionOrSubqueryBody(TSqlQuery& query, TBlocks& blocks, const TRule_define_action_or_subquery_body& body) {
if (body.HasBlock2()) {
+ Ctx.PushCurrentBlocks(&blocks);
+ Y_DEFER {
+ Ctx.PopCurrentBlocks();
+ };
if (!query.Statement(blocks, body.GetBlock2().GetRule_sql_stmt_core1())) {
return false;
}