mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-30 03:22:14 +00:00
Updates to simply extractDependentTable
This commit is contained in:
parent
00d5997612
commit
aeeb4457ed
@ -54,7 +54,7 @@ namespace ErrorCodes
|
||||
extern const int SUPPORT_IS_DISABLED;
|
||||
}
|
||||
|
||||
static void extractDependentTable(ASTPtr & query, String & select_database_name, String & select_table_name, const String & database_name, const String & table_name, ASTPtr & inner_outer_query, ASTPtr & inner_subquery)
|
||||
static void extractDependentTable(ASTPtr & query, String & select_database_name, String & select_table_name, const String & table_name, ASTPtr & inner_subquery)
|
||||
{
|
||||
ASTSelectQuery & select_query = typeid_cast<ASTSelectQuery &>(*query);
|
||||
auto db_and_table = getDatabaseAndTable(select_query, 0);
|
||||
@ -85,10 +85,9 @@ static void extractDependentTable(ASTPtr & query, String & select_database_name,
|
||||
if (ast_select->list_of_selects->children.size() != 1)
|
||||
throw Exception("UNION is not supported for LIVE VIEW", ErrorCodes::QUERY_IS_NOT_SUPPORTED_IN_LIVE_VIEW);
|
||||
|
||||
inner_outer_query = query;
|
||||
inner_subquery = ast_select->list_of_selects->children.at(0)->clone();
|
||||
|
||||
extractDependentTable(ast_select->list_of_selects->children.at(0), select_database_name, select_table_name, database_name, table_name, inner_outer_query, inner_subquery);
|
||||
extractDependentTable(ast_select->list_of_selects->children.at(0), select_database_name, select_table_name, table_name, inner_subquery);
|
||||
}
|
||||
else
|
||||
throw Exception("Logical error while creating StorageLiveView."
|
||||
@ -195,7 +194,7 @@ void StorageLiveView::writeIntoLiveView(
|
||||
auto blocks_storage = StorageBlocks::createStorage(live_view.database_name, live_view.table_name, parent_storage->getColumns(), std::move(from), QueryProcessingStage::WithMergeableState);
|
||||
block_context->addExternalTable(live_view.table_name + "_blocks", blocks_storage);
|
||||
|
||||
InterpreterSelectQuery select(live_view.getInnerOuterQuery(), *block_context, StoragePtr(), SelectQueryOptions(QueryProcessingStage::Complete));
|
||||
InterpreterSelectQuery select(live_view.getInnerBlocksQuery(), *block_context, StoragePtr(), SelectQueryOptions(QueryProcessingStage::Complete));
|
||||
BlockInputStreamPtr data = std::make_shared<MaterializingBlockInputStream>(select.execute().in);
|
||||
|
||||
/// Squashing is needed here because the view query can generate a lot of blocks
|
||||
@ -231,13 +230,11 @@ StorageLiveView::StorageLiveView(
|
||||
throw Exception("UNION is not supported for LIVE VIEW", ErrorCodes::QUERY_IS_NOT_SUPPORTED_IN_LIVE_VIEW);
|
||||
|
||||
inner_query = query.select->list_of_selects->children.at(0);
|
||||
inner_outer_query = inner_query->clone();
|
||||
ASTPtr outer_query = inner_query->clone();
|
||||
inner_blocks_query = inner_query->clone();
|
||||
|
||||
inner_outer_query = inner_query->clone();
|
||||
InterpreterSelectQuery(inner_outer_query, *live_view_context, SelectQueryOptions().modify().analyze());
|
||||
InterpreterSelectQuery(inner_blocks_query, *live_view_context, SelectQueryOptions().modify().analyze());
|
||||
|
||||
extractDependentTable(inner_outer_query, select_database_name, select_table_name, database_name, table_name, outer_query, inner_subquery);
|
||||
extractDependentTable(inner_blocks_query, select_database_name, select_table_name, table_name, inner_subquery);
|
||||
|
||||
/// If the table is not specified - use the table `system.one`
|
||||
if (select_table_name.empty())
|
||||
@ -323,7 +320,7 @@ bool StorageLiveView::getNewBlocks()
|
||||
auto blocks_storage = StorageBlocks::createStorage(database_name, table_name, global_context.getTable(select_database_name, select_table_name)->getColumns(), {from}, QueryProcessingStage::WithMergeableState);
|
||||
block_context->addExternalTable(table_name + "_blocks", blocks_storage);
|
||||
|
||||
InterpreterSelectQuery select(inner_outer_query->clone(), *block_context, StoragePtr(), SelectQueryOptions(QueryProcessingStage::Complete));
|
||||
InterpreterSelectQuery select(inner_blocks_query->clone(), *block_context, StoragePtr(), SelectQueryOptions(QueryProcessingStage::Complete));
|
||||
BlockInputStreamPtr data = std::make_shared<MaterializingBlockInputStream>(select.execute().in);
|
||||
|
||||
/// Squashing is needed here because the view query can generate a lot of blocks
|
||||
|
@ -49,7 +49,6 @@ public:
|
||||
NameAndTypePair getColumn(const String & column_name) const override;
|
||||
bool hasColumn(const String & column_name) const override;
|
||||
|
||||
// const NamesAndTypesList & getColumnsListImpl() const override { return *columns; }
|
||||
ASTPtr getInnerQuery() const { return inner_query->clone(); }
|
||||
ASTPtr getInnerSubQuery() const
|
||||
{
|
||||
@ -57,10 +56,10 @@ public:
|
||||
return inner_subquery->clone();
|
||||
return nullptr;
|
||||
}
|
||||
ASTPtr getInnerOuterQuery() const
|
||||
ASTPtr getInnerBlocksQuery() const
|
||||
{
|
||||
if (inner_outer_query)
|
||||
return inner_outer_query->clone();
|
||||
if (inner_blocks_query)
|
||||
return inner_blocks_query->clone();
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
@ -160,7 +159,7 @@ private:
|
||||
String database_name;
|
||||
ASTPtr inner_query; /// stored query : SELECT * FROM ( SELECT a FROM A)
|
||||
ASTPtr inner_subquery; /// stored query's innermost subquery if any
|
||||
ASTPtr inner_outer_query; /// query right before innermost subquery
|
||||
ASTPtr inner_blocks_query; /// query over the mergeable blocks to produce final result
|
||||
Context & global_context;
|
||||
std::unique_ptr<Context> live_view_context;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user