2015-01-26 15:27:51 +00:00
|
|
|
#pragma once
|
|
|
|
|
2015-01-29 15:47:21 +00:00
|
|
|
#include <Poco/Timestamp.h>
|
2018-12-10 15:25:45 +00:00
|
|
|
#include "IDictionarySource.h"
|
2019-05-17 14:34:25 +00:00
|
|
|
#include <Core/Block.h>
|
2020-04-02 22:35:22 +00:00
|
|
|
#include <Interpreters/Context.h>
|
2015-01-26 15:27:51 +00:00
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
2020-02-25 18:10:48 +00:00
|
|
|
namespace ErrorCodes
|
|
|
|
{
|
|
|
|
extern const int NOT_IMPLEMENTED;
|
|
|
|
}
|
2020-04-02 22:35:22 +00:00
|
|
|
// class Context;
|
2016-12-08 02:49:04 +00:00
|
|
|
|
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:
|
2019-12-10 17:27:29 +00:00
|
|
|
FileDictionarySource(const std::string & filepath_, const std::string & format_,
|
2020-04-02 22:35:22 +00:00
|
|
|
Block & sample_block_, Context & context_, bool check_config);
|
2015-01-26 15:27:51 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
FileDictionarySource(const FileDictionarySource & other);
|
2015-01-30 13:43:16 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
BlockInputStreamPtr loadAll() override;
|
2015-01-26 15:27:51 +00:00
|
|
|
|
2018-02-15 13:08:23 +00:00
|
|
|
BlockInputStreamPtr loadUpdatedAll() override
|
|
|
|
{
|
|
|
|
throw Exception{"Method loadUpdatedAll is unsupported for FileDictionarySource", ErrorCodes::NOT_IMPLEMENTED};
|
|
|
|
}
|
|
|
|
|
2017-12-01 20:21:35 +00:00
|
|
|
BlockInputStreamPtr loadIds(const std::vector<UInt64> & /*ids*/) override
|
2017-04-01 07:20:54 +00:00
|
|
|
{
|
|
|
|
throw Exception{"Method loadIds is unsupported for FileDictionarySource", ErrorCodes::NOT_IMPLEMENTED};
|
|
|
|
}
|
2015-11-16 17:27:12 +00:00
|
|
|
|
2018-12-10 15:25:45 +00:00
|
|
|
BlockInputStreamPtr loadKeys(const Columns & /*key_columns*/, const std::vector<size_t> & /*requested_rows*/) override
|
2017-04-01 07:20:54 +00:00
|
|
|
{
|
|
|
|
throw Exception{"Method loadKeys is unsupported for FileDictionarySource", ErrorCodes::NOT_IMPLEMENTED};
|
|
|
|
}
|
2015-01-26 15:27:51 +00:00
|
|
|
|
2020-03-19 02:17:30 +00:00
|
|
|
bool isModified() const override
|
|
|
|
{
|
|
|
|
// We can't count on that the mtime increases or that it has
|
|
|
|
// a particular relation to system time, so just check for strict
|
|
|
|
// equality.
|
|
|
|
return getLastModification() != last_modification;
|
|
|
|
}
|
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
bool supportsSelectiveLoad() const override { return false; }
|
2015-01-29 15:47:21 +00:00
|
|
|
|
2018-01-15 12:44:39 +00:00
|
|
|
///Not supported for FileDictionarySource
|
|
|
|
bool hasUpdateField() const override { return false; }
|
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
DictionarySourcePtr clone() const override { return std::make_unique<FileDictionarySource>(*this); }
|
2015-01-30 13:43:16 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
std::string toString() const override;
|
2015-03-25 10:09:33 +00:00
|
|
|
|
2015-01-30 13:43:16 +00:00
|
|
|
private:
|
2017-04-01 07:20:54 +00:00
|
|
|
Poco::Timestamp getLastModification() const;
|
2015-01-29 15:47:21 +00:00
|
|
|
|
2019-12-10 17:27:29 +00:00
|
|
|
const std::string filepath;
|
2017-04-01 07:20:54 +00:00
|
|
|
const std::string format;
|
|
|
|
Block sample_block;
|
2020-04-02 22:35:22 +00:00
|
|
|
const Context context;
|
2017-04-01 07:20:54 +00:00
|
|
|
Poco::Timestamp last_modification;
|
2015-01-26 15:27:51 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|