2020-06-16 15:47:40 +00:00
|
|
|
#include <Processors/QueryPlan/MergingSortedStep.h>
|
|
|
|
#include <Processors/QueryPipeline.h>
|
|
|
|
#include <Processors/Merges/MergingSortedTransform.h>
|
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
2020-06-18 13:00:16 +00:00
|
|
|
static ITransformingStep::DataStreamTraits getTraits()
|
|
|
|
{
|
2020-06-18 20:11:42 +00:00
|
|
|
return ITransformingStep::DataStreamTraits
|
|
|
|
{
|
2020-06-18 13:00:16 +00:00
|
|
|
.preserves_distinct_columns = true
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2020-06-16 15:47:40 +00:00
|
|
|
MergingSortedStep::MergingSortedStep(
|
2020-06-16 16:13:07 +00:00
|
|
|
const DataStream & input_stream,
|
2020-06-16 15:47:40 +00:00
|
|
|
SortDescription sort_description_,
|
|
|
|
size_t max_block_size_,
|
|
|
|
UInt64 limit_)
|
2020-06-18 13:00:16 +00:00
|
|
|
: ITransformingStep(input_stream, input_stream.header, getTraits())
|
2020-06-16 15:47:40 +00:00
|
|
|
, sort_description(std::move(sort_description_))
|
|
|
|
, max_block_size(max_block_size_)
|
|
|
|
, limit(limit_)
|
|
|
|
{
|
2020-06-18 13:00:16 +00:00
|
|
|
/// Streams are merged together, only global distinct keys remain distinct.
|
|
|
|
/// Note: we can not clear it if know that there will be only one stream in pipeline. Should we add info about it?
|
|
|
|
output_stream->local_distinct_columns.clear();
|
2020-06-16 15:47:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void MergingSortedStep::transformPipeline(QueryPipeline & pipeline)
|
|
|
|
{
|
|
|
|
/// If there are several streams, then we merge them into one
|
|
|
|
if (pipeline.getNumStreams() > 1)
|
|
|
|
{
|
|
|
|
|
|
|
|
auto transform = std::make_shared<MergingSortedTransform>(
|
|
|
|
pipeline.getHeader(),
|
|
|
|
pipeline.getNumStreams(),
|
|
|
|
sort_description,
|
|
|
|
max_block_size, limit);
|
|
|
|
|
|
|
|
pipeline.addPipe({ std::move(transform) });
|
|
|
|
|
|
|
|
pipeline.enableQuotaForCurrentStreams();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|