2013-11-08 17:43:03 +00:00
|
|
|
#pragma once
|
|
|
|
|
2017-06-06 17:18:32 +00:00
|
|
|
#include <ext/shared_ptr_helper.h>
|
2016-08-26 21:25:05 +00:00
|
|
|
|
2017-07-25 21:07:05 +00:00
|
|
|
#include <Storages/IStorage.h>
|
2013-11-08 17:43:03 +00:00
|
|
|
|
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
2017-07-25 21:07:05 +00:00
|
|
|
class IAST;
|
|
|
|
using ASTPtr = std::shared_ptr<IAST>;
|
|
|
|
|
|
|
|
|
|
|
|
class StorageMaterializedView : public ext::shared_ptr_helper<StorageMaterializedView>, public IStorage
|
2016-08-26 21:25:05 +00:00
|
|
|
{
|
2013-11-08 17:43:03 +00:00
|
|
|
public:
|
2017-04-01 07:20:54 +00:00
|
|
|
std::string getName() const override { return "MaterializedView"; }
|
2017-07-25 21:07:05 +00:00
|
|
|
std::string getTableName() const override { return table_name; }
|
2017-12-25 21:57:29 +00:00
|
|
|
const NamesAndTypesList & getColumnsListImpl() const override { return columns; }
|
2017-07-25 21:07:05 +00:00
|
|
|
ASTPtr getInnerQuery() const { return inner_query->clone(); };
|
2017-10-21 20:08:49 +00:00
|
|
|
StoragePtr getTargetTable() const;
|
2013-11-08 17:43:03 +00:00
|
|
|
|
2017-12-25 21:57:29 +00:00
|
|
|
NameAndTypePair getColumn(const String & column_name) const override;
|
2017-04-01 07:20:54 +00:00
|
|
|
bool hasColumn(const String & column_name) const override;
|
2014-08-05 10:56:58 +00:00
|
|
|
|
2017-10-21 20:08:49 +00:00
|
|
|
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(); }
|
2014-10-07 23:08:56 +00:00
|
|
|
|
2017-05-21 22:25:25 +00:00
|
|
|
BlockOutputStreamPtr write(const ASTPtr & query, const Settings & settings) override;
|
2017-04-01 07:20:54 +00:00
|
|
|
void drop() override;
|
2017-09-06 20:34:26 +00:00
|
|
|
bool optimize(const ASTPtr & query, const ASTPtr & partition, bool final, bool deduplicate, const Context & context) override;
|
2017-12-16 01:41:06 +00:00
|
|
|
void shutdown() override;
|
2018-02-12 19:26:16 +00:00
|
|
|
bool checkTableCanBeDropped() const override;
|
2013-11-08 17:43:03 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
BlockInputStreams read(
|
|
|
|
const Names & column_names,
|
2017-07-15 03:48:36 +00:00
|
|
|
const SelectQueryInfo & query_info,
|
2017-04-01 07:20:54 +00:00
|
|
|
const Context & context,
|
|
|
|
QueryProcessingStage::Enum & processed_stage,
|
2017-06-02 15:54:39 +00:00
|
|
|
size_t max_block_size,
|
|
|
|
unsigned num_streams) override;
|
2013-11-08 17:43:03 +00:00
|
|
|
|
2018-02-21 19:26:59 +00:00
|
|
|
String getDataPath() const override { return getTargetTable()->getDataPath(); }
|
|
|
|
|
2013-11-08 17:43:03 +00:00
|
|
|
private:
|
2017-07-25 21:07:05 +00:00
|
|
|
String select_database_name;
|
|
|
|
String select_table_name;
|
2017-10-21 20:08:49 +00:00
|
|
|
String target_database_name;
|
|
|
|
String target_table_name;
|
2017-07-25 21:07:05 +00:00
|
|
|
String table_name;
|
|
|
|
String database_name;
|
|
|
|
ASTPtr inner_query;
|
2017-10-26 15:39:56 +00:00
|
|
|
Context & global_context;
|
2017-10-21 20:08:49 +00:00
|
|
|
bool has_inner_table = false;
|
2017-07-25 21:07:05 +00:00
|
|
|
|
2017-11-04 03:20:18 +00:00
|
|
|
protected:
|
2017-04-01 07:20:54 +00:00
|
|
|
StorageMaterializedView(
|
|
|
|
const String & table_name_,
|
|
|
|
const String & database_name_,
|
2017-10-26 15:39:56 +00:00
|
|
|
Context & local_context,
|
2017-09-17 18:49:43 +00:00
|
|
|
const ASTCreateQuery & query,
|
2017-12-25 21:57:29 +00:00
|
|
|
const NamesAndTypesList & columns_,
|
|
|
|
const NamesAndTypesList & materialized_columns_,
|
|
|
|
const NamesAndTypesList & alias_columns_,
|
2017-04-01 07:20:54 +00:00
|
|
|
const ColumnDefaults & column_defaults_,
|
|
|
|
bool attach_);
|
2013-11-08 17:43:03 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|