Minor style changes in StorageMaterializedView::read, StorageMerge::createSources

This commit is contained in:
vdimir 2021-06-12 12:27:05 +03:00
parent 768b8fed75
commit 26c59961ae
No known key found for this signature in database
GPG Key ID: F57B3E10A21DBB31
2 changed files with 17 additions and 28 deletions

View File

@ -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))
{

View File

@ -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);