blob: f43af57c752ac4daf344415cbf2012557aa58139 (
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
|
#include "schema_gateway.h"
#include <yql/essentials/sql/v1/complete/name/object/simple/schema_gateway.h>
#include <util/charset/utf8.h>
namespace NSQLComplete {
namespace {
class TSimpleSchemaGateway: public ISimpleSchemaGateway {
public:
explicit TSimpleSchemaGateway(THashMap<TString, TVector<TFolderEntry>> data)
: Data_(std::move(data))
{
for (const auto& [k, _] : Data_) {
Y_ENSURE(k.StartsWith("/"), k << " must start with the '/'");
Y_ENSURE(k.EndsWith("/"), k << " must end with the '/'");
}
}
TSplittedPath Split(TStringBuf path) const override {
size_t pos = path.find_last_of('/');
if (pos == TString::npos) {
return {"", path};
}
TStringBuf head, tail;
TStringBuf(path).SplitAt(pos + 1, head, tail);
return {head, tail};
}
NThreading::TFuture<TVector<TFolderEntry>> List(TString folder) const override {
TVector<TFolderEntry> entries;
if (const auto* data = Data_.FindPtr(folder)) {
entries = *data;
}
return NThreading::MakeFuture(std::move(entries));
}
private:
THashMap<TString, TVector<TFolderEntry>> Data_;
};
} // namespace
ISchemaGateway::TPtr MakeStaticSchemaGateway(THashMap<TString, TVector<TFolderEntry>> fs) {
return MakeSimpleSchemaGateway(
ISimpleSchemaGateway::TPtr(
new TSimpleSchemaGateway(std::move(fs))));
}
} // namespace NSQLComplete
|