mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-18 05:32:52 +00:00
34 lines
713 B
C++
34 lines
713 B
C++
#include <DB/DataStreams/ConcatBlockInputStream.h>
|
|
|
|
|
|
namespace DB
|
|
{
|
|
|
|
BlockInputStreams narrowBlockInputStreams(BlockInputStreams & inputs, size_t width)
|
|
{
|
|
size_t size = inputs.size();
|
|
if (size <= width)
|
|
return inputs;
|
|
|
|
std::vector<BlockInputStreams> partitions(width);
|
|
|
|
typedef std::vector<size_t> Distribution;
|
|
Distribution distribution(size);
|
|
|
|
for (size_t i = 0; i < size; ++i)
|
|
distribution[i] = i % width;
|
|
|
|
std::random_shuffle(distribution.begin(), distribution.end());
|
|
|
|
for (size_t i = 0; i < size; ++i)
|
|
partitions[distribution[i]].push_back(inputs[i]);
|
|
|
|
BlockInputStreams res(width);
|
|
for (size_t i = 0; i < width; ++i)
|
|
res[i] = new ConcatBlockInputStream(partitions[i]);
|
|
|
|
return res;
|
|
}
|
|
|
|
}
|