2018-10-19 12:02:31 +00:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <Core/SortDescription.h>
|
|
|
|
#include <Interpreters/sortBlock.h>
|
2019-01-23 14:48:50 +00:00
|
|
|
#include <DataStreams/IBlockInputStream.h>
|
2018-10-19 12:02:31 +00:00
|
|
|
|
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
|
|
|
/** Takes stream already sorted by `x` and finishes sorting it by (`x`, `y`).
|
|
|
|
* During sorting only blocks with rows that equal by `x` saved in RAM.
|
|
|
|
* */
|
2019-01-23 14:48:50 +00:00
|
|
|
class FinishSortingBlockInputStream : public IBlockInputStream
|
2018-10-19 12:02:31 +00:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
/// limit - if not 0, allowed to return just first 'limit' rows in sorted order.
|
|
|
|
FinishSortingBlockInputStream(const BlockInputStreamPtr & input, const SortDescription & description_sorted_,
|
|
|
|
const SortDescription & description_to_sort_,
|
2019-02-10 15:17:45 +00:00
|
|
|
size_t max_merged_block_size_, UInt64 limit_);
|
2018-10-19 12:02:31 +00:00
|
|
|
|
|
|
|
String getName() const override { return "FinishSorting"; }
|
|
|
|
|
|
|
|
bool isSortedOutput() const override { return true; }
|
|
|
|
const SortDescription & getSortDescription() const override { return description_to_sort; }
|
|
|
|
|
|
|
|
Block getHeader() const override { return header; }
|
|
|
|
|
|
|
|
protected:
|
|
|
|
Block readImpl() override;
|
|
|
|
|
|
|
|
private:
|
|
|
|
SortDescription description_sorted;
|
|
|
|
SortDescription description_to_sort;
|
|
|
|
size_t max_merged_block_size;
|
2019-02-10 15:17:45 +00:00
|
|
|
UInt64 limit;
|
2018-10-19 12:02:31 +00:00
|
|
|
|
|
|
|
Block tail_block;
|
|
|
|
Blocks blocks;
|
|
|
|
|
|
|
|
std::unique_ptr<IBlockInputStream> impl;
|
|
|
|
|
|
|
|
/// Before operation, will remove constant columns from blocks. And after, place constant columns back.
|
|
|
|
/// to avoid excessive virtual function calls
|
|
|
|
/// Save original block structure here.
|
|
|
|
Block header;
|
|
|
|
|
|
|
|
bool end_of_stream = false;
|
|
|
|
size_t total_rows_processed = 0;
|
|
|
|
};
|
2018-10-19 13:04:50 +00:00
|
|
|
}
|