2013-10-30 13:52:02 +00:00
|
|
|
#pragma once
|
|
|
|
|
2018-08-16 02:55:52 +00:00
|
|
|
#include <Parsers/ASTSelectQuery.h>
|
2019-03-11 14:01:45 +00:00
|
|
|
#include <Parsers/IAST_fwd.h>
|
|
|
|
#include <Storages/IStorage.h>
|
|
|
|
|
2021-10-02 07:13:14 +00:00
|
|
|
#include <base/shared_ptr_helper.h>
|
2013-10-30 13:52:02 +00:00
|
|
|
|
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
2021-06-15 19:55:21 +00:00
|
|
|
class StorageView final : public shared_ptr_helper<StorageView>, public IStorage
|
2014-10-29 01:18:50 +00:00
|
|
|
{
|
2021-06-15 19:55:21 +00:00
|
|
|
friend struct shared_ptr_helper<StorageView>;
|
2013-10-30 13:52:02 +00:00
|
|
|
public:
|
2017-04-01 07:20:54 +00:00
|
|
|
std::string getName() const override { return "View"; }
|
2020-01-24 16:20:36 +00:00
|
|
|
bool isView() const override { return true; }
|
2013-11-08 17:43:03 +00:00
|
|
|
|
2017-04-16 15:00:33 +00:00
|
|
|
/// It is passed inside the query and solved at its level.
|
2017-04-01 07:20:54 +00:00
|
|
|
bool supportsSampling() const override { return true; }
|
2017-07-25 21:07:05 +00:00
|
|
|
bool supportsFinal() const override { return true; }
|
2014-10-07 23:08:56 +00:00
|
|
|
|
2020-08-03 13:54:14 +00:00
|
|
|
Pipe read(
|
2017-04-01 07:20:54 +00:00
|
|
|
const Names & column_names,
|
2020-06-15 19:08:58 +00:00
|
|
|
const StorageMetadataPtr & /*metadata_snapshot*/,
|
2020-09-20 17:52:17 +00:00
|
|
|
SelectQueryInfo & query_info,
|
2021-04-10 23:33:54 +00:00
|
|
|
ContextPtr context,
|
2018-04-19 14:47:09 +00:00
|
|
|
QueryProcessingStage::Enum processed_stage,
|
2019-02-18 23:38:44 +00:00
|
|
|
size_t max_block_size,
|
2017-06-02 15:54:39 +00:00
|
|
|
unsigned num_streams) override;
|
2013-11-08 17:43:03 +00:00
|
|
|
|
2020-09-17 13:22:24 +00:00
|
|
|
void read(
|
|
|
|
QueryPlan & query_plan,
|
|
|
|
const Names & column_names,
|
2020-09-18 11:39:07 +00:00
|
|
|
const StorageMetadataPtr & metadata_snapshot,
|
2020-11-10 12:02:22 +00:00
|
|
|
SelectQueryInfo & query_info,
|
2021-04-10 23:33:54 +00:00
|
|
|
ContextPtr context,
|
2020-09-17 13:22:24 +00:00
|
|
|
QueryProcessingStage::Enum processed_stage,
|
|
|
|
size_t max_block_size,
|
|
|
|
unsigned num_streams) override;
|
|
|
|
|
2020-06-17 14:06:22 +00:00
|
|
|
void replaceWithSubquery(ASTSelectQuery & select_query, ASTPtr & view_name, const StorageMetadataPtr & metadata_snapshot) const
|
2020-06-15 12:36:10 +00:00
|
|
|
{
|
2020-06-17 14:06:22 +00:00
|
|
|
replaceWithSubquery(select_query, metadata_snapshot->getSelectQuery().inner_query->clone(), view_name);
|
2020-06-15 12:36:10 +00:00
|
|
|
}
|
2020-02-05 08:22:25 +00:00
|
|
|
|
2020-06-15 12:36:10 +00:00
|
|
|
static void replaceWithSubquery(ASTSelectQuery & outer_query, ASTPtr view_query, ASTPtr & view_name);
|
|
|
|
static ASTPtr restoreViewName(ASTSelectQuery & select_query, const ASTPtr & view_name);
|
2020-02-05 08:22:25 +00:00
|
|
|
|
2017-11-04 03:20:18 +00:00
|
|
|
protected:
|
2017-04-01 07:20:54 +00:00
|
|
|
StorageView(
|
2019-12-04 16:06:55 +00:00
|
|
|
const StorageID & table_id_,
|
2017-09-17 18:49:43 +00:00
|
|
|
const ASTCreateQuery & query,
|
2021-05-13 14:21:55 +00:00
|
|
|
const ColumnsDescription & columns_,
|
2021-06-22 14:32:02 +00:00
|
|
|
const String & comment);
|
2013-10-30 13:52:02 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|