blob: a8f3b11cf933e1a82f77ec214ee5ce88663ce7df (
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
|
#include "udf_meta.h"
#include <util/generic/hash.h>
#include <util/generic/hash_set.h>
namespace NYql {
namespace {
class TUdfMeta: public IUdfMeta {
public:
explicit TUdfMeta(const NJson::TJsonValue& json)
{
for (auto& [module, v] : json.GetMapSafe()) {
auto& names = Modules_[to_lower(module)];
for (auto& item : v.GetArraySafe()) {
auto& map = item.GetMapSafe();
TMeta meta;
if (auto ptr = map.FindPtr("isTypeAwareness")) {
meta.IsTypeAwareness = ptr->GetBooleanSafe();
if (auto ptr = map.FindPtr("polyArgs")) {
meta.PolyArgs = ptr->GetStringSafe();
}
if (auto ptr = map.FindPtr("resolvedCallableTypes")) {
meta.ResolvedCallableTypes = ptr->GetStringSafe();
}
}
if (!meta.IsTypeAwareness) {
meta.CallableType = map.at("callableType").GetStringSafe();
if (auto ptr = map.FindPtr("runConfigType")) {
meta.RunConfigType = ptr->GetStringSafe();
}
meta.ArgCount = map.at("argCount").GetIntegerSafe();
if (auto ptr = map.FindPtr("optionalArgCount")) {
meta.OptionalArgCount = ptr->GetIntegerSafe();
}
if (auto ptr = map.FindPtr("isStrict")) {
meta.IsStrict = ptr->GetBooleanSafe();
}
if (auto ptr = map.FindPtr("supportsBlocks")) {
meta.SupportsBlocks = ptr->GetBooleanSafe();
}
if (auto ptr = map.FindPtr("minLangVer")) {
Y_ENSURE(ParseLangVersion(ptr->GetStringSafe(), meta.MinLangVer));
}
if (auto ptr = map.FindPtr("maxLangVer")) {
Y_ENSURE(ParseLangVersion(ptr->GetStringSafe(), meta.MaxLangVer));
}
}
names.emplace(to_lower(map.at("name").GetStringSafe()), meta);
}
}
}
bool HasModule(TStringBuf module) const final {
return Modules_.contains(module);
}
bool HasFunction(TStringBuf module, TStringBuf function) const final {
auto ptr = Modules_.FindPtr(module);
if (!ptr) {
return false;
}
return ptr->contains(function);
}
const TMeta* GetMetadata(TStringBuf module, TStringBuf function) const final {
auto ptr = Modules_.FindPtr(module);
if (!ptr) {
return nullptr;
}
return ptr->FindPtr(function);
}
private:
THashMap<TString, THashMap<TString, TMeta>> Modules_;
};
} // namespace
std::unique_ptr<IUdfMeta> ParseUdfMeta(const NJson::TJsonValue& json) {
return std::make_unique<TUdfMeta>(json);
}
} // namespace NYql
|