2015-01-26 15:27:51 +00:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <DB/Interpreters/Context.h>
|
|
|
|
#include <DB/Dictionaries/DictionaryStructure.h>
|
|
|
|
#include <DB/Dictionaries/IDictionarySource.h>
|
2015-01-28 16:23:52 +00:00
|
|
|
#include <DB/Dictionaries/OwningBufferBlockInputStream.h>
|
2015-01-29 15:47:21 +00:00
|
|
|
#include <Poco/Timestamp.h>
|
|
|
|
#include <Poco/File.h>
|
2015-01-26 15:27:51 +00:00
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
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
|
|
|
|
{
|
2015-01-26 16:53:44 +00:00
|
|
|
static const auto max_block_size = 8192;
|
|
|
|
|
2015-01-26 15:27:51 +00:00
|
|
|
public:
|
|
|
|
FileDictionarySource(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
|
|
|
: filename{filename}, format{format}, sample_block{sample_block}, context(context),
|
2015-01-30 11:51:59 +00:00
|
|
|
last_modification{getLastModification()}
|
2015-01-29 15:47:21 +00:00
|
|
|
{}
|
2015-01-26 15:27:51 +00:00
|
|
|
|
2015-01-30 13:43:16 +00:00
|
|
|
FileDictionarySource(const FileDictionarySource & other)
|
|
|
|
: filename{other.filename}, format{other.format},
|
|
|
|
sample_block{other.sample_block}, context(other.context),
|
|
|
|
last_modification{other.last_modification}
|
|
|
|
{}
|
|
|
|
|
2015-01-26 15:27:51 +00:00
|
|
|
BlockInputStreamPtr loadAll() override
|
|
|
|
{
|
2015-02-10 21:10:58 +00:00
|
|
|
auto in_ptr = std::make_unique<ReadBufferFromFile>(filename);
|
2015-01-28 16:23:52 +00:00
|
|
|
auto stream = context.getFormatFactory().getInput(
|
2015-01-26 15:27:51 +00:00
|
|
|
format, *in_ptr, sample_block, max_block_size, context.getDataTypeFactory());
|
2015-01-29 15:47:21 +00:00
|
|
|
last_modification = getLastModification();
|
2015-01-28 16:23:52 +00:00
|
|
|
|
|
|
|
return new OwningBufferBlockInputStream{stream, std::move(in_ptr)};
|
2015-01-26 15:27:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
BlockInputStreamPtr loadIds(const std::vector<std::uint64_t> ids) override
|
|
|
|
{
|
|
|
|
throw Exception{
|
|
|
|
"Method unsupported",
|
|
|
|
ErrorCodes::NOT_IMPLEMENTED
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
2015-03-25 10:09:33 +00:00
|
|
|
std::string toString() const override { return "File: " + filename + ' ' + format; }
|
|
|
|
|
2015-01-30 13:43:16 +00:00
|
|
|
private:
|
2015-01-29 15:47:21 +00:00
|
|
|
Poco::Timestamp getLastModification() const { return Poco::File{filename}.getLastModified(); }
|
|
|
|
|
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
|
|
|
};
|
|
|
|
|
|
|
|
}
|