Skip to content

Commit 731eb6b

Browse files
committed
YQL-19845 introduced max released version, used in fastcheck/linter/purecalc & embedded
commit_hash:b5d1a0cb6f6eedc8b2a450091bde452ac628406d
1 parent 868c99f commit 731eb6b

23 files changed

+264
-55
lines changed
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#include "check_runner.h"
2+
#include <yql/essentials/core/langver/yql_core_langver.h>
3+
4+
namespace NYql {
5+
namespace NFastCheck {
6+
7+
TCheckResponse TCheckRunnerBase::Run(const TChecksRequest& request) {
8+
TMaybe<TIssue> verIssue;
9+
if (!CheckLangVersion(request.LangVer, GetMaxReleasedLangVersion(), verIssue)) {
10+
TCheckResponse response;
11+
response.Success = false;
12+
response.CheckName = GetCheckName();
13+
response.Issues.AddIssue(*verIssue);
14+
return response;
15+
}
16+
17+
auto ret = DoRun(request);
18+
if (!verIssue) {
19+
return ret;
20+
}
21+
22+
TCheckResponse response;
23+
response.Success = ret.Success;
24+
response.CheckName = GetCheckName();
25+
response.Issues.AddIssue(*verIssue);
26+
response.Issues.AddIssues(ret.Issues);
27+
return response;
28+
}
29+
30+
}
31+
}

yql/essentials/public/fastcheck/check_runner.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,14 @@ class ICheckRunner {
1212
virtual TCheckResponse Run(const TChecksRequest& request) = 0;
1313
};
1414

15+
class TCheckRunnerBase : public ICheckRunner {
16+
public:
17+
virtual TCheckResponse Run(const TChecksRequest& request) final;
18+
19+
protected:
20+
virtual TCheckResponse DoRun(const TChecksRequest& request) = 0;
21+
};
22+
1523
class ICheckRunnerFactory {
1624
public:
1725
virtual ~ICheckRunnerFactory() = default;

yql/essentials/public/fastcheck/fastcheck.cpp

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,22 @@
1212
#include <yql/essentials/sql/v1/proto_parser/antlr4/proto_parser.h>
1313
#include <yql/essentials/sql/v1/proto_parser/antlr4_ansi/proto_parser.h>
1414
#include <yql/essentials/parser/pg_wrapper/interface/parser.h>
15+
#include <yql/essentials/core/langver/yql_core_langver.h>
1516

1617
namespace NYql {
1718
namespace NFastCheck {
1819

1920
bool CheckProgram(const TString& program, const TOptions& options, TIssues& errors) {
21+
TMaybe<TIssue> verIssue;
22+
auto verCheck = CheckLangVersion(options.LangVer, GetMaxReleasedLangVersion(), verIssue);
23+
if (verIssue) {
24+
errors.AddIssue(*verIssue);
25+
}
26+
27+
if (!verCheck) {
28+
return false;
29+
}
30+
2031
NSQLTranslationV1::TLexers lexers;
2132
lexers.Antlr4 = NSQLTranslationV1::MakeAntlr4LexerFactory();
2233
lexers.Antlr4Ansi = NSQLTranslationV1::MakeAntlr4AnsiLexerFactory();
@@ -33,6 +44,7 @@ bool CheckProgram(const TString& program, const TOptions& options, TIssues& erro
3344
TAstParseResult astRes;
3445
if (options.IsSql) {
3546
NSQLTranslation::TTranslationSettings settings;
47+
settings.LangVer = options.LangVer;
3648
settings.ClusterMapping = options.ClusterMapping;
3749
settings.SyntaxVersion = options.SyntaxVersion;
3850
settings.V0Behavior = NSQLTranslation::EV0Behavior::Disable;
@@ -47,7 +59,7 @@ bool CheckProgram(const TString& program, const TOptions& options, TIssues& erro
4759
}
4860

4961
if (!astRes.IsOk()) {
50-
errors = std::move(astRes.Issues);
62+
errors.AddIssues(astRes.Issues);
5163
return false;
5264
}
5365

@@ -59,6 +71,7 @@ bool CheckProgram(const TString& program, const TOptions& options, TIssues& erro
5971
// parse SQL libs
6072
for (const auto& x : options.SqlLibs) {
6173
NSQLTranslation::TTranslationSettings settings;
74+
settings.LangVer = options.LangVer;
6275
settings.ClusterMapping = options.ClusterMapping;
6376
settings.SyntaxVersion = options.SyntaxVersion;
6477
settings.V0Behavior = NSQLTranslation::EV0Behavior::Disable;
@@ -67,7 +80,7 @@ bool CheckProgram(const TString& program, const TOptions& options, TIssues& erro
6780

6881
astRes = SqlToYql(translators, x.second, settings);
6982
if (!astRes.IsOk()) {
70-
errors = std::move(astRes.Issues);
83+
errors.AddIssues(astRes.Issues);
7184
return false;
7285
}
7386
}
@@ -90,7 +103,7 @@ bool CheckProgram(const TString& program, const TOptions& options, TIssues& erro
90103
IModuleResolver::TPtr moduleResolver;
91104
TUserDataTable userDataTable = GetYqlModuleResolver(libCtx, moduleResolver, userData, options.ClusterMapping, {});
92105
if (!userDataTable) {
93-
errors = libCtx.IssueManager.GetIssues();
106+
errors.AddIssues(libCtx.IssueManager.GetIssues());
94107
libCtx.IssueManager.Reset();
95108
return false;
96109
}
@@ -103,7 +116,7 @@ bool CheckProgram(const TString& program, const TOptions& options, TIssues& erro
103116
TExprContext exprCtx(libCtx.NextUniqueId);
104117
TExprNode::TPtr exprRoot;
105118
if (!CompileExpr(*astRes.Root, exprRoot, exprCtx, moduleResolver.get(), nullptr, false, Max<ui32>(), options.SyntaxVersion)) {
106-
errors = exprCtx.IssueManager.GetIssues();
119+
errors.AddIssues(exprCtx.IssueManager.GetIssues());
107120
exprCtx.IssueManager.Reset();
108121
return false;
109122
}

yql/essentials/public/fastcheck/fastcheck.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#include <yql/essentials/ast/yql_errors.h>
33
#include <util/generic/hash.h>
44
#include <yql/essentials/providers/common/provider/yql_provider_names.h>
5+
#include <yql/essentials/public/langver/yql_langver.h>
56

67
namespace NYql {
78
namespace NFastCheck {
@@ -11,6 +12,7 @@ struct TOptions {
1112
bool ParseOnly = false;
1213
THashMap<TString, TString> ClusterMapping;
1314
ui16 SyntaxVersion = 1;
15+
TLangVersion LangVer = MinLangVersion;
1416
bool IsLibrary = false;
1517
THashMap<TString, TString> SqlLibs = {}; // mapping file name => SQL
1618
};

yql/essentials/public/fastcheck/fastcheck_ut.cpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ using namespace NYql::NFastCheck;
77
Y_UNIT_TEST_SUITE(TFastCheckTests) {
88
Y_UNIT_TEST(ParsePureYqlGood) {
99
TOptions options;
10+
options.LangVer = GetMaxReleasedLangVersion();
1011
options.IsSql = false;
1112
options.ParseOnly = true;
1213
TIssues errors;
@@ -16,6 +17,7 @@ Y_UNIT_TEST_SUITE(TFastCheckTests) {
1617

1718
Y_UNIT_TEST(ParsePureYqlBad) {
1819
TOptions options;
20+
options.LangVer = GetMaxReleasedLangVersion();
1921
options.IsSql = false;
2022
options.ParseOnly = true;
2123
TIssues errors;
@@ -25,6 +27,7 @@ Y_UNIT_TEST_SUITE(TFastCheckTests) {
2527

2628
Y_UNIT_TEST(ParsePureSqlGood) {
2729
TOptions options;
30+
options.LangVer = GetMaxReleasedLangVersion();
2831
options.IsSql = true;
2932
options.ParseOnly = true;
3033
TIssues errors;
@@ -34,6 +37,7 @@ Y_UNIT_TEST_SUITE(TFastCheckTests) {
3437

3538
Y_UNIT_TEST(ParsePureSqlBad) {
3639
TOptions options;
40+
options.LangVer = GetMaxReleasedLangVersion();
3741
options.IsSql = true;
3842
options.ParseOnly = true;
3943
TIssues errors;
@@ -43,6 +47,7 @@ Y_UNIT_TEST_SUITE(TFastCheckTests) {
4347

4448
Y_UNIT_TEST(CompilePureYqlBad) {
4549
TOptions options;
50+
options.LangVer = GetMaxReleasedLangVersion();
4651
options.IsSql = false;
4752
options.ParseOnly = false;
4853
TIssues errors;
@@ -52,6 +57,7 @@ Y_UNIT_TEST_SUITE(TFastCheckTests) {
5257

5358
Y_UNIT_TEST(CompileTableSqlGood) {
5459
TOptions options;
60+
options.LangVer = GetMaxReleasedLangVersion();
5561
options.IsSql = true;
5662
options.ParseOnly = false;
5763
options.ClusterMapping["plato"] = YtProviderName;
@@ -62,6 +68,7 @@ Y_UNIT_TEST_SUITE(TFastCheckTests) {
6268

6369
Y_UNIT_TEST(CompileTableSqlBad) {
6470
TOptions options;
71+
options.LangVer = GetMaxReleasedLangVersion();
6572
options.IsSql = true;
6673
options.ParseOnly = false;
6774
TIssues errors;
@@ -71,6 +78,7 @@ Y_UNIT_TEST_SUITE(TFastCheckTests) {
7178

7279
Y_UNIT_TEST(CompileLibrary) {
7380
TOptions options;
81+
options.LangVer = GetMaxReleasedLangVersion();
7482
options.IsSql = true;
7583
options.IsLibrary = true;
7684
TIssues errors;
@@ -80,6 +88,7 @@ Y_UNIT_TEST_SUITE(TFastCheckTests) {
8088

8189
Y_UNIT_TEST(CompileSqlWithLibsGood) {
8290
TOptions options;
91+
options.LangVer = GetMaxReleasedLangVersion();
8392
options.IsSql = true;
8493
options.ParseOnly = false;
8594
options.SqlLibs["foo.sql"] = "$x = 1; export $x;";
@@ -90,6 +99,7 @@ Y_UNIT_TEST_SUITE(TFastCheckTests) {
9099

91100
Y_UNIT_TEST(ParseSqlWithBadLib) {
92101
TOptions options;
102+
options.LangVer = GetMaxReleasedLangVersion();
93103
options.IsSql = true;
94104
options.ParseOnly = true;
95105
options.SqlLibs["foo.sql"] = "$x = 1; zexport $x;";
@@ -100,6 +110,7 @@ Y_UNIT_TEST_SUITE(TFastCheckTests) {
100110

101111
Y_UNIT_TEST(CompileSqlWithUnresolvedLib) {
102112
TOptions options;
113+
options.LangVer = GetMaxReleasedLangVersion();
103114
options.IsSql = true;
104115
options.ParseOnly = false;
105116
options.SqlLibs["foo.sql"] = "$x = 1; export $x;";
@@ -110,11 +121,22 @@ Y_UNIT_TEST_SUITE(TFastCheckTests) {
110121

111122
Y_UNIT_TEST(ParseSqlWithUnresolvedLib) {
112123
TOptions options;
124+
options.LangVer = GetMaxReleasedLangVersion();
113125
options.IsSql = true;
114126
options.ParseOnly = true;
115127
options.SqlLibs["foo.sql"] = "$x = 1; export $x;";
116128
TIssues errors;
117129
UNIT_ASSERT(CheckProgram("pragma library('foo.sql');import foo symbols $y; select $y", options, errors));
118130
UNIT_ASSERT_VALUES_EQUAL(0, errors.Size());
119131
}
132+
133+
Y_UNIT_TEST(TooHighLangVer) {
134+
TOptions options;
135+
options.LangVer = GetMaxLangVersion();
136+
options.IsSql = false;
137+
options.ParseOnly = true;
138+
TIssues errors;
139+
UNIT_ASSERT(!CheckProgram("(return world)", options, errors));
140+
UNIT_ASSERT_VALUES_EQUAL(1, errors.Size());
141+
}
120142
}

yql/essentials/public/fastcheck/format.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,13 @@ TString ReplaceHidden(TStringBuf input) {
4040
return res;
4141
}
4242

43-
class TFormatRunner : public ICheckRunner {
43+
class TFormatRunner : public TCheckRunnerBase {
4444
public:
4545
TString GetCheckName() const final {
4646
return "format";
4747
}
4848

49-
TCheckResponse Run(const TChecksRequest& request) final {
49+
TCheckResponse DoRun(const TChecksRequest& request) final {
5050
switch (request.Syntax) {
5151
case ESyntax::SExpr:
5252
return RunSExpr(request);

yql/essentials/public/fastcheck/lexer.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@ namespace NFastCheck {
99

1010
namespace {
1111

12-
class TLexerRunner : public ICheckRunner {
12+
class TLexerRunner : public TCheckRunnerBase {
1313
public:
1414
TString GetCheckName() const final {
1515
return "lexer";
1616
}
1717

18-
TCheckResponse Run(const TChecksRequest& request) final {
18+
TCheckResponse DoRun(const TChecksRequest& request) final {
1919
switch (request.Syntax) {
2020
case ESyntax::SExpr:
2121
return RunSExpr(request);

yql/essentials/public/fastcheck/linter.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include <util/generic/hash.h>
55
#include <util/generic/set.h>
66
#include <yql/essentials/providers/common/provider/yql_provider_names.h>
7+
#include <yql/essentials/public/langver/yql_langver.h>
78

89
namespace NYql {
910
namespace NFastCheck {
@@ -40,6 +41,7 @@ struct TChecksRequest {
4041
THashMap<TString, TString> ClusterMapping;
4142
ESyntax Syntax = ESyntax::YQL;
4243
ui16 SyntaxVersion = 1;
44+
TLangVersion LangVer = MinLangVersion;
4345
bool IsAnsiLexer = false;
4446
EMode Mode = EMode::Default;
4547
TMaybe<TVector<TCheckFilter>> Filters;

0 commit comments

Comments
 (0)