small improvements

This commit is contained in:
yariks5s 2024-05-17 17:10:48 +00:00
parent ef9bfbd85a
commit 40a78df96a
4 changed files with 19 additions and 32 deletions

View File

@ -147,47 +147,35 @@ Block ApplySquashing::addImpl(Chunk && input_chunk)
return Block(); return Block();
const auto *info = getInfoFromChunk(input_chunk); const auto *info = getInfoFromChunk(input_chunk);
append(info->chunks); for (auto & chunk : info->chunks)
append(chunk);
Block to_return; Block to_return;
std::swap(to_return, accumulated_block); std::swap(to_return, accumulated_block);
return to_return; return to_return;
} }
void ApplySquashing::append(const std::vector<Chunk> & input_chunks) void ApplySquashing::append(Chunk & input_chunk)
{
std::vector<IColumn::MutablePtr> mutable_columns;
size_t rows = 0;
for (const Chunk & chunk : input_chunks)
rows += chunk.getNumRows();
// add here resize of mutable_column
for (const auto & input_chunk : input_chunks)
{ {
if (input_chunk.getNumColumns() == 0)
return;
if (!accumulated_block) if (!accumulated_block)
{ {
for (size_t i = 0; i < input_chunks[0].getNumColumns(); ++ i) for (size_t i = 0; i < input_chunk.getNumColumns(); ++ i)
{ {
ColumnWithTypeAndName col = ColumnWithTypeAndName(input_chunks[0].getColumns()[i], header.getDataTypes()[i], header.getNames()[i]); ColumnWithTypeAndName col = ColumnWithTypeAndName(input_chunk.getColumns()[i], header.getDataTypes()[i], header.getNames()[i]);
mutable_columns.push_back(IColumn::mutate(col.column)); accumulated_block.insert(accumulated_block.columns(), col);
accumulated_block.insert(col);
} }
return;
} }
if (input_chunk.getNumColumns() == 0)
continue;
for (auto & column : mutable_columns)
column->reserve(rows);
for (size_t i = 0, size = accumulated_block.columns(); i < size; ++i) for (size_t i = 0, size = accumulated_block.columns(); i < size; ++i)
{ {
const auto source_column = input_chunk.getColumns()[i]; const auto source_column = input_chunk.getColumns()[i];
mutable_columns[i] = IColumn::mutate(std::move(accumulated_block.getByPosition(i).column)); auto mutable_column = IColumn::mutate(std::move(accumulated_block.getByPosition(i).column));
mutable_columns[i]->insertRangeFrom(*source_column, 0, source_column->size()); mutable_column->insertRangeFrom(*source_column, 0, source_column->size());
accumulated_block.getByPosition(i).column = mutable_columns[i]->cloneFinalized(); accumulated_block.getByPosition(i).column = std::move(mutable_column);
}
} }
} }

View File

@ -70,7 +70,7 @@ private:
const ChunksToSquash * getInfoFromChunk(const Chunk & chunk); const ChunksToSquash * getInfoFromChunk(const Chunk & chunk);
void append(const std::vector<Chunk> & input_chunk); void append(Chunk & input_chunk);
bool isEnoughSize(const Block & block); bool isEnoughSize(const Block & block);
bool isEnoughSize(size_t rows, size_t bytes) const; bool isEnoughSize(size_t rows, size_t bytes) const;

View File

@ -1,6 +1,5 @@
#include <Processors/Transforms/PlanSquashingTransform.h> #include <Processors/Transforms/PlanSquashingTransform.h>
#include <Processors/IProcessor.h> #include <Processors/IProcessor.h>
#include "Common/logger_useful.h"
#include <Common/Exception.h> #include <Common/Exception.h>
namespace DB namespace DB

View File

@ -318,7 +318,7 @@ Block ProjectionDescription::calculate(const Block & block, ContextPtr context)
} }
else else
{ {
builder.addTransform(std::make_shared<SimpleSquashingTransform>(builder.getHeader(), block.rows(), 0)); builder.addTransform(std::make_shared<SquashingTransform>(builder.getHeader(), block.rows(), 0));
} }
auto pipeline = QueryPipelineBuilder::getPipeline(std::move(builder)); auto pipeline = QueryPipelineBuilder::getPipeline(std::move(builder));