ClickHouse/dbms/src/Storages/StorageMaterializedView.h

103 lines
3.6 KiB
C++
Raw Normal View History

#pragma once
2017-06-06 17:18:32 +00:00
#include <ext/shared_ptr_helper.h>
2019-03-11 14:01:45 +00:00
#include <Parsers/IAST_fwd.h>
#include <Parsers/ASTSelectWithUnionQuery.h>
#include <Storages/IStorage.h>
#include <Storages/StorageInMemoryMetadata.h>
namespace DB
{
class StorageMaterializedView final : public ext::shared_ptr_helper<StorageMaterializedView>, public IStorage
{
2019-08-26 19:07:29 +00:00
friend struct ext::shared_ptr_helper<StorageMaterializedView>;
public:
std::string getName() const override { return "MaterializedView"; }
2020-01-24 16:20:36 +00:00
bool isView() const override { return true; }
ASTPtr getSelectQuery() const { return select->clone(); }
ASTPtr getInnerQuery() const { return inner_query->clone(); }
NameAndTypePair getColumn(const String & column_name) const override;
bool hasColumn(const String & column_name) const override;
StorageInMemoryMetadata getInMemoryMetadata() const override;
bool supportsSampling() const override { return getTargetTable()->supportsSampling(); }
bool supportsPrewhere() const override { return getTargetTable()->supportsPrewhere(); }
bool supportsFinal() const override { return getTargetTable()->supportsFinal(); }
bool supportsIndexForIn() const override { return getTargetTable()->supportsIndexForIn(); }
bool mayBenefitFromIndexForIn(const ASTPtr & left_in_operand, const Context & query_context) const override
{
return getTargetTable()->mayBenefitFromIndexForIn(left_in_operand, query_context);
}
BlockOutputStreamPtr write(const ASTPtr & query, const Context & context) override;
2019-08-27 20:43:08 +00:00
void drop(TableStructureWriteLockHolder &) override;
2019-08-27 20:43:08 +00:00
void truncate(const ASTPtr &, const Context &, TableStructureWriteLockHolder &) override;
2018-04-21 00:35:20 +00:00
bool optimize(const ASTPtr & query, const ASTPtr & partition, bool final, bool deduplicate, const Context & context) override;
void alter(const AlterCommands & params, const Context & context, TableStructureWriteLockHolder & table_lock_holder) override;
void checkAlterIsPossible(const AlterCommands & commands, const Settings & settings) override;
void alterPartition(const ASTPtr & query, const PartitionCommands & commands, const Context & context) override;
void mutate(const MutationCommands & commands, const Context & context) override;
2019-08-27 20:43:08 +00:00
void rename(const String & new_path_to_db, const String & new_database_name, const String & new_table_name, TableStructureWriteLockHolder &) override;
void shutdown() override;
void checkTableCanBeDropped() const override;
void checkPartitionCanBeDropped(const ASTPtr & partition) override;
QueryProcessingStage::Enum getQueryProcessingStage(const Context & context) const override;
2018-10-17 14:08:52 +00:00
StoragePtr getTargetTable() const;
StoragePtr tryGetTargetTable() const;
ActionLock getActionLock(StorageActionBlockType type) override;
Pipes read(
const Names & column_names,
const SelectQueryInfo & query_info,
const Context & context,
QueryProcessingStage::Enum processed_stage,
size_t max_block_size,
2017-06-02 15:54:39 +00:00
unsigned num_streams) override;
2019-04-04 13:13:59 +00:00
Strings getDataPaths() const override;
private:
2019-12-30 18:20:43 +00:00
/// Can be empty if SELECT query doesn't contain table
StorageID select_table_id = StorageID::createEmpty();
/// Will be initialized in constructor
StorageID target_table_id = StorageID::createEmpty();
ASTPtr select;
ASTPtr inner_query;
Context & global_context;
bool has_inner_table = false;
void checkStatementCanBeForwarded() const;
protected:
StorageMaterializedView(
2019-12-04 16:06:55 +00:00
const StorageID & table_id_,
Context & local_context,
const ASTCreateQuery & query,
const ColumnsDescription & columns_,
bool attach_);
};
}