2012-05-30 05:53:09 +00:00
|
|
|
|
#pragma once
|
|
|
|
|
|
2015-10-05 01:11:12 +00:00
|
|
|
|
#include <DB/Common/OptimizedRegularExpression.h>
|
2012-05-30 05:53:09 +00:00
|
|
|
|
#include <DB/Storages/IStorage.h>
|
2014-01-10 13:24:50 +00:00
|
|
|
|
|
2012-05-30 05:53:09 +00:00
|
|
|
|
|
|
|
|
|
namespace DB
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
/** Таблица, представляющая собой объединение произвольного количества других таблиц.
|
|
|
|
|
* У всех таблиц должна быть одинаковая структура.
|
|
|
|
|
*/
|
|
|
|
|
class StorageMerge : public IStorage
|
|
|
|
|
{
|
|
|
|
|
public:
|
2013-02-06 11:26:35 +00:00
|
|
|
|
static StoragePtr create(
|
2012-05-30 05:53:09 +00:00
|
|
|
|
const std::string & name_, /// Имя таблицы.
|
|
|
|
|
NamesAndTypesListPtr columns_, /// Список столбцов.
|
|
|
|
|
const String & source_database_, /// В какой БД искать таблицы-источники.
|
|
|
|
|
const String & table_name_regexp_, /// Регексп имён таблиц-источников.
|
2013-05-05 18:02:05 +00:00
|
|
|
|
const Context & context_); /// Известные таблицы.
|
2012-05-30 05:53:09 +00:00
|
|
|
|
|
2014-09-30 03:08:47 +00:00
|
|
|
|
static StoragePtr create(
|
|
|
|
|
const std::string & name_, /// Имя таблицы.
|
|
|
|
|
NamesAndTypesListPtr columns_, /// Список столбцов.
|
2014-10-03 15:30:10 +00:00
|
|
|
|
const NamesAndTypesList & materialized_columns_,
|
2014-09-30 03:08:47 +00:00
|
|
|
|
const NamesAndTypesList & alias_columns_,
|
|
|
|
|
const ColumnDefaults & column_defaults_,
|
|
|
|
|
const String & source_database_, /// В какой БД искать таблицы-источники.
|
|
|
|
|
const String & table_name_regexp_, /// Регексп имён таблиц-источников.
|
|
|
|
|
const Context & context_); /// Известные таблицы.
|
|
|
|
|
|
2014-10-03 17:55:36 +00:00
|
|
|
|
std::string getName() const override { return "Merge"; }
|
|
|
|
|
std::string getTableName() const override { return name; }
|
2012-05-30 05:53:09 +00:00
|
|
|
|
|
2016-04-04 21:41:16 +00:00
|
|
|
|
/// Проверка откладывается до метода read. Там проверяется поддержка у использующихся таблиц.
|
2015-05-18 21:20:43 +00:00
|
|
|
|
bool supportsSampling() const override { return true; }
|
2014-10-03 17:55:36 +00:00
|
|
|
|
bool supportsPrewhere() const override { return true; }
|
2015-05-18 21:20:43 +00:00
|
|
|
|
bool supportsFinal() const override { return true; }
|
|
|
|
|
bool supportsIndexForIn() const override { return true; }
|
2015-01-16 15:22:12 +00:00
|
|
|
|
|
2014-10-10 15:45:43 +00:00
|
|
|
|
const NamesAndTypesList & getColumnsListImpl() const override { return *columns; }
|
2016-03-05 03:17:11 +00:00
|
|
|
|
NameAndTypePair getColumn(const String & column_name) const override;
|
|
|
|
|
bool hasColumn(const String & column_name) const override;
|
2012-05-30 05:53:09 +00:00
|
|
|
|
|
|
|
|
|
BlockInputStreams read(
|
|
|
|
|
const Names & column_names,
|
|
|
|
|
ASTPtr query,
|
2014-12-17 11:53:17 +00:00
|
|
|
|
const Context & context,
|
2013-02-01 19:02:04 +00:00
|
|
|
|
const Settings & settings,
|
2012-05-30 05:53:09 +00:00
|
|
|
|
QueryProcessingStage::Enum & processed_stage,
|
|
|
|
|
size_t max_block_size = DEFAULT_BLOCK_SIZE,
|
2014-10-03 17:55:36 +00:00
|
|
|
|
unsigned threads = 1) override;
|
2012-05-30 05:53:09 +00:00
|
|
|
|
|
2014-03-20 13:28:49 +00:00
|
|
|
|
void drop() override {}
|
2014-10-03 17:55:36 +00:00
|
|
|
|
void rename(const String & new_path_to_db, const String & new_database_name, const String & new_table_name) override { name = new_table_name; }
|
2014-10-18 19:14:09 +00:00
|
|
|
|
|
2013-09-23 12:01:19 +00:00
|
|
|
|
/// в подтаблицах добавлять и удалять столбы нужно вручную
|
|
|
|
|
/// структура подтаблиц не проверяется
|
2016-01-28 01:00:27 +00:00
|
|
|
|
void alter(const AlterCommands & params, const String & database_name, const String & table_name, const Context & context) override;
|
2014-02-11 18:38:21 +00:00
|
|
|
|
|
2012-05-30 05:53:09 +00:00
|
|
|
|
private:
|
2012-06-18 06:19:13 +00:00
|
|
|
|
String name;
|
2012-05-30 05:53:09 +00:00
|
|
|
|
NamesAndTypesListPtr columns;
|
|
|
|
|
String source_database;
|
|
|
|
|
OptimizedRegularExpression table_name_regexp;
|
2013-05-05 18:02:05 +00:00
|
|
|
|
const Context & context;
|
2014-10-18 19:14:09 +00:00
|
|
|
|
|
2013-02-06 11:26:35 +00:00
|
|
|
|
StorageMerge(
|
|
|
|
|
const std::string & name_,
|
|
|
|
|
NamesAndTypesListPtr columns_,
|
|
|
|
|
const String & source_database_,
|
|
|
|
|
const String & table_name_regexp_,
|
2013-05-05 18:02:05 +00:00
|
|
|
|
const Context & context_);
|
2014-04-13 09:46:36 +00:00
|
|
|
|
|
2013-02-06 11:26:35 +00:00
|
|
|
|
StorageMerge(
|
|
|
|
|
const std::string & name_,
|
|
|
|
|
NamesAndTypesListPtr columns_,
|
2014-10-03 15:30:10 +00:00
|
|
|
|
const NamesAndTypesList & materialized_columns_,
|
2014-09-30 03:08:47 +00:00
|
|
|
|
const NamesAndTypesList & alias_columns_,
|
|
|
|
|
const ColumnDefaults & column_defaults_,
|
2013-02-06 11:26:35 +00:00
|
|
|
|
const String & source_database_,
|
|
|
|
|
const String & table_name_regexp_,
|
2013-05-05 18:02:05 +00:00
|
|
|
|
const Context & context_);
|
2014-04-13 09:46:36 +00:00
|
|
|
|
|
|
|
|
|
void getSelectedTables(StorageVector & selected_tables) const;
|
2014-10-03 17:55:36 +00:00
|
|
|
|
|
|
|
|
|
Block getBlockWithVirtualColumns(const StorageVector & selected_tables) const;
|
2012-05-30 05:53:09 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
}
|