2017-09-08 23:31:18 +00:00
|
|
|
#include <random>
|
2019-07-28 15:30:38 +00:00
|
|
|
#include <Common/thread_local_rng.h>
|
2017-04-01 09:19:00 +00:00
|
|
|
#include <DataStreams/ConcatBlockInputStream.h>
|
2012-06-25 03:04:34 +00:00
|
|
|
|
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
|
|
|
BlockInputStreams narrowBlockInputStreams(BlockInputStreams & inputs, size_t width)
|
|
|
|
{
|
2017-04-01 07:20:54 +00:00
|
|
|
size_t size = inputs.size();
|
|
|
|
if (size <= width)
|
|
|
|
return inputs;
|
2012-06-25 03:04:34 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
std::vector<BlockInputStreams> partitions(width);
|
2012-06-25 03:04:34 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
using Distribution = std::vector<size_t>;
|
|
|
|
Distribution distribution(size);
|
2012-08-21 18:34:55 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
for (size_t i = 0; i < size; ++i)
|
|
|
|
distribution[i] = i % width;
|
2012-08-21 18:34:55 +00:00
|
|
|
|
2019-07-28 15:30:38 +00:00
|
|
|
std::shuffle(distribution.begin(), distribution.end(), thread_local_rng);
|
2012-08-21 18:34:55 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
for (size_t i = 0; i < size; ++i)
|
|
|
|
partitions[distribution[i]].push_back(inputs[i]);
|
2012-06-25 03:04:34 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
BlockInputStreams res(width);
|
|
|
|
for (size_t i = 0; i < width; ++i)
|
|
|
|
res[i] = std::make_shared<ConcatBlockInputStream>(partitions[i]);
|
2012-06-25 03:04:34 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
return res;
|
2012-06-25 03:04:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|