ClickHouse/src/Dictionaries/LibraryDictionarySource.h

102 lines
2.5 KiB
C++
Raw Normal View History

#pragma once
#include <Common/SharedLibrary.h>
2021-03-12 08:04:20 +00:00
#include <Common/LibraryBridgeHelper.h>
#include <common/LocalDateTime.h>
2021-03-05 09:38:00 +00:00
#include <Common/thread_local_rng.h>
#include "DictionaryStructure.h"
2019-02-15 11:46:07 +00:00
#include <Core/ExternalResultDescription.h>
#include "IDictionarySource.h"
namespace Poco
{
class Logger;
namespace Util
{
class AbstractConfiguration;
}
}
namespace DB
{
2021-03-05 09:38:00 +00:00
2020-02-25 18:10:48 +00:00
namespace ErrorCodes
{
extern const int NOT_IMPLEMENTED;
}
2021-03-05 09:38:00 +00:00
2017-09-05 17:13:00 +00:00
class CStringsHolder;
2021-03-05 09:38:00 +00:00
using LibraryBridgeHelperPtr = std::shared_ptr<LibraryBridgeHelper>;
class LibraryDictionarySource final : public IDictionarySource
{
public:
LibraryDictionarySource(
const DictionaryStructure & dict_struct_,
const Poco::Util::AbstractConfiguration & config,
2019-08-03 11:02:40 +00:00
const std::string & config_prefix_,
Block & sample_block_,
2021-03-05 09:38:00 +00:00
const Context & context_,
bool check_config);
LibraryDictionarySource(const LibraryDictionarySource & other);
2019-07-08 00:51:43 +00:00
LibraryDictionarySource & operator=(const LibraryDictionarySource &) = delete;
~LibraryDictionarySource() override;
BlockInputStreamPtr loadAll() override;
BlockInputStreamPtr loadUpdatedAll() override
{
throw Exception{"Method loadUpdatedAll is unsupported for LibraryDictionarySource", ErrorCodes::NOT_IMPLEMENTED};
}
BlockInputStreamPtr loadIds(const std::vector<UInt64> & ids) override;
BlockInputStreamPtr loadKeys(const Columns & key_columns, const std::vector<std::size_t> & requested_rows) override;
bool isModified() const override;
bool supportsSelectiveLoad() const override;
///Not yet supported
bool hasUpdateField() const override { return false; }
DictionarySourcePtr clone() const override;
std::string toString() const override;
private:
2021-03-05 09:38:00 +00:00
String getDictAttributesString();
2021-03-07 19:53:10 +00:00
static String getDictIdsString(const std::vector<UInt64> & ids);
static String getLibrarySettingsString(const Poco::Util::AbstractConfiguration & config, const std::string & config_root);
2021-03-05 09:38:00 +00:00
Poco::Logger * log;
const DictionaryStructure dict_struct;
const std::string config_prefix;
const std::string path;
2021-03-05 09:38:00 +00:00
const std::string dictionary_id;
Block sample_block;
2021-03-05 09:38:00 +00:00
Context context;
LibraryBridgeHelperPtr bridge_helper;
ExternalResultDescription description;
2021-03-05 09:38:00 +00:00
String createDictID()
{
std::uniform_int_distribution<int> distribution('a', 'z');
String random_str(16, ' ');
for (auto & c : random_str)
c = distribution(thread_local_rng);
return random_str;
}
};
}