2019-03-26 18:28:37 +00:00
|
|
|
#pragma once
|
|
|
|
#include <Processors/Formats/IOutputFormat.h>
|
|
|
|
#include <Common/ConcurrentBoundedQueue.h>
|
|
|
|
#include <DataStreams/BlockStreamProfileInfo.h>
|
2019-04-05 10:52:07 +00:00
|
|
|
#include <IO/WriteBuffer.h>
|
2019-03-26 18:28:37 +00:00
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
2020-01-26 07:52:34 +00:00
|
|
|
/// LazyOutputFormat is used to retrieve ready data from executing pipeline.
|
2020-05-15 19:30:41 +00:00
|
|
|
/// You can periodically call `getChunk` from separate thread.
|
2020-05-20 18:53:18 +00:00
|
|
|
/// Used in PullingAsyncPipelineExecutor.
|
2019-03-26 18:28:37 +00:00
|
|
|
class LazyOutputFormat : public IOutputFormat
|
|
|
|
{
|
|
|
|
|
|
|
|
public:
|
2019-06-18 08:25:27 +00:00
|
|
|
explicit LazyOutputFormat(const Block & header)
|
2019-07-09 12:26:22 +00:00
|
|
|
: IOutputFormat(header, out), queue(2), finished_processing(false) {}
|
2019-03-26 18:28:37 +00:00
|
|
|
|
2019-04-05 10:52:07 +00:00
|
|
|
String getName() const override { return "LazyOutputFormat"; }
|
|
|
|
|
2020-05-14 21:03:38 +00:00
|
|
|
Chunk getChunk(UInt64 milliseconds = 0);
|
|
|
|
Chunk getTotals();
|
|
|
|
Chunk getExtremes();
|
2019-03-26 18:28:37 +00:00
|
|
|
|
2020-01-23 14:58:50 +00:00
|
|
|
bool isFinished() { return finished_processing && queue.size() == 0; }
|
2019-03-26 18:28:37 +00:00
|
|
|
|
|
|
|
BlockStreamProfileInfo & getProfileInfo() { return info; }
|
|
|
|
|
2019-04-08 14:55:20 +00:00
|
|
|
void setRowsBeforeLimit(size_t rows_before_limit) override;
|
|
|
|
|
2020-01-23 10:04:18 +00:00
|
|
|
void finish()
|
|
|
|
{
|
|
|
|
finished_processing = true;
|
|
|
|
/// Clear queue in case if somebody is waiting lazy_format to push.
|
|
|
|
queue.clear();
|
|
|
|
}
|
2019-07-08 10:14:36 +00:00
|
|
|
|
2021-02-24 21:27:47 +00:00
|
|
|
void finalize() override
|
|
|
|
{
|
|
|
|
finished_processing = true;
|
|
|
|
|
|
|
|
/// In case we are waiting for result.
|
|
|
|
queue.emplace(Chunk());
|
|
|
|
}
|
2021-02-24 14:10:35 +00:00
|
|
|
|
2019-03-26 18:28:37 +00:00
|
|
|
protected:
|
2021-01-03 18:51:57 +00:00
|
|
|
void consume(Chunk chunk) override
|
2019-07-08 10:14:36 +00:00
|
|
|
{
|
|
|
|
if (!finished_processing)
|
2021-01-03 18:51:57 +00:00
|
|
|
queue.emplace(std::move(chunk));
|
2019-07-08 10:14:36 +00:00
|
|
|
}
|
|
|
|
|
2021-01-03 18:51:57 +00:00
|
|
|
void consumeTotals(Chunk chunk) override { totals = std::move(chunk); }
|
|
|
|
void consumeExtremes(Chunk chunk) override { extremes = std::move(chunk); }
|
2019-03-26 18:28:37 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
|
2021-01-03 18:51:57 +00:00
|
|
|
ConcurrentBoundedQueue<Chunk> queue;
|
|
|
|
Chunk totals;
|
|
|
|
Chunk extremes;
|
2019-03-26 18:28:37 +00:00
|
|
|
|
2019-04-05 10:52:07 +00:00
|
|
|
/// Is not used.
|
|
|
|
static WriteBuffer out;
|
|
|
|
|
2019-03-26 18:28:37 +00:00
|
|
|
BlockStreamProfileInfo info;
|
|
|
|
|
2019-04-05 11:43:28 +00:00
|
|
|
std::atomic<bool> finished_processing;
|
2019-03-26 18:28:37 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|