summaryrefslogtreecommitdiffstats
path: root/yql/essentials/sql/v1/complete/name/object/simple/cached/schema.cpp
blob: 77abd97c576740ff2b20089da6203f761c7816ff (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
#include "schema.h"

#include <yql/essentials/sql/v1/complete/name/cache/cached.h>

namespace NSQLComplete {

    namespace {

        class TSimpleSchema: public ISimpleSchema {
        public:
            TSimpleSchema(
                TSchemaCaches caches,
                TString Zone,
                ISimpleSchema::TPtr Origin)
                : Zone_(std::move(Zone))
                , Origin_(std::move(Origin))
                , QueryList_(std::move(caches.List), [origin = Origin_](const TSchemaDescribeCacheKey& key) {
                    return origin->List(key.Cluster, key.Path);
                })
                , QueryDescribeTable_(std::move(caches.DescribeTable), [origin = Origin_](const TSchemaDescribeCacheKey& key) {
                    return origin->DescribeTable(key.Cluster, key.Path);
                })
            {
            }

            TSplittedPath Split(TStringBuf path) const override {
                return Origin_->Split(path);
            }

            NThreading::TFuture<TVector<TFolderEntry>>
            List(TString cluster, TString folder) const override {
                return QueryList_({
                    .Zone = Zone_,
                    .Cluster = std::move(cluster),
                    .Path = std::move(folder),
                });
            }

            NThreading::TFuture<TMaybe<TTableDetails>>
            DescribeTable(const TString& cluster, const TString& path) const override {
                return QueryDescribeTable_({
                    .Zone = Zone_,
                    .Cluster = cluster,
                    .Path = path,
                });
            }

        private:
            TString Zone_;
            ISimpleSchema::TPtr Origin_;
            TCachedQuery<TSchemaDescribeCacheKey, TVector<TFolderEntry>> QueryList_;
            TCachedQuery<TSchemaDescribeCacheKey, TMaybe<TTableDetails>> QueryDescribeTable_;
        };

    } // namespace

    ISimpleSchema::TPtr MakeCachedSimpleSchema(
        ISchemaListCache::TPtr cache, TString zone, ISimpleSchema::TPtr origin) {
        return new TSimpleSchema({.List = std::move(cache)}, std::move(zone), std::move(origin));
    }

    ISimpleSchema::TPtr MakeCachedSimpleSchema(TSchemaCaches caches, TString zone, ISimpleSchema::TPtr origin) {
        return new TSimpleSchema(std::move(caches), std::move(zone), std::move(origin));
    }

} // namespace NSQLComplete