mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-14 19:45:11 +00:00
Minor style changes in StorageMaterializedView::read, StorageMerge::createSources
This commit is contained in:
parent
768b8fed75
commit
26c59961ae
@ -47,6 +47,17 @@ static inline String generateInnerTableName(const StorageID & view_id)
|
||||
return ".inner." + view_id.getTableName();
|
||||
}
|
||||
|
||||
/// Remove columns from target_header that does not exists in src_header
|
||||
static void removeNonCommonColumns(const Block & src_header, Block & target_header)
|
||||
{
|
||||
std::set<size_t> target_only_positions;
|
||||
for (const auto & column : target_header)
|
||||
{
|
||||
if (!src_header.has(column.name))
|
||||
target_only_positions.insert(target_header.getPositionByName(column.name));
|
||||
}
|
||||
target_header.erase(target_only_positions);
|
||||
}
|
||||
|
||||
StorageMaterializedView::StorageMaterializedView(
|
||||
const StorageID & table_id_,
|
||||
@ -168,26 +179,14 @@ void StorageMaterializedView::read(
|
||||
auto target_header = query_plan.getCurrentDataStream().header;
|
||||
|
||||
/// No need to convert columns that does not exists in MV
|
||||
std::set<size_t> target_only_positions;
|
||||
for (const auto & column : target_header)
|
||||
{
|
||||
if (!mv_header.has(column.name))
|
||||
target_only_positions.insert(target_header.getPositionByName(column.name));
|
||||
}
|
||||
target_header.erase(target_only_positions);
|
||||
removeNonCommonColumns(mv_header, target_header);
|
||||
|
||||
/// No need to convert columns that does not exists in the result header.
|
||||
///
|
||||
/// Distributed storage may process query up to the specific stage, and
|
||||
/// so the result header may not include all the columns from the
|
||||
/// materialized view.
|
||||
std::set<size_t> source_only_positions;
|
||||
for (const auto & column : mv_header)
|
||||
{
|
||||
if (!target_header.has(column.name))
|
||||
source_only_positions.insert(mv_header.getPositionByName(column.name));
|
||||
}
|
||||
mv_header.erase(source_only_positions);
|
||||
removeNonCommonColumns(target_header, mv_header);
|
||||
|
||||
if (!blocksHaveEqualStructure(mv_header, target_header))
|
||||
{
|
||||
|
@ -41,18 +41,6 @@ namespace ErrorCodes
|
||||
extern const int ALTER_OF_COLUMN_IS_FORBIDDEN;
|
||||
}
|
||||
|
||||
namespace
|
||||
{
|
||||
|
||||
TreeRewriterResult modifySelect(ASTSelectQuery & select, const TreeRewriterResult & rewriter_result, ContextPtr context)
|
||||
{
|
||||
TreeRewriterResult new_rewriter_result = rewriter_result;
|
||||
removeJoin(select, new_rewriter_result, context);
|
||||
return new_rewriter_result;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
StorageMerge::StorageMerge(
|
||||
const StorageID & table_id_,
|
||||
const ColumnsDescription & columns_,
|
||||
@ -147,7 +135,7 @@ QueryProcessingStage::Enum StorageMerge::getQueryProcessingStage(
|
||||
/// should be done on the initiator always.
|
||||
///
|
||||
/// Since in case of JOIN query on shards will receive query w/o JOIN (and their columns).
|
||||
/// (see modifySelect()/removeJoin())
|
||||
/// (see removeJoin())
|
||||
///
|
||||
/// And for this we need to return FetchColumns.
|
||||
if (const auto * select = query_info.query->as<ASTSelectQuery>(); select && hasJoin(*select))
|
||||
@ -297,7 +285,9 @@ Pipe StorageMerge::createSources(
|
||||
|
||||
/// Original query could contain JOIN but we need only the first joined table and its columns.
|
||||
auto & modified_select = modified_query_info.query->as<ASTSelectQuery &>();
|
||||
auto new_analyzer_res = modifySelect(modified_select, *query_info.syntax_analyzer_result, modified_context);
|
||||
|
||||
TreeRewriterResult new_analyzer_res = *query_info.syntax_analyzer_result;
|
||||
removeJoin(modified_select, new_analyzer_res, modified_context);
|
||||
modified_query_info.syntax_analyzer_result = std::make_shared<TreeRewriterResult>(std::move(new_analyzer_res));
|
||||
|
||||
VirtualColumnUtils::rewriteEntityInAst(modified_query_info.query, "_table", table_name);
|
||||
|
Loading…
Reference in New Issue
Block a user