提交 b3845b10 编写于 作者: A Alexey Milovidov

More simple

上级 39730bfc
......@@ -28,13 +28,13 @@ public:
MemorySource(
Names column_names_,
BlocksList::iterator first_,
BlocksList::iterator last_,
size_t num_blocks_,
const StorageMemory & storage,
const StorageMetadataPtr & metadata_snapshot)
: SourceWithProgress(metadata_snapshot->getSampleBlockForColumns(column_names_, storage.getVirtuals(), storage.getStorageID()))
, column_names(std::move(column_names_))
, current(first_)
, last(last_) /// [first, last]
, current_it(first_)
, num_blocks(num_blocks_)
{
}
......@@ -49,7 +49,7 @@ protected:
}
else
{
const Block & src = *current;
const Block & src = *current_it;
Columns columns;
columns.reserve(column_names.size());
......@@ -57,17 +57,23 @@ protected:
for (const auto & name : column_names)
columns.emplace_back(src.getByName(name).column);
if (current == last)
if (current_block_idx == num_blocks)
{
is_finished = true;
}
else
++current;
{
++current_it;
++current_block_idx;
}
return Chunk(std::move(columns), src.rows());
}
}
private:
Names column_names;
BlocksList::iterator current;
BlocksList::iterator last;
BlocksList::iterator current_it;
size_t current_block_idx = 0;
const size_t num_blocks;
bool is_finished = false;
};
......@@ -126,27 +132,23 @@ Pipe StorageMemory::read(
Pipes pipes;
BlocksList::iterator first = data.begin();
BlocksList::iterator it = data.begin();
size_t offset = 0;
for (size_t stream = 0; stream < num_streams; ++stream)
{
auto next = first;
while (offset < stream * size / num_streams)
{
++next;
++offset;
}
if (first == next)
continue;
size_t next_offset = stream * size / num_streams;
size_t num_blocks = next_offset - offset;
auto last = next;
--last;
assert(num_blocks > 0);
pipes.emplace_back(std::make_shared<MemorySource>(column_names, first, last, *this, metadata_snapshot));
pipes.emplace_back(std::make_shared<MemorySource>(column_names, it, num_blocks, *this, metadata_snapshot));
first = next;
while (offset < next_offset)
{
++it;
++offset;
}
}
return Pipe::unitePipes(std::move(pipes));
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册