ClickHouse/dbms/src/DataStreams/narrowBlockInputStreams.cpp

34 lines
713 B
C++
Raw Normal View History

2012-06-25 03:04:34 +00:00
#include <DB/DataStreams/ConcatBlockInputStream.h>
namespace DB
{
BlockInputStreams narrowBlockInputStreams(BlockInputStreams & inputs, size_t width)
{
2012-08-21 18:34:55 +00:00
size_t size = inputs.size();
if (size <= width)
2012-06-25 03:04:34 +00:00
return inputs;
std::vector<BlockInputStreams> partitions(width);
2012-08-21 18:34:55 +00:00
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]);
2012-06-25 03:04:34 +00:00
BlockInputStreams res(width);
for (size_t i = 0; i < width; ++i)
res[i] = new ConcatBlockInputStream(partitions[i]);
return res;
}
}