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-04-16 06:12:35 +00:00
|
|
|
#include <DB/IO/ReadBufferFromFile.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-08-12 03:57:32 +00:00
|
|
|
: filename{filename}, format{format}, sample_block{sample_block}, context(context)
|
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);
|
2016-02-13 06:37:19 +00:00
|
|
|
auto stream = context.getInputFormat(
|
2015-05-28 03:49:28 +00:00
|
|
|
format, *in_ptr, sample_block, max_block_size);
|
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
|
|
|
}
|
|
|
|
|
2015-05-22 13:25:45 +00:00
|
|
|
BlockInputStreamPtr loadIds(const std::vector<std::uint64_t> & ids) override
|
2015-01-26 15:27:51 +00:00
|
|
|
{
|
2015-11-16 17:27:12 +00:00
|
|
|
throw Exception{"Method unsupported", ErrorCodes::NOT_IMPLEMENTED};
|
|
|
|
}
|
|
|
|
|
|
|
|
BlockInputStreamPtr loadKeys(
|
|
|
|
const ConstColumnPlainPtrs & key_columns, const std::vector<std::size_t> & requested_rows) override
|
|
|
|
{
|
|
|
|
throw Exception{"Method unsupported", 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
|
|
|
|
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
|
|
|
};
|
|
|
|
|
|
|
|
}
|