diff options
author | mrlolthe1st <mrlolthe1st@yandex-team.com> | 2022-09-21 01:29:41 +0300 |
---|---|---|
committer | mrlolthe1st <mrlolthe1st@yandex-team.com> | 2022-09-21 01:29:41 +0300 |
commit | 62fd1ae429a9401f4870113dcacb4b6d9da3cac9 (patch) | |
tree | 10ed394c2f1b22bae87ba467adb0905202ca2a0f | |
parent | 196b6fb2030654f8da700901c939461dfe077961 (diff) | |
download | ydb-62fd1ae429a9401f4870113dcacb4b6d9da3cac9.tar.gz |
fix: warn for OFFSET without ORDER BY
added warning for offset without order
-rw-r--r-- | ydb/library/yql/core/issue/protos/issue_id.proto | 1 | ||||
-rw-r--r-- | ydb/library/yql/core/issue/yql_issue.txt | 4 | ||||
-rw-r--r-- | ydb/library/yql/sql/v1/node.cpp | 4 | ||||
-rw-r--r-- | ydb/library/yql/sql/v1/node.h | 1 | ||||
-rw-r--r-- | ydb/library/yql/sql/v1/select.cpp | 11 |
5 files changed, 20 insertions, 1 deletions
diff --git a/ydb/library/yql/core/issue/protos/issue_id.proto b/ydb/library/yql/core/issue/protos/issue_id.proto index f866325f0f4..67a7c6b0b19 100644 --- a/ydb/library/yql/core/issue/protos/issue_id.proto +++ b/ydb/library/yql/core/issue/protos/issue_id.proto @@ -138,6 +138,7 @@ message TIssuesIds { YQL_UNUSED_HINT = 4534; YQL_DEPRECATED_POSITIONAL_SCHEMA = 4535; YQL_DUPLICATE_DECLARE = 4536; + YQL_OFFSET_WITHOUT_SORT = 4537; // yql parser errors YQL_NOT_ALLOWED_IN_DISCOVERY = 4600; diff --git a/ydb/library/yql/core/issue/yql_issue.txt b/ydb/library/yql/core/issue/yql_issue.txt index bde10483c60..2dd72cb447e 100644 --- a/ydb/library/yql/core/issue/yql_issue.txt +++ b/ydb/library/yql/core/issue/yql_issue.txt @@ -623,4 +623,8 @@ ids { ids { code: YT_FOLDER_INPUT_IS_NOT_A_FOLDER severity: S_ERROR +} +ids { + code: YQL_OFFSET_WITHOUT_SORT + severity: S_WARNING }
\ No newline at end of file diff --git a/ydb/library/yql/sql/v1/node.cpp b/ydb/library/yql/sql/v1/node.cpp index d69193ec018..bb5e410e777 100644 --- a/ydb/library/yql/sql/v1/node.cpp +++ b/ydb/library/yql/sql/v1/node.cpp @@ -293,6 +293,10 @@ const TString* INode::ModuleName() const { return nullptr; } +bool INode::HasSkip() const { + return false; +} + void INode::VisitTree(const TVisitFunc& func) const { TVisitNodeSet visited; VisitTree(func, visited); diff --git a/ydb/library/yql/sql/v1/node.h b/ydb/library/yql/sql/v1/node.h index 84be0f9be12..633143aa34c 100644 --- a/ydb/library/yql/sql/v1/node.h +++ b/ydb/library/yql/sql/v1/node.h @@ -169,6 +169,7 @@ namespace NSQLTranslationV1 { virtual bool IsSelect() const; virtual const TString* FuncName() const; virtual const TString* ModuleName() const; + virtual bool HasSkip() const; using TVisitFunc = std::function<bool (const INode&)>; using TVisitNodeSet = std::unordered_set<const INode*>; diff --git a/ydb/library/yql/sql/v1/select.cpp b/ydb/library/yql/sql/v1/select.cpp index f1de60ba734..e2dd68db4ee 100644 --- a/ydb/library/yql/sql/v1/select.cpp +++ b/ydb/library/yql/sql/v1/select.cpp @@ -2697,7 +2697,7 @@ TSourcePtr BuildOverWindowSource(TPosition pos, const TString& windowName, ISour class TSkipTakeNode final: public TAstListNode { public: TSkipTakeNode(TPosition pos, const TNodePtr& skip, const TNodePtr& take) - : TAstListNode(pos) + : TAstListNode(pos), IsSkipProvided_(!!skip) { TNodePtr select(AstNode("select")); if (skip) { @@ -2710,6 +2710,12 @@ public: TPtr DoClone() const final { return {}; } + + bool HasSkip() const { + return IsSkipProvided_; + } +private: + const bool IsSkipProvided_; }; TNodePtr BuildSkipTake(TPosition pos, const TNodePtr& skip, const TNodePtr& take) { @@ -2743,6 +2749,9 @@ public: if (!SkipTake->Init(ctx, FakeSource.Get())) { return false; } + if (SkipTake->HasSkip() && EOrderKind::Sort != Source->GetOrderKind()) { + ctx.Warning(Source->GetPos(), TIssuesIds::YQL_OFFSET_WITHOUT_SORT) << "LIMIT with OFFSET without ORDER BY may provide different results from run to run"; + } } return true; |