Skip to content

Commit

Permalink
remove repeat mergeBlocks
Browse files Browse the repository at this point in the history
  • Loading branch information
SeaRise committed Dec 28, 2022
1 parent bf3518a commit 2fe6c7b
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 49 deletions.
6 changes: 3 additions & 3 deletions dbms/src/Flash/tests/gtest_projection_executor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -343,23 +343,23 @@ try
.scan("test_db", "test_table3")
.project({lit(Field(String("a")))})
.build(context);
executeAndAssertColumnsEqual(req, {createColumns({toVec<String>({"a", "a", "a", "a", "a"})})});
executeAndAssertColumnsEqual(req, {createColumns({createConstColumn<String>(5, "a")})});

req = context
.scan("test_db", "test_table3")
.project(MockAstVec{})
.project(MockAstVec{})
.project({lit(Field(String("a")))})
.build(context);
executeAndAssertColumnsEqual(req, {createColumns({toVec<String>({"a", "a", "a", "a", "a"})})});
executeAndAssertColumnsEqual(req, {createColumns({createConstColumn<String>(5, "a")})});

req = context
.scan("test_db", "test_table3")
.project({col("s1"), col("s2"), col("s3"), col("s4")})
.project(MockAstVec{})
.project({lit(Field(String("a")))})
.build(context);
executeAndAssertColumnsEqual(req, {createColumns({toVec<String>({"a", "a", "a", "a", "a"})})});
executeAndAssertColumnsEqual(req, {createColumns({createConstColumn<String>(5, "a")})});

req = context
.scan("test_db", "test_table3")
Expand Down
17 changes: 1 addition & 16 deletions dbms/src/Storages/DeltaMerge/tests/gtest_segment_test_basic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -303,22 +303,7 @@ Block SegmentTestBasic::prepareWriteBlock(Int64 start_key, Int64 end_key, bool i

Block sortMergeBlocks(std::vector<Block> && blocks)
{
auto accumulated_block = std::move(blocks[0]);

for (size_t block_idx = 1; block_idx < blocks.size(); ++block_idx)
{
auto block = std::move(blocks[block_idx]);

size_t columns = block.columns();
size_t rows = block.rows();

for (size_t i = 0; i < columns; ++i)
{
MutableColumnPtr mutable_column = (*std::move(accumulated_block.getByPosition(i).column)).mutate();
mutable_column->insertRangeFrom(*block.getByPosition(i).column, 0, rows);
accumulated_block.getByPosition(i).column = std::move(mutable_column);
}
}
auto accumulated_block = mergeBlocks(std::move(blocks));

SortDescription sort;
sort.emplace_back(EXTRA_HANDLE_COLUMN_NAME, 1, 0);
Expand Down
32 changes: 2 additions & 30 deletions dbms/src/TestUtils/ExecutorTestUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -166,34 +166,6 @@ void ExecutorTest::executeAndAssertRowsEqual(const std::shared_ptr<tipb::DAGRequ
});
}

Block mergeBlocksForTest(Blocks blocks)
{
if (blocks.empty())
return {};

Block sample_block = blocks.back();
std::vector<MutableColumnPtr> actual_cols;
for (const auto & column : sample_block.getColumnsWithTypeAndName())
{
actual_cols.push_back(column.type->createColumn());
}
for (const auto & block : blocks)
{
for (size_t i = 0; i < block.columns(); ++i)
{
for (size_t j = 0; j < block.rows(); ++j)
{
actual_cols[i]->insert((*(block.getColumnsWithTypeAndName())[i].column)[j]);
}
}
}

ColumnsWithTypeAndName actual_columns;
for (size_t i = 0; i < actual_cols.size(); ++i)
actual_columns.push_back({std::move(actual_cols[i]), sample_block.getColumnsWithTypeAndName()[i].type, sample_block.getColumnsWithTypeAndName()[i].name, sample_block.getColumnsWithTypeAndName()[i].column_id});
return Block(actual_columns);
}

void readStream(Blocks & blocks, BlockInputStreamPtr stream)
{
stream->readPrefix();
Expand All @@ -214,7 +186,7 @@ DB::ColumnsWithTypeAndName readBlocks(std::vector<BlockInputStreamPtr> streams)
Blocks actual_blocks;
for (const auto & stream : streams)
readStream(actual_blocks, stream);
return mergeBlocksForTest(std::move(actual_blocks)).getColumnsWithTypeAndName();
return mergeBlocks(std::move(actual_blocks)).getColumnsWithTypeAndName();
}

void ExecutorTest::enablePlanner(bool is_enable)
Expand All @@ -238,7 +210,7 @@ ColumnsWithTypeAndName ExecutorTest::executeStreams(DAGContext * dag_context)
// Currently, don't care about regions information in tests.
Blocks blocks;
queryExecute(context.context, /*internal=*/true)->execute([&blocks](const Block & block) { blocks.push_back(block); }).verify();
return mergeBlocksForTest(std::move(blocks)).getColumnsWithTypeAndName();
return mergeBlocks(std::move(blocks)).getColumnsWithTypeAndName();
}

Blocks ExecutorTest::getExecuteStreamsReturnBlocks(const std::shared_ptr<tipb::DAGRequest> & request, size_t concurrency)
Expand Down

0 comments on commit 2fe6c7b

Please sign in to comment.