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>
|
|
|
|
|
2013-10-30 13:52:02 +00:00
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
2022-05-03 06:43:28 +00:00
|
|
|
class StorageView final : public IStorage
|
2014-10-29 01:18:50 +00:00
|
|
|
{
|
2013-10-30 13:52:02 +00:00
|
|
|
public:
|
2022-04-19 20:47:29 +00:00
|
|
|
StorageView(
|
|
|
|
const StorageID & table_id_,
|
|
|
|
const ASTCreateQuery & query,
|
|
|
|
const ColumnsDescription & columns_,
|
2023-07-25 12:04:55 +00:00
|
|
|
const String & comment,
|
|
|
|
const bool is_parameterized_view_=false);
|
2022-04-19 20:47:29 +00:00
|
|
|
|
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; }
|
2022-09-23 11:35:22 +00:00
|
|
|
bool isParameterizedView() const { return is_parameterized_view; }
|
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-09-17 13:22:24 +00:00
|
|
|
void read(
|
|
|
|
QueryPlan & query_plan,
|
|
|
|
const Names & column_names,
|
2021-07-09 03:15:41 +00:00
|
|
|
const StorageSnapshotPtr & storage_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,
|
2022-10-07 10:46:45 +00:00
|
|
|
size_t num_streams) override;
|
2020-09-17 13:22:24 +00:00
|
|
|
|
2023-03-13 08:18:44 +00:00
|
|
|
static void replaceQueryParametersIfParametrizedView(ASTPtr & outer_query, const NameToNameMap & parameter_values);
|
2022-09-23 11:35:22 +00:00
|
|
|
|
2022-10-19 16:30:03 +00:00
|
|
|
static void replaceWithSubquery(ASTSelectQuery & select_query, ASTPtr & view_name, const StorageMetadataPtr & metadata_snapshot, const bool parameterized_view)
|
2020-06-15 12:36:10 +00:00
|
|
|
{
|
2022-10-19 16:30:03 +00:00
|
|
|
replaceWithSubquery(select_query, metadata_snapshot->getSelectQuery().inner_query->clone(), view_name, parameterized_view);
|
2020-06-15 12:36:10 +00:00
|
|
|
}
|
2020-02-05 08:22:25 +00:00
|
|
|
|
2022-10-19 16:30:03 +00:00
|
|
|
static void replaceWithSubquery(ASTSelectQuery & outer_query, ASTPtr view_query, ASTPtr & view_name, const bool parameterized_view);
|
2020-06-15 12:36:10 +00:00
|
|
|
static ASTPtr restoreViewName(ASTSelectQuery & select_query, const ASTPtr & view_name);
|
2022-12-19 14:05:38 +00:00
|
|
|
|
2022-09-23 11:35:22 +00:00
|
|
|
protected:
|
|
|
|
bool is_parameterized_view;
|
2013-10-30 13:52:02 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|