2017-04-25 09:10:27 +00:00
|
|
|
#pragma once
|
|
|
|
|
2017-06-08 13:35:35 +00:00
|
|
|
#include <ext/shared_ptr_helper.h>
|
2017-04-25 09:10:27 +00:00
|
|
|
#include <Parsers/ASTSelectQuery.h>
|
|
|
|
#include <Storages/IStorage.h>
|
|
|
|
#include <common/MultiVersion.h>
|
|
|
|
#include <common/logger_useful.h>
|
|
|
|
|
|
|
|
#include <Interpreters/ExternalDictionaries.h>
|
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
|
|
|
class StorageDictionary : private ext::shared_ptr_helper<StorageDictionary>, public IStorage
|
|
|
|
{
|
|
|
|
friend class ext::shared_ptr_helper<StorageDictionary>;
|
2017-05-04 18:14:23 +00:00
|
|
|
|
2017-04-25 09:10:27 +00:00
|
|
|
public:
|
|
|
|
static StoragePtr create(
|
|
|
|
const String & table_name_,
|
|
|
|
const String & database_name_,
|
|
|
|
Context & context_,
|
|
|
|
ASTPtr & query_,
|
|
|
|
NamesAndTypesListPtr columns_,
|
|
|
|
const NamesAndTypesList & materialized_columns_,
|
|
|
|
const NamesAndTypesList & alias_columns_,
|
|
|
|
const ColumnDefaults & column_defaults_);
|
|
|
|
|
|
|
|
std::string getName() const override { return "Dictionary"; }
|
|
|
|
std::string getTableName() const override { return table_name; }
|
|
|
|
const NamesAndTypesList & getColumnsListImpl() const override { return *columns; }
|
|
|
|
|
|
|
|
BlockInputStreams read(
|
|
|
|
const Names & column_names,
|
2017-05-29 17:26:45 +00:00
|
|
|
const ASTPtr& query,
|
2017-04-25 09:10:27 +00:00
|
|
|
const Context & context,
|
|
|
|
QueryProcessingStage::Enum & processed_stage,
|
|
|
|
size_t max_block_size = DEFAULT_BLOCK_SIZE,
|
|
|
|
unsigned threads = 1) override;
|
|
|
|
|
|
|
|
void drop() override {}
|
|
|
|
|
|
|
|
private:
|
2017-05-15 13:58:40 +00:00
|
|
|
using Ptr = MultiVersion<IDictionaryBase>::Version;
|
|
|
|
|
2017-04-25 09:10:27 +00:00
|
|
|
String select_database_name;
|
|
|
|
String select_table_name;
|
|
|
|
String table_name;
|
|
|
|
String database_name;
|
|
|
|
ASTSelectQuery inner_query;
|
|
|
|
Context & context;
|
|
|
|
NamesAndTypesListPtr columns;
|
|
|
|
String dictionary_name;
|
|
|
|
const ExternalDictionaries & external_dictionaries;
|
|
|
|
Poco::Logger * logger;
|
|
|
|
|
|
|
|
StorageDictionary(
|
|
|
|
const String & table_name_,
|
|
|
|
const String & database_name_,
|
|
|
|
Context & context_,
|
|
|
|
ASTPtr & query_,
|
|
|
|
NamesAndTypesListPtr columns_,
|
|
|
|
const NamesAndTypesList & materialized_columns_,
|
|
|
|
const NamesAndTypesList & alias_columns_,
|
|
|
|
const ColumnDefaults & column_defaults_,
|
|
|
|
const ExternalDictionaries & external_dictionaries_);
|
|
|
|
|
2017-05-15 13:58:40 +00:00
|
|
|
void checkNamesAndTypesCompatibleWithDictionary(Ptr dictionary) const;
|
2017-04-25 09:10:27 +00:00
|
|
|
|
2017-05-15 13:58:40 +00:00
|
|
|
NamesAndTypes getNamesAndTypesFromDictionaryStructure(Ptr dictionary) const;
|
2017-04-28 18:33:31 +00:00
|
|
|
|
2017-04-25 09:10:27 +00:00
|
|
|
template <class ForwardIterator>
|
2017-05-15 13:58:40 +00:00
|
|
|
std::string generateNamesAndTypesDescription(ForwardIterator begin, ForwardIterator end) const {
|
2017-04-25 09:10:27 +00:00
|
|
|
if (begin == end) {
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
std::string description;
|
|
|
|
for (; begin != end; ++begin) {
|
|
|
|
description += ", ";
|
|
|
|
description += begin->name;
|
|
|
|
description += ' ';
|
|
|
|
description += begin->type->getName();
|
|
|
|
}
|
|
|
|
return description.substr(2, description.size());
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2017-05-15 13:58:40 +00:00
|
|
|
}
|
|
|
|
|