2015-01-27 00:52:03 +00:00
|
|
|
|
#pragma once
|
|
|
|
|
|
2016-08-30 19:27:15 +00:00
|
|
|
|
#include <ext/shared_ptr_helper.hpp>
|
2016-08-26 21:25:05 +00:00
|
|
|
|
|
2015-01-27 00:52:03 +00:00
|
|
|
|
#include <DB/Storages/IStorage.h>
|
|
|
|
|
#include <DB/Interpreters/Set.h>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
namespace DB
|
|
|
|
|
{
|
|
|
|
|
|
2015-01-27 21:24:24 +00:00
|
|
|
|
|
|
|
|
|
/** Общая часть StorageSet и StorageJoin.
|
|
|
|
|
*/
|
2016-08-30 19:27:15 +00:00
|
|
|
|
class StorageSetOrJoinBase : private ext::shared_ptr_helper<StorageSetOrJoinBase>, public IStorage
|
2015-01-27 21:24:24 +00:00
|
|
|
|
{
|
2016-08-30 19:27:15 +00:00
|
|
|
|
friend class ext::shared_ptr_helper<StorageSetOrJoinBase>;
|
2015-01-28 00:08:45 +00:00
|
|
|
|
friend class SetOrJoinBlockOutputStream;
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
String getTableName() const override { return name; }
|
|
|
|
|
const NamesAndTypesList & getColumnsListImpl() const override { return *columns; }
|
|
|
|
|
|
|
|
|
|
void rename(const String & new_path_to_db, const String & new_database_name, const String & new_table_name) override;
|
|
|
|
|
|
2015-09-10 20:43:42 +00:00
|
|
|
|
BlockOutputStreamPtr write(ASTPtr query, const Settings & settings) override;
|
2015-01-28 00:08:45 +00:00
|
|
|
|
|
2015-01-27 21:24:24 +00:00
|
|
|
|
protected:
|
2015-01-28 00:08:45 +00:00
|
|
|
|
StorageSetOrJoinBase(
|
|
|
|
|
const String & path_,
|
|
|
|
|
const String & name_,
|
|
|
|
|
NamesAndTypesListPtr columns_,
|
|
|
|
|
const NamesAndTypesList & materialized_columns_,
|
|
|
|
|
const NamesAndTypesList & alias_columns_,
|
|
|
|
|
const ColumnDefaults & column_defaults_);
|
|
|
|
|
|
2015-01-27 21:24:24 +00:00
|
|
|
|
String path;
|
|
|
|
|
String name;
|
|
|
|
|
NamesAndTypesListPtr columns;
|
|
|
|
|
|
|
|
|
|
UInt64 increment = 0; /// Для имён файлов бэкапа.
|
|
|
|
|
|
|
|
|
|
/// Восстановление из бэкапа.
|
|
|
|
|
void restore();
|
2015-01-28 00:08:45 +00:00
|
|
|
|
|
|
|
|
|
private:
|
2015-05-28 03:49:28 +00:00
|
|
|
|
void restoreFromFile(const String & file_path);
|
2015-01-27 21:24:24 +00:00
|
|
|
|
|
2015-01-28 00:08:45 +00:00
|
|
|
|
/// Вставить блок в состояние.
|
2015-01-27 21:24:24 +00:00
|
|
|
|
virtual void insertBlock(const Block & block) = 0;
|
2015-01-28 00:08:45 +00:00
|
|
|
|
virtual size_t getSize() const = 0;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
2015-01-27 00:52:03 +00:00
|
|
|
|
/** Позволяет сохранить множество для последующего использования в правой части оператора IN.
|
|
|
|
|
* При вставке в таблицу, данные будут вставлены в множество,
|
|
|
|
|
* а также записаны в файл-бэкап, для восстановления после перезапуска.
|
|
|
|
|
* Чтение из таблицы напрямую невозможно - возможно лишь указание в правой части оператора IN.
|
|
|
|
|
*/
|
2016-08-30 19:27:15 +00:00
|
|
|
|
class StorageSet : private ext::shared_ptr_helper<StorageSet>, public StorageSetOrJoinBase
|
2015-01-27 00:52:03 +00:00
|
|
|
|
{
|
2016-08-30 19:27:15 +00:00
|
|
|
|
friend class ext::shared_ptr_helper<StorageSet>;
|
2016-08-26 21:25:05 +00:00
|
|
|
|
|
2015-01-27 00:52:03 +00:00
|
|
|
|
public:
|
|
|
|
|
static StoragePtr create(
|
|
|
|
|
const String & path_,
|
|
|
|
|
const String & name_,
|
|
|
|
|
NamesAndTypesListPtr columns_,
|
|
|
|
|
const NamesAndTypesList & materialized_columns_,
|
|
|
|
|
const NamesAndTypesList & alias_columns_,
|
|
|
|
|
const ColumnDefaults & column_defaults_)
|
|
|
|
|
{
|
2016-08-30 19:27:15 +00:00
|
|
|
|
return ext::shared_ptr_helper<StorageSet>::make_shared(path_, name_, columns_, materialized_columns_, alias_columns_, column_defaults_);
|
2015-01-27 00:52:03 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
String getName() const override { return "Set"; }
|
|
|
|
|
|
|
|
|
|
/// Получить доступ к внутренностям.
|
|
|
|
|
SetPtr & getSet() { return set; }
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
SetPtr set { new Set{Limits{}} };
|
|
|
|
|
|
|
|
|
|
StorageSet(
|
|
|
|
|
const String & path_,
|
|
|
|
|
const String & name_,
|
|
|
|
|
NamesAndTypesListPtr columns_,
|
|
|
|
|
const NamesAndTypesList & materialized_columns_,
|
|
|
|
|
const NamesAndTypesList & alias_columns_,
|
|
|
|
|
const ColumnDefaults & column_defaults_);
|
|
|
|
|
|
2015-01-28 00:08:45 +00:00
|
|
|
|
void insertBlock(const Block & block) override { set->insertFromBlock(block); }
|
|
|
|
|
size_t getSize() const override { return set->getTotalRowCount(); };
|
2015-01-27 00:52:03 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
}
|