1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
|
#include "fastcheck.h"
#include <library/cpp/testing/unittest/registar.h>
using namespace NYql;
using namespace NYql::NFastCheck;
Y_UNIT_TEST_SUITE(TFastCheckTests) {
Y_UNIT_TEST(ParsePureYqlGood) {
TOptions options;
options.LangVer = GetMaxReleasedLangVersion();
options.IsSql = false;
options.ParseOnly = true;
TIssues errors;
UNIT_ASSERT(CheckProgram("(return world)", options, errors));
UNIT_ASSERT_VALUES_EQUAL(0, errors.Size());
}
Y_UNIT_TEST(ParsePureYqlBad) {
TOptions options;
options.LangVer = GetMaxReleasedLangVersion();
options.IsSql = false;
options.ParseOnly = true;
TIssues errors;
UNIT_ASSERT(CheckProgram("(return world1)", options, errors));
UNIT_ASSERT_VALUES_EQUAL(0, errors.Size());
}
Y_UNIT_TEST(ParsePureSqlGood) {
TOptions options;
options.LangVer = GetMaxReleasedLangVersion();
options.IsSql = true;
options.ParseOnly = true;
TIssues errors;
UNIT_ASSERT(CheckProgram("select 1", options, errors));
UNIT_ASSERT_VALUES_EQUAL(0, errors.Size());
}
Y_UNIT_TEST(ParsePureSqlBad) {
TOptions options;
options.LangVer = GetMaxReleasedLangVersion();
options.IsSql = true;
options.ParseOnly = true;
TIssues errors;
UNIT_ASSERT(!CheckProgram("select1", options, errors));
UNIT_ASSERT_VALUES_EQUAL(1, errors.Size());
}
Y_UNIT_TEST(CompilePureYqlBad) {
TOptions options;
options.LangVer = GetMaxReleasedLangVersion();
options.IsSql = false;
options.ParseOnly = false;
TIssues errors;
UNIT_ASSERT(!CheckProgram("(return world1)", options, errors));
UNIT_ASSERT_VALUES_EQUAL(1, errors.Size());
}
Y_UNIT_TEST(CompileTableSqlGood) {
TOptions options;
options.LangVer = GetMaxReleasedLangVersion();
options.IsSql = true;
options.ParseOnly = false;
options.ClusterMapping["plato"] = YtProviderName;
TIssues errors;
UNIT_ASSERT(CheckProgram("select key,count(*) from plato.Input group by key", options, errors));
UNIT_ASSERT_VALUES_EQUAL(0, errors.Size());
}
Y_UNIT_TEST(CompileTableSqlBad) {
TOptions options;
options.LangVer = GetMaxReleasedLangVersion();
options.IsSql = true;
options.ParseOnly = false;
TIssues errors;
UNIT_ASSERT(!CheckProgram("select key,count(*) from plato.Input", options, errors));
UNIT_ASSERT_VALUES_EQUAL(1, errors.Size());
}
Y_UNIT_TEST(CompileLibrary) {
TOptions options;
options.LangVer = GetMaxReleasedLangVersion();
options.IsSql = true;
options.IsLibrary = true;
TIssues errors;
UNIT_ASSERT(CheckProgram("$x = 1; export $x", options, errors));
UNIT_ASSERT_VALUES_EQUAL(0, errors.Size());
}
Y_UNIT_TEST(CompileSqlWithLibsGood) {
TOptions options;
options.LangVer = GetMaxReleasedLangVersion();
options.IsSql = true;
options.ParseOnly = false;
options.SqlLibs["foo.sql"] = "$x = 1; export $x;";
TIssues errors;
UNIT_ASSERT(CheckProgram("pragma library('foo.sql');import foo symbols $x; select $x", options, errors));
UNIT_ASSERT_VALUES_EQUAL(0, errors.Size());
}
Y_UNIT_TEST(ParseSqlWithBadLib) {
TOptions options;
options.LangVer = GetMaxReleasedLangVersion();
options.IsSql = true;
options.ParseOnly = true;
options.SqlLibs["foo.sql"] = "$x = 1; zexport $x;";
TIssues errors;
UNIT_ASSERT(!CheckProgram("pragma library('foo.sql');import foo symbols $x; select $x", options, errors));
UNIT_ASSERT_VALUES_EQUAL(1, errors.Size());
}
Y_UNIT_TEST(CompileSqlWithUnresolvedLib) {
TOptions options;
options.LangVer = GetMaxReleasedLangVersion();
options.IsSql = true;
options.ParseOnly = false;
options.SqlLibs["foo.sql"] = "$x = 1; export $x;";
TIssues errors;
UNIT_ASSERT(!CheckProgram("pragma library('foo.sql');import foo symbols $y; select $y", options, errors));
UNIT_ASSERT_VALUES_EQUAL(1, errors.Size());
}
Y_UNIT_TEST(ParseSqlWithUnresolvedLib) {
TOptions options;
options.LangVer = GetMaxReleasedLangVersion();
options.IsSql = true;
options.ParseOnly = true;
options.SqlLibs["foo.sql"] = "$x = 1; export $x;";
TIssues errors;
UNIT_ASSERT(CheckProgram("pragma library('foo.sql');import foo symbols $y; select $y", options, errors));
UNIT_ASSERT_VALUES_EQUAL(0, errors.Size());
}
Y_UNIT_TEST(TooHighLangVer) {
TOptions options;
options.LangVer = GetMaxLangVersion();
options.IsSql = false;
options.ParseOnly = true;
TIssues errors;
UNIT_ASSERT(!CheckProgram("(return world)", options, errors));
UNIT_ASSERT_VALUES_EQUAL(1, errors.Size());
}
Y_UNIT_TEST(UsedFlags) {
TString program = R"sql(
$input = AsList(
AsStruct(1 AS key, 1001 AS subkey, 'AAA' AS value),
);
SELECT
count(DISTINCT i1.key) OVER (
PARTITION BY
i1.subkey
) AS cnt,
FROM
AS_TABLE($input) AS i1
)sql";
TOptions options;
options.IsSql = true;
TIssues errors;
UNIT_ASSERT_C(CheckProgram(program, options, errors), errors.ToOneLineString());
}
} // Y_UNIT_TEST_SUITE(TFastCheckTests)
|