aboutsummaryrefslogtreecommitdiffstats
path: root/yql/essentials/public/result_format/yql_result_format_data.h
blob: 58290a5c4108f62c7f719c2f2862125945c75bd3 (plain) (blame)
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
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
#pragma once

#include "yql_result_format_common.h"

#include <library/cpp/yson/node/node.h>

namespace NYql::NResult {

class IDataVisitor {
public:
    virtual ~IDataVisitor() = default;

    virtual void OnVoid() = 0;
    virtual void OnNull() = 0;
    virtual void OnEmptyList() = 0;
    virtual void OnEmptyDict() = 0;
    virtual void OnBool(bool value) = 0;
    virtual void OnInt8(i8 value) = 0;
    virtual void OnUint8(ui8 value) = 0;
    virtual void OnInt16(i16 value) = 0;
    virtual void OnUint16(ui16 value) = 0;
    virtual void OnInt32(i32 value) = 0;
    virtual void OnUint32(ui32 value) = 0;
    virtual void OnInt64(i64 value) = 0;
    virtual void OnUint64(ui64 value) = 0;
    virtual void OnFloat(float value) = 0;
    virtual void OnDouble(double value) = 0;
    virtual void OnString(TStringBuf value, bool isUtf8) = 0;
    virtual void OnUtf8(TStringBuf value) = 0;
    virtual void OnYson(TStringBuf value, bool isUtf8) = 0;
    virtual void OnJson(TStringBuf value) = 0;
    virtual void OnJsonDocument(TStringBuf value) = 0;
    virtual void OnUuid(TStringBuf value, bool isUtf8) = 0;
    virtual void OnDyNumber(TStringBuf value, bool isUtf8) = 0;
    virtual void OnDate(ui16 value) = 0;
    virtual void OnDatetime(ui32 value) = 0;
    virtual void OnTimestamp(ui64 value) = 0;
    virtual void OnTzDate(TStringBuf value) = 0;
    virtual void OnTzDatetime(TStringBuf value) = 0;
    virtual void OnTzTimestamp(TStringBuf value) = 0;
    virtual void OnInterval(i64 value) = 0;
    virtual void OnDate32(i32 value) = 0;
    virtual void OnDatetime64(i64 value) = 0;
    virtual void OnTimestamp64(i64 value) = 0;
    virtual void OnTzDate32(TStringBuf value) = 0;
    virtual void OnTzDatetime64(TStringBuf value) = 0;
    virtual void OnTzTimestamp64(TStringBuf value) = 0;
    virtual void OnInterval64(i64 value) = 0;
    virtual void OnDecimal(TStringBuf value) = 0;
    virtual void OnBeginOptional() = 0;
    virtual void OnEmptyOptional() = 0;
    virtual void OnBeforeOptionalItem() = 0;
    virtual void OnAfterOptionalItem() = 0;
    virtual void OnEndOptional() = 0;
    virtual void OnBeginList() = 0;
    virtual void OnBeforeListItem() = 0;
    virtual void OnAfterListItem() = 0;
    virtual void OnEndList() = 0;
    virtual void OnBeginTuple() = 0;
    virtual void OnBeforeTupleItem() = 0;
    virtual void OnAfterTupleItem() = 0;
    virtual void OnEndTuple() = 0;
    virtual void OnBeginStruct() = 0;
    virtual void OnBeforeStructItem() = 0;
    virtual void OnAfterStructItem() = 0;
    virtual void OnEndStruct() = 0;
    virtual void OnBeginDict() = 0;
    virtual void OnBeforeDictItem() = 0;
    virtual void OnBeforeDictKey() = 0;
    virtual void OnAfterDictKey() = 0;
    virtual void OnBeforeDictPayload() = 0;
    virtual void OnAfterDictPayload() = 0;
    virtual void OnAfterDictItem() = 0;
    virtual void OnEndDict() = 0;
    virtual void OnBeginVariant(ui32 index) = 0;
    virtual void OnEndVariant() = 0;
    virtual void OnPg(TMaybe<TStringBuf> value, bool isUtf8) = 0;
};

class TSameActionDataVisitor : public IDataVisitor {
public:
    void OnVoid() override;
    void OnNull() override;
    void OnEmptyList() override;
    void OnEmptyDict() override;
    void OnBool(bool value) override;
    void OnInt8(i8 value) override;
    void OnUint8(ui8 value) override;
    void OnInt16(i16 value) override;
    void OnUint16(ui16 value) override;
    void OnInt32(i32 value) override;
    void OnUint32(ui32 value) override;
    void OnInt64(i64 value) override;
    void OnUint64(ui64 value) override;
    void OnFloat(float value) override;
    void OnDouble(double value) override;
    void OnString(TStringBuf value, bool isUtf8) override;
    void OnUtf8(TStringBuf value) override;
    void OnYson(TStringBuf value, bool isUtf8) override;
    void OnJson(TStringBuf value) override;
    void OnJsonDocument(TStringBuf value) override;
    void OnUuid(TStringBuf value, bool isUtf8) override;
    void OnDyNumber(TStringBuf value, bool isUtf8) override;
    void OnDate(ui16 value) override;
    void OnDatetime(ui32 value) override;
    void OnTimestamp(ui64 value) override;
    void OnTzDate(TStringBuf value) override;
    void OnTzDatetime(TStringBuf value) override;
    void OnTzTimestamp(TStringBuf value) override;
    void OnInterval(i64 value) override;
    void OnDate32(i32 value) override;
    void OnDatetime64(i64 value) override;
    void OnTimestamp64(i64 value) override;
    void OnTzDate32(TStringBuf value) override;
    void OnTzDatetime64(TStringBuf value) override;
    void OnTzTimestamp64(TStringBuf value) override;
    void OnInterval64(i64 value) override;
    void OnDecimal(TStringBuf value) override;
    void OnBeginOptional() override;
    void OnBeforeOptionalItem() override;
    void OnAfterOptionalItem() override;
    void OnEmptyOptional() override;
    void OnEndOptional() override;
    void OnBeginList() override;
    void OnBeforeListItem() override;
    void OnAfterListItem() override;
    void OnEndList() override;
    void OnBeginTuple() override;
    void OnBeforeTupleItem() override;
    void OnAfterTupleItem() override;
    void OnEndTuple() override;
    void OnBeginStruct() override;
    void OnBeforeStructItem() override;
    void OnAfterStructItem() override;
    void OnEndStruct() override;
    void OnBeginDict() override;
    void OnBeforeDictItem() override;
    void OnBeforeDictKey() override;
    void OnAfterDictKey() override;
    void OnBeforeDictPayload() override;
    void OnAfterDictPayload() override;
    void OnAfterDictItem() override;
    void OnEndDict() override;
    void OnBeginVariant(ui32 index) override;
    void OnEndVariant() override;
    void OnPg(TMaybe<TStringBuf> value, bool isUtf8) override;

public:
    virtual void Do() = 0;
};

class TThrowingDataVisitor : public TSameActionDataVisitor {
public:
    void Do() final;
};

class TEmptyDataVisitor : public TSameActionDataVisitor {
public:
    void Do() final;
};

void ParseData(const NYT::TNode& typeNode, const NYT::TNode& dataNode, IDataVisitor& visitor);

class TDataBuilder : public IDataVisitor {
public:
    TDataBuilder();
    const NYT::TNode& GetResult() const;

    void OnVoid() final;
    void OnNull() final;
    void OnEmptyList() final;
    void OnEmptyDict() final;
    void OnBool(bool value) final;
    void OnInt8(i8 value) final;
    void OnUint8(ui8 value) final;
    void OnInt16(i16 value) final;
    void OnUint16(ui16 value) final;
    void OnInt32(i32 value) final;
    void OnUint32(ui32 value) final;
    void OnInt64(i64 value) final;
    void OnUint64(ui64 value) final;
    void OnFloat(float value) final;
    void OnDouble(double value) final;
    void OnString(TStringBuf value, bool isUtf8) final;
    void OnUtf8(TStringBuf value) final;
    void OnYson(TStringBuf value, bool isUtf8) final;
    void OnJson(TStringBuf value) final;
    void OnJsonDocument(TStringBuf value) final;
    void OnUuid(TStringBuf value, bool isUtf8) final;
    void OnDyNumber(TStringBuf value, bool isUtf8) final;
    void OnDate(ui16 value) final;
    void OnDatetime(ui32 value) final;
    void OnTimestamp(ui64 value) final;
    void OnTzDate(TStringBuf value) final;
    void OnTzDatetime(TStringBuf value) final;
    void OnTzTimestamp(TStringBuf value) final;
    void OnInterval(i64 value) final;
    void OnDate32(i32 value) final;
    void OnDatetime64(i64 value) final;
    void OnTimestamp64(i64 value) final;
    void OnTzDate32(TStringBuf value) final;
    void OnTzDatetime64(TStringBuf value) final;
    void OnTzTimestamp64(TStringBuf value) final;
    void OnInterval64(i64 value) final;
    void OnDecimal(TStringBuf value) final;
    void OnBeginOptional() final;
    void OnBeforeOptionalItem() final;
    void OnAfterOptionalItem() final;
    void OnEmptyOptional() final;
    void OnEndOptional() final;
    void OnBeginList() final;
    void OnBeforeListItem() final;
    void OnAfterListItem() final;
    void OnEndList() final;
    void OnBeginTuple() final;
    void OnBeforeTupleItem() final;
    void OnAfterTupleItem() final;
    void OnEndTuple() final;
    void OnBeginStruct() final;
    void OnBeforeStructItem() final;
    void OnAfterStructItem() final;
    void OnEndStruct() final;
    void OnBeginDict() final;
    void OnBeforeDictItem() final;
    void OnBeforeDictKey() final;
    void OnAfterDictKey() final;
    void OnBeforeDictPayload() final;
    void OnAfterDictPayload() final;
    void OnAfterDictItem() final;
    void OnEndDict() final;
    void OnBeginVariant(ui32 index) final;
    void OnEndVariant() final;
    void OnPg(TMaybe<TStringBuf> value, bool isUtf8) final;

private:
    NYT::TNode& Top();
    void Push(NYT::TNode* value);
    void Pop();

private:
    NYT::TNode Root;
    TVector<NYT::TNode*> Stack;
};

}