aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorvvvv <vvvv@ydb.tech>2023-07-31 15:15:27 +0300
committervvvv <vvvv@ydb.tech>2023-07-31 15:15:27 +0300
commitfb1bbff59f7094d0a7281b6685863e5ce77f337d (patch)
tree43779be83aa595e2df5c632209aadcae7a6c1613
parent9b78557ca29a91c6ca8c964cd6622431791cfd65 (diff)
downloadydb-fb1bbff59f7094d0a7281b6685863e5ce77f337d.tar.gz
Revert "Allow DISCARD in SUBQUERY"
This reverts commit ed52aaa7c82c291103226fea40649ca7b339f461, reversing changes made to c6884232d88ff395369713a4983fe964bc757ab9.
-rw-r--r--ydb/library/yql/sql/v1/node.cpp4
-rw-r--r--ydb/library/yql/sql/v1/node.h1
-rw-r--r--ydb/library/yql/sql/v1/select.cpp30
-rw-r--r--ydb/library/yql/sql/v1/sql_query.cpp11
-rw-r--r--ydb/library/yql/sql/v1/sql_select.cpp4
-rw-r--r--ydb/library/yql/sql/v1/sql_translation.cpp9
6 files changed, 10 insertions, 49 deletions
diff --git a/ydb/library/yql/sql/v1/node.cpp b/ydb/library/yql/sql/v1/node.cpp
index 79c92301dc..c13a6a2e6b 100644
--- a/ydb/library/yql/sql/v1/node.cpp
+++ b/ydb/library/yql/sql/v1/node.cpp
@@ -278,10 +278,6 @@ bool INode::IsSelect() const {
return false;
}
-bool INode::HasSelectResult() const {
- return false;
-}
-
const TString* INode::FuncName() const {
return nullptr;
}
diff --git a/ydb/library/yql/sql/v1/node.h b/ydb/library/yql/sql/v1/node.h
index f79a2d7d80..be900e88f9 100644
--- a/ydb/library/yql/sql/v1/node.h
+++ b/ydb/library/yql/sql/v1/node.h
@@ -174,7 +174,6 @@ namespace NSQLTranslationV1 {
void UseAsInner();
virtual bool UsedSubquery() const;
virtual bool IsSelect() const;
- virtual bool HasSelectResult() const;
virtual const TString* FuncName() const;
virtual const TString* ModuleName() const;
virtual bool HasSkip() const;
diff --git a/ydb/library/yql/sql/v1/select.cpp b/ydb/library/yql/sql/v1/select.cpp
index d7b1e57c31..79663eca9f 100644
--- a/ydb/library/yql/sql/v1/select.cpp
+++ b/ydb/library/yql/sql/v1/select.cpp
@@ -1160,10 +1160,6 @@ public:
return Settings;
}
- bool HasSelectResult() const final {
- return !Settings.Discard;
- }
-
TPtr DoClone() const final {
return new TReduceSource(Pos, Mode, Source->CloneSource(), CloneContainer(OrderBy),
CloneContainer(Keys), CloneContainer(Args), SafeClone(Udf), SafeClone(Having), Settings,
@@ -1380,10 +1376,6 @@ public:
return Settings;
}
- bool HasSelectResult() const override {
- return !Settings.Discard;
- }
-
TNodePtr DoClone() const final {
auto newSource = MakeIntrusive<TCompositeSelect>(Pos, Source->CloneSource(), OriginalSource->CloneSource(), Settings);
newSource->SetSubselects(CloneContainer(Subselects), CloneContainer(Grouping), CloneContainer(GroupByExpr));
@@ -1756,10 +1748,6 @@ public:
return true;
}
- bool HasSelectResult() const override {
- return !Settings.Discard;
- }
-
bool IsStream() const override {
return Source->IsStream();
}
@@ -2370,10 +2358,6 @@ public:
return false;
}
- bool HasSelectResult() const override {
- return !Settings.Discard;
- }
-
bool IsStream() const override {
return Source->IsStream();
}
@@ -2678,10 +2662,6 @@ public:
return true;
}
- bool HasSelectResult() const override {
- return !Settings.Discard;
- }
-
TWriteSettings GetWriteSettings() const override {
return Settings;
}
@@ -2876,10 +2856,6 @@ public:
return Source->IsSelect();
}
- bool HasSelectResult() const override {
- return Source->HasSelectResult();
- }
-
TPtr DoClone() const final {
return MakeIntrusive<TSelect>(Pos, Source->CloneSource(), SafeClone(SkipTake));
}
@@ -2915,10 +2891,6 @@ public:
return true;
}
- bool HasSelectResult() const override {
- return Source->HasSelectResult();
- }
-
bool DoInit(TContext& ctx, ISource* src) override {
if (!Source->Init(ctx, src)) {
return false;
@@ -2991,7 +2963,7 @@ public:
return false;
}
node = L(node, Y("let", "output", output));
- if (WriteResult || writeSettings.Discard) {
+ if (WriteResult) {
if (EOrderKind::None == Source->GetOrderKind() && ctx.UseUnordered(*Source)) {
node = L(node, Y("let", "output", Y("Unordered", "output")));
}
diff --git a/ydb/library/yql/sql/v1/sql_query.cpp b/ydb/library/yql/sql/v1/sql_query.cpp
index 40cd4a5aba..54ea1f4c73 100644
--- a/ydb/library/yql/sql/v1/sql_query.cpp
+++ b/ydb/library/yql/sql/v1/sql_query.cpp
@@ -2181,22 +2181,19 @@ TNodePtr TSqlQuery::Build(const TSQLv1ParserAST& ast) {
}
ui32 topLevelSelects = 0;
- bool hasTailOps = false;
for (auto& block : blocks) {
- if (block->HasSelectResult()) {
+ if (block->IsSelect()) {
++topLevelSelects;
- } else if (topLevelSelects) {
- hasTailOps = true;
}
}
- if ((Mode == NSQLTranslation::ESqlMode::SUBQUERY || Mode == NSQLTranslation::ESqlMode::LIMITED_VIEW) && (topLevelSelects != 1 || hasTailOps)) {
- Error() << "Strictly one select/process/reduce statement is expected at the end of "
+ if ((Mode == NSQLTranslation::ESqlMode::SUBQUERY || Mode == NSQLTranslation::ESqlMode::LIMITED_VIEW) && topLevelSelects != 1) {
+ Error() << "Strictly one select/process/reduce statement must be used in the "
<< (Mode == NSQLTranslation::ESqlMode::LIMITED_VIEW ? "view" : "subquery");
return nullptr;
}
- if (!Ctx.PragmaAutoCommit && Ctx.Settings.EndOfQueryCommit && IsQueryMode(Mode)) {
+ if (!Ctx.PragmaAutoCommit && Ctx.Settings.EndOfQueryCommit && IsQueryMode(Mode)) {
AddStatementToBlocks(blocks, BuildCommitClusters(Ctx.Pos()));
}
diff --git a/ydb/library/yql/sql/v1/sql_select.cpp b/ydb/library/yql/sql/v1/sql_select.cpp
index d2f4a87075..b525ca0cbf 100644
--- a/ydb/library/yql/sql/v1/sql_select.cpp
+++ b/ydb/library/yql/sql/v1/sql_select.cpp
@@ -1211,8 +1211,8 @@ TSqlSelect::TSelectKindResult TSqlSelect::SelectKind(const TRule_select_kind& no
{
const bool discard = node.HasBlock1();
const bool hasLabel = node.HasBlock3();
- if (hasLabel && (Mode == NSQLTranslation::ESqlMode::LIMITED_VIEW || Mode == NSQLTranslation::ESqlMode::SUBQUERY)) {
- Ctx.Error() << "INTO RESULT is not allowed in current mode";
+ if ((discard || hasLabel) && (Mode == NSQLTranslation::ESqlMode::LIMITED_VIEW || Mode == NSQLTranslation::ESqlMode::SUBQUERY)) {
+ Ctx.Error() << "DISCARD and INTO RESULT are not allowed in current mode";
return {};
}
diff --git a/ydb/library/yql/sql/v1/sql_translation.cpp b/ydb/library/yql/sql/v1/sql_translation.cpp
index 325bacc944..aaf4b53958 100644
--- a/ydb/library/yql/sql/v1/sql_translation.cpp
+++ b/ydb/library/yql/sql/v1/sql_translation.cpp
@@ -3970,17 +3970,14 @@ bool TSqlTranslation::DefineActionOrSubqueryStatement(const TRule_define_action_
const bool hasValidBody = DefineActionOrSubqueryBody(query, innerBlocks, stmt.GetRule_define_action_or_subquery_body8());
ui32 topLevelSelects = 0;
- bool hasTailOps = false;
for (auto& block : innerBlocks) {
- if (block->HasSelectResult()) {
+ if (block->IsSelect()) {
++topLevelSelects;
- } else if (topLevelSelects) {
- hasTailOps = true;
}
}
- if (isSubquery && (topLevelSelects != 1 || hasTailOps)) {
- Error() << "Strictly one select/process/reduce statement is expected at the end of subquery";
+ if (isSubquery && topLevelSelects != 1) {
+ Error() << "Strictly one select/process/reduce statement must be used in the subquery, got: " << topLevelSelects;
return false;
}