blob: cef9a995235a455c01a910fa9fb354e5b71dbacd (
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
|
#include "helpers.h"
#include <library/cpp/yson/writer.h>
#include <library/cpp/yson/node/node_visitor.h>
#include <util/string/ascii.h>
#include <util/generic/hash_set.h>
namespace NYql {
namespace NPureCalc {
namespace NPrivate {
NYT::TNode GetSchema(
const TVector<TString>& fields,
const TVector<TString>& optionalFields
) {
THashSet<TString> optionalFilter {
optionalFields.begin(), optionalFields.end()
};
NYT::TNode members {NYT::TNode::CreateList()};
auto addField = [&] (const TString& name, const TString& type) {
auto typeNode = NYT::TNode::CreateList()
.Add("DataType")
.Add(type);
if (optionalFilter.contains(name)) {
typeNode = NYT::TNode::CreateList()
.Add("OptionalType")
.Add(typeNode);
}
members.Add(NYT::TNode::CreateList()
.Add(name)
.Add(typeNode)
);
};
for (const auto& field: fields) {
TString type {field};
type[0] = AsciiToUpper(type[0]);
addField(field, type);
}
NYT::TNode schema = NYT::TNode::CreateList()
.Add("StructType")
.Add(members);
return schema;
}
}
}
}
|