2015-01-26 15:27:51 +00:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <DB/Dictionaries/IDictionarySource.h>
|
2015-01-29 15:47:21 +00:00
|
|
|
#include <Poco/Timestamp.h>
|
2016-12-08 02:49:04 +00:00
|
|
|
|
2015-01-26 15:27:51 +00:00
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
2016-12-08 02:49:04 +00:00
|
|
|
class Context;
|
|
|
|
|
|
|
|
|
2015-02-10 14:50:43 +00:00
|
|
|
/// Allows loading dictionaries from a file with given format, does not support "random access"
|
2015-01-26 15:27:51 +00:00
|
|
|
class FileDictionarySource final : public IDictionarySource
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
FileDictionarySource(const std::string & filename, const std::string & format, Block & sample_block,
|
2016-12-08 02:49:04 +00:00
|
|
|
const Context & context);
|
2015-01-26 15:27:51 +00:00
|
|
|
|
2016-12-08 02:49:04 +00:00
|
|
|
FileDictionarySource(const FileDictionarySource & other);
|
2015-01-30 13:43:16 +00:00
|
|
|
|
2016-12-08 02:49:04 +00:00
|
|
|
BlockInputStreamPtr loadAll() override;
|
2015-01-26 15:27:51 +00:00
|
|
|
|
2016-10-26 22:27:38 +00:00
|
|
|
BlockInputStreamPtr loadIds(const std::vector<UInt64> & ids) override
|
2015-01-26 15:27:51 +00:00
|
|
|
{
|
2016-12-08 02:49:04 +00:00
|
|
|
throw Exception{"Method loadIds is unsupported for FileDictionarySource", ErrorCodes::NOT_IMPLEMENTED};
|
2015-11-16 17:27:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
BlockInputStreamPtr loadKeys(
|
|
|
|
const ConstColumnPlainPtrs & key_columns, const std::vector<std::size_t> & requested_rows) override
|
|
|
|
{
|
2016-12-08 02:49:04 +00:00
|
|
|
throw Exception{"Method loadKeys is unsupported for FileDictionarySource", ErrorCodes::NOT_IMPLEMENTED};
|
2015-01-26 15:27:51 +00:00
|
|
|
}
|
|
|
|
|
2015-01-29 15:47:21 +00:00
|
|
|
bool isModified() const override { return getLastModification() > last_modification; }
|
2015-02-10 14:50:43 +00:00
|
|
|
bool supportsSelectiveLoad() const override { return false; }
|
2015-01-29 15:47:21 +00:00
|
|
|
|
2015-02-10 21:10:58 +00:00
|
|
|
DictionarySourcePtr clone() const override { return std::make_unique<FileDictionarySource>(*this); }
|
2015-01-30 13:43:16 +00:00
|
|
|
|
2016-12-08 02:49:04 +00:00
|
|
|
std::string toString() const override;
|
2015-03-25 10:09:33 +00:00
|
|
|
|
2015-01-30 13:43:16 +00:00
|
|
|
private:
|
2016-12-08 02:49:04 +00:00
|
|
|
Poco::Timestamp getLastModification() const;
|
2015-01-29 15:47:21 +00:00
|
|
|
|
2015-01-26 15:27:51 +00:00
|
|
|
const std::string filename;
|
|
|
|
const std::string format;
|
|
|
|
Block sample_block;
|
2015-02-10 14:50:43 +00:00
|
|
|
const Context & context;
|
2015-01-29 15:47:21 +00:00
|
|
|
Poco::Timestamp last_modification;
|
2015-01-26 15:27:51 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|