Skip to content

Commit 2a8d528

Browse files
authored
result_format: type parser & builder (#8469)
1 parent 93089ee commit 2a8d528

File tree

6 files changed

+1245
-0
lines changed

6 files changed

+1245
-0
lines changed
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
UNITTEST_FOR(ydb/library/yql/public/result_format)
2+
3+
SRCS(
4+
yql_result_format_ut.cpp
5+
)
6+
7+
PEERDIR(
8+
library/cpp/yson/node
9+
)
10+
11+
END()
12+
Lines changed: 290 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,290 @@
1+
#include <ydb/library/yql/public/result_format/yql_result_format.h>
2+
3+
#include <library/cpp/yson/node/node_io.h>
4+
5+
#include <library/cpp/testing/unittest/registar.h>
6+
7+
namespace NYql::NResult {
8+
9+
void Test(const TString& input) {
10+
TTypeBuilder builder;
11+
auto node = NYT::NodeFromYsonString(input);
12+
ParseType(node, builder);
13+
UNIT_ASSERT_VALUES_EQUAL(NYT::NodeToCanonicalYsonString(builder.GetResult()), NYT::NodeToCanonicalYsonString(node));
14+
}
15+
16+
Y_UNIT_TEST_SUITE(TParseType) {
17+
Y_UNIT_TEST(Throwing) {
18+
TThrowingTypeVisitor v;
19+
UNIT_ASSERT_EXCEPTION(v.OnNull(), TUnsupportedException);
20+
UNIT_ASSERT_EXCEPTION(v.OnVoid(), TUnsupportedException);
21+
UNIT_ASSERT_EXCEPTION(v.OnEmptyList(), TUnsupportedException);
22+
UNIT_ASSERT_EXCEPTION(v.OnEmptyDict(), TUnsupportedException);
23+
UNIT_ASSERT_EXCEPTION(v.OnBool(), TUnsupportedException);
24+
UNIT_ASSERT_EXCEPTION(v.OnInt8(), TUnsupportedException);
25+
UNIT_ASSERT_EXCEPTION(v.OnUint8(), TUnsupportedException);
26+
UNIT_ASSERT_EXCEPTION(v.OnInt16(), TUnsupportedException);
27+
UNIT_ASSERT_EXCEPTION(v.OnUint16(), TUnsupportedException);
28+
UNIT_ASSERT_EXCEPTION(v.OnInt32(), TUnsupportedException);
29+
UNIT_ASSERT_EXCEPTION(v.OnUint32(), TUnsupportedException);
30+
UNIT_ASSERT_EXCEPTION(v.OnInt64(), TUnsupportedException);
31+
UNIT_ASSERT_EXCEPTION(v.OnUint64(), TUnsupportedException);
32+
UNIT_ASSERT_EXCEPTION(v.OnFloat(), TUnsupportedException);
33+
UNIT_ASSERT_EXCEPTION(v.OnDouble(), TUnsupportedException);
34+
UNIT_ASSERT_EXCEPTION(v.OnString(), TUnsupportedException);
35+
UNIT_ASSERT_EXCEPTION(v.OnUtf8(), TUnsupportedException);
36+
UNIT_ASSERT_EXCEPTION(v.OnYson(), TUnsupportedException);
37+
UNIT_ASSERT_EXCEPTION(v.OnJson(), TUnsupportedException);
38+
UNIT_ASSERT_EXCEPTION(v.OnJsonDocument(), TUnsupportedException);
39+
UNIT_ASSERT_EXCEPTION(v.OnUuid(), TUnsupportedException);
40+
UNIT_ASSERT_EXCEPTION(v.OnDyNumber(), TUnsupportedException);
41+
UNIT_ASSERT_EXCEPTION(v.OnDate(), TUnsupportedException);
42+
UNIT_ASSERT_EXCEPTION(v.OnDatetime(), TUnsupportedException);
43+
UNIT_ASSERT_EXCEPTION(v.OnTimestamp(), TUnsupportedException);
44+
UNIT_ASSERT_EXCEPTION(v.OnTzDate(), TUnsupportedException);
45+
UNIT_ASSERT_EXCEPTION(v.OnTzDatetime(), TUnsupportedException);
46+
UNIT_ASSERT_EXCEPTION(v.OnTzTimestamp(), TUnsupportedException);
47+
UNIT_ASSERT_EXCEPTION(v.OnInterval(), TUnsupportedException);
48+
UNIT_ASSERT_EXCEPTION(v.OnDate32(), TUnsupportedException);
49+
UNIT_ASSERT_EXCEPTION(v.OnDatetime64(), TUnsupportedException);
50+
UNIT_ASSERT_EXCEPTION(v.OnTimestamp64(), TUnsupportedException);
51+
UNIT_ASSERT_EXCEPTION(v.OnTzDate32(), TUnsupportedException);
52+
UNIT_ASSERT_EXCEPTION(v.OnTzDatetime64(), TUnsupportedException);
53+
UNIT_ASSERT_EXCEPTION(v.OnTzTimestamp64(), TUnsupportedException);
54+
UNIT_ASSERT_EXCEPTION(v.OnInterval64(), TUnsupportedException);
55+
UNIT_ASSERT_EXCEPTION(v.OnDecimal(10, 1), TUnsupportedException);
56+
UNIT_ASSERT_EXCEPTION(v.OnBeginOptional(), TUnsupportedException);
57+
UNIT_ASSERT_EXCEPTION(v.OnEndOptional(), TUnsupportedException);
58+
UNIT_ASSERT_EXCEPTION(v.OnBeginList(), TUnsupportedException);
59+
UNIT_ASSERT_EXCEPTION(v.OnEndList(), TUnsupportedException);
60+
UNIT_ASSERT_EXCEPTION(v.OnBeginTuple(), TUnsupportedException);
61+
UNIT_ASSERT_EXCEPTION(v.OnTupleItem(), TUnsupportedException);
62+
UNIT_ASSERT_EXCEPTION(v.OnEndTuple(), TUnsupportedException);
63+
UNIT_ASSERT_EXCEPTION(v.OnBeginStruct(), TUnsupportedException);
64+
UNIT_ASSERT_EXCEPTION(v.OnStructItem("foo"), TUnsupportedException);
65+
UNIT_ASSERT_EXCEPTION(v.OnEndStruct(), TUnsupportedException);
66+
UNIT_ASSERT_EXCEPTION(v.OnBeginDict(), TUnsupportedException);
67+
UNIT_ASSERT_EXCEPTION(v.OnDictKey(), TUnsupportedException);
68+
UNIT_ASSERT_EXCEPTION(v.OnDictPayload(), TUnsupportedException);
69+
UNIT_ASSERT_EXCEPTION(v.OnEndDict(), TUnsupportedException);
70+
UNIT_ASSERT_EXCEPTION(v.OnBeginVariant(), TUnsupportedException);
71+
UNIT_ASSERT_EXCEPTION(v.OnEndVariant(), TUnsupportedException);
72+
UNIT_ASSERT_EXCEPTION(v.OnBeginTagged("foo"), TUnsupportedException);
73+
UNIT_ASSERT_EXCEPTION(v.OnEndTagged(), TUnsupportedException);
74+
UNIT_ASSERT_EXCEPTION(v.OnPgType("int4", "N"), TUnsupportedException);
75+
}
76+
77+
Y_UNIT_TEST(BadNotList) {
78+
UNIT_ASSERT_EXCEPTION(Test("foo"), TUnsupportedException);
79+
}
80+
81+
Y_UNIT_TEST(BadEmptyList) {
82+
UNIT_ASSERT_EXCEPTION(Test("[]"), TUnsupportedException);
83+
}
84+
85+
Y_UNIT_TEST(BadNotStringName) {
86+
UNIT_ASSERT_EXCEPTION(Test("[#]"), TUnsupportedException);
87+
}
88+
89+
Y_UNIT_TEST(BadUnknownName) {
90+
UNIT_ASSERT_EXCEPTION(Test("[unknown]"), TUnsupportedException);
91+
}
92+
93+
Y_UNIT_TEST(Void) {
94+
Test("[VoidType]");
95+
}
96+
97+
Y_UNIT_TEST(Null) {
98+
Test("[NullType]");
99+
}
100+
101+
Y_UNIT_TEST(EmptyList) {
102+
Test("[EmptyListType]");
103+
}
104+
105+
Y_UNIT_TEST(EmptyDict) {
106+
Test("[EmptyDictType]");
107+
}
108+
109+
Y_UNIT_TEST(BadUnknownDataName) {
110+
UNIT_ASSERT_EXCEPTION(Test("[DataType;unknown]"), TUnsupportedException);
111+
}
112+
113+
Y_UNIT_TEST(Bool) {
114+
Test("[DataType;Bool]");
115+
}
116+
117+
Y_UNIT_TEST(Int8) {
118+
Test("[DataType;Int8]");
119+
}
120+
121+
Y_UNIT_TEST(Uint8) {
122+
Test("[DataType;Uint8]");
123+
}
124+
125+
Y_UNIT_TEST(Int16) {
126+
Test("[DataType;Int16]");
127+
}
128+
129+
Y_UNIT_TEST(Uint16) {
130+
Test("[DataType;Uint16]");
131+
}
132+
133+
Y_UNIT_TEST(Int32) {
134+
Test("[DataType;Int32]");
135+
}
136+
137+
Y_UNIT_TEST(Uint32) {
138+
Test("[DataType;Uint32]");
139+
}
140+
141+
Y_UNIT_TEST(Int64) {
142+
Test("[DataType;Int64]");
143+
}
144+
145+
Y_UNIT_TEST(Uint64) {
146+
Test("[DataType;Uint64]");
147+
}
148+
149+
Y_UNIT_TEST(Float) {
150+
Test("[DataType;Float]");
151+
}
152+
153+
Y_UNIT_TEST(Double) {
154+
Test("[DataType;Double]");
155+
}
156+
157+
Y_UNIT_TEST(String) {
158+
Test("[DataType;String]");
159+
}
160+
161+
Y_UNIT_TEST(Utf8) {
162+
Test("[DataType;Utf8]");
163+
}
164+
165+
Y_UNIT_TEST(Yson) {
166+
Test("[DataType;Yson]");
167+
}
168+
169+
Y_UNIT_TEST(Json) {
170+
Test("[DataType;Json]");
171+
}
172+
173+
Y_UNIT_TEST(JsonDocument) {
174+
Test("[DataType;JsonDocument]");
175+
}
176+
177+
Y_UNIT_TEST(Uuid) {
178+
Test("[DataType;Uuid]");
179+
}
180+
181+
Y_UNIT_TEST(DyNumber) {
182+
Test("[DataType;DyNumber]");
183+
}
184+
185+
Y_UNIT_TEST(Date) {
186+
Test("[DataType;Date]");
187+
}
188+
189+
Y_UNIT_TEST(Datetime) {
190+
Test("[DataType;Datetime]");
191+
}
192+
193+
Y_UNIT_TEST(Timestamp) {
194+
Test("[DataType;Timestamp]");
195+
}
196+
197+
Y_UNIT_TEST(TzDate) {
198+
Test("[DataType;TzDate]");
199+
}
200+
201+
Y_UNIT_TEST(TzDatetime) {
202+
Test("[DataType;TzDatetime]");
203+
}
204+
205+
Y_UNIT_TEST(TzTimestamp) {
206+
Test("[DataType;TzTimestamp]");
207+
}
208+
209+
Y_UNIT_TEST(Interval) {
210+
Test("[DataType;Interval]");
211+
}
212+
213+
Y_UNIT_TEST(Date32) {
214+
Test("[DataType;Date32]");
215+
}
216+
217+
Y_UNIT_TEST(Datetime64) {
218+
Test("[DataType;Datetime64]");
219+
}
220+
221+
Y_UNIT_TEST(Timestamp64) {
222+
Test("[DataType;Timestamp64]");
223+
}
224+
225+
Y_UNIT_TEST(TzDate32) {
226+
Test("[DataType;TzDate32]");
227+
}
228+
229+
Y_UNIT_TEST(TzDatetime64) {
230+
Test("[DataType;TzDatetime64]");
231+
}
232+
233+
Y_UNIT_TEST(TzTimestamp64) {
234+
Test("[DataType;TzTimestamp64]");
235+
}
236+
237+
Y_UNIT_TEST(Interval64) {
238+
Test("[DataType;Interval64]");
239+
}
240+
241+
Y_UNIT_TEST(Decimal) {
242+
Test("[DataType;Decimal;\"10\";\"1\"]");
243+
}
244+
245+
Y_UNIT_TEST(OptionalInt32) {
246+
Test("[OptionalType;[DataType;Int32]]");
247+
}
248+
249+
Y_UNIT_TEST(ListInt32) {
250+
Test("[ListType;[DataType;Int32]]");
251+
}
252+
253+
Y_UNIT_TEST(ListListInt32) {
254+
Test("[ListType;[ListType;[DataType;Int32]]]");
255+
}
256+
257+
Y_UNIT_TEST(TupleInt32String) {
258+
Test("[TupleType;[[DataType;Int32];[DataType;String]]]");
259+
}
260+
261+
Y_UNIT_TEST(EmptyTuple) {
262+
Test("[TupleType;[]]");
263+
}
264+
265+
Y_UNIT_TEST(StructInt32String) {
266+
Test("[StructType;[[foo;[DataType;Int32]];[bar;[DataType;String]]]]");
267+
}
268+
269+
Y_UNIT_TEST(EmptyStruct) {
270+
Test("[StructType;[]]");
271+
}
272+
273+
Y_UNIT_TEST(DictInt32String) {
274+
Test("[DictType;[DataType;Int32];[DataType;String]]");
275+
}
276+
277+
Y_UNIT_TEST(VariantTupleInt32String) {
278+
Test("[VariantType;[TupleType;[[DataType;Int32];[DataType;String]]]]");
279+
}
280+
281+
Y_UNIT_TEST(TaggedInt32) {
282+
Test("[TaggedType;foo;[DataType;Int32]]");
283+
}
284+
285+
Y_UNIT_TEST(PgType) {
286+
Test("[PgType;int4;N]");
287+
}
288+
}
289+
290+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
LIBRARY()
2+
3+
SRCS(
4+
yql_result_format.cpp
5+
)
6+
7+
PEERDIR(
8+
library/cpp/yson/node
9+
)
10+
11+
END()
12+
13+
RECURSE_FOR_TESTS(
14+
ut
15+
)
16+

0 commit comments

Comments
 (0)