blob: 921b94623714375f10a945cb2e71d64cf7b13e0e (
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
|
#include "documentation.h"
#include <yql/essentials/sql/v1/complete/name/service/name_service.h>
namespace NSQLComplete {
namespace {
class TStaticDocumentation: public IDocumentation {
public:
explicit TStaticDocumentation(TDocByNormalizedNameMap docs)
: Docs_(std::move(docs))
{
}
TMaybe<TString> Lookup(TStringBuf name) const override {
if (auto* ptr = Docs_.FindPtr(Normalized(name))) {
return *ptr;
}
return Nothing();
}
private:
TString Normalized(TStringBuf name) const {
return NormalizeName(name);
}
TDocByNormalizedNameMap Docs_;
};
class TReservedDocumentation: public IDocumentation {
public:
TReservedDocumentation(
IDocumentation::TPtr primary, IDocumentation::TPtr fallback)
: Primary_(std::move(primary))
, Fallback_(std::move(fallback))
{
}
TMaybe<TString> Lookup(TStringBuf name) const override {
return Primary_->Lookup(name).Or([name, f = Fallback_] {
return f->Lookup(name);
});
}
private:
IDocumentation::TPtr Primary_;
IDocumentation::TPtr Fallback_;
};
} // namespace
IDocumentation::TPtr MakeStaticDocumentation(TDocByNormalizedNameMap docs) {
return new TStaticDocumentation(std::move(docs));
}
IDocumentation::TPtr MakeReservedDocumentation(
IDocumentation::TPtr primary, IDocumentation::TPtr fallback) {
return new TReservedDocumentation(std::move(primary), std::move(fallback));
}
} // namespace NSQLComplete
|