ClickHouse/dbms/src/Storages/StorageMerge.h

69 lines
2.3 KiB
C++
Raw Normal View History

2012-05-30 05:53:09 +00:00
#pragma once
2017-06-06 17:18:32 +00:00
#include <ext/shared_ptr_helper.h>
#include <Common/OptimizedRegularExpression.h>
#include <Storages/IStorage.h>
2014-01-10 13:24:50 +00:00
2012-05-30 05:53:09 +00:00
namespace DB
{
2017-04-16 15:00:33 +00:00
/** A table that represents the union of an arbitrary number of other tables.
* All tables must have the same structure.
2012-05-30 05:53:09 +00:00
*/
class StorageMerge : public ext::shared_ptr_helper<StorageMerge>, public IStorage
2012-05-30 05:53:09 +00:00
{
public:
std::string getName() const override { return "Merge"; }
std::string getTableName() const override { return name; }
bool isRemote() const override;
2017-04-16 15:00:33 +00:00
/// The check is delayed to the read method. It checks the support of the tables used.
bool supportsSampling() const override { return true; }
bool supportsPrewhere() const override { return true; }
bool supportsFinal() const override { return true; }
bool supportsIndexForIn() const override { return true; }
NameAndTypePair getColumn(const String & column_name) const override;
bool hasColumn(const String & column_name) const override;
BlockInputStreams read(
const Names & column_names,
const SelectQueryInfo & query_info,
const Context & context,
QueryProcessingStage::Enum & processed_stage,
2017-06-02 15:54:39 +00:00
size_t max_block_size,
unsigned num_streams) override;
void drop() override {}
2017-12-01 21:13:25 +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; }
2017-04-16 15:00:33 +00:00
/// you need to add and remove columns in the sub-tables manually
/// the structure of sub-tables is not checked
void alter(const AlterCommands & params, const String & database_name, const String & table_name, const Context & context) override;
2012-05-30 05:53:09 +00:00
private:
String name;
String source_database;
OptimizedRegularExpression table_name_regexp;
const Context & context;
using StorageListWithLocks = std::list<std::pair<StoragePtr, TableStructureReadLockPtr>>;
StorageListWithLocks getSelectedTables() const;
Block getBlockWithVirtualColumns(const StorageListWithLocks & selected_tables) const;
protected:
StorageMerge(
const std::string & name_,
const ColumnsDescription & columns_,
const String & source_database_,
const String & table_name_regexp_,
const Context & context_);
2012-05-30 05:53:09 +00:00
};
}