1#pragma once
2
3#include <Poco/Timestamp.h>
4#include "IDictionarySource.h"
5#include <Core/Block.h>
6
7
8namespace DB
9{
10class Context;
11
12/// Allows loading dictionaries from a file with given format, does not support "random access"
13class FileDictionarySource final : public IDictionarySource
14{
15public:
16 FileDictionarySource(const std::string & filepath_, const std::string & format_,
17 Block & sample_block_, const Context & context_, bool check_config);
18
19 FileDictionarySource(const FileDictionarySource & other);
20
21 BlockInputStreamPtr loadAll() override;
22
23 BlockInputStreamPtr loadUpdatedAll() override
24 {
25 throw Exception{"Method loadUpdatedAll is unsupported for FileDictionarySource", ErrorCodes::NOT_IMPLEMENTED};
26 }
27
28 BlockInputStreamPtr loadIds(const std::vector<UInt64> & /*ids*/) override
29 {
30 throw Exception{"Method loadIds is unsupported for FileDictionarySource", ErrorCodes::NOT_IMPLEMENTED};
31 }
32
33 BlockInputStreamPtr loadKeys(const Columns & /*key_columns*/, const std::vector<size_t> & /*requested_rows*/) override
34 {
35 throw Exception{"Method loadKeys is unsupported for FileDictionarySource", ErrorCodes::NOT_IMPLEMENTED};
36 }
37
38 bool isModified() const override { return getLastModification() > last_modification; }
39 bool supportsSelectiveLoad() const override { return false; }
40
41 ///Not supported for FileDictionarySource
42 bool hasUpdateField() const override { return false; }
43
44 DictionarySourcePtr clone() const override { return std::make_unique<FileDictionarySource>(*this); }
45
46 std::string toString() const override;
47
48private:
49 Poco::Timestamp getLastModification() const;
50
51 const std::string filepath;
52 const std::string format;
53 Block sample_block;
54 const Context & context;
55 Poco::Timestamp last_modification;
56};
57
58}
59