ClickHouse/src/Processors/Formats/LazyOutputFormat.h

66 lines
1.5 KiB
C++
Raw Normal View History

2019-03-26 18:28:37 +00:00
#pragma once
#include <Processors/Formats/IOutputFormat.h>
#include <Common/ConcurrentBoundedQueue.h>
2021-10-15 20:18:20 +00:00
#include <QueryPipeline/ProfileInfo.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.
/// 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)
2021-10-06 11:02:40 +00:00
: IOutputFormat(header, out), queue(2) {}
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
2021-10-08 08:48:08 +00:00
bool isFinished() { return queue.isFinishedAndEmpty(); }
2019-03-26 18:28:37 +00:00
2021-10-15 20:18:20 +00:00
ProfileInfo & getProfileInfo() { return info; }
2019-03-26 18:28:37 +00:00
2019-04-08 14:55:20 +00:00
void setRowsBeforeLimit(size_t rows_before_limit) override;
void onCancel() override
2020-01-23 10:04:18 +00:00
{
2021-10-08 08:48:08 +00:00
queue.clearAndFinish();
2020-01-23 10:04:18 +00:00
}
2021-11-11 18:09:21 +00:00
void finalizeImpl() override
2021-02-24 21:27:47 +00:00
{
2021-10-06 11:02:40 +00:00
queue.finish();
2021-02-24 21:27:47 +00:00
}
2021-09-15 19:35:48 +00:00
bool expectMaterializedColumns() const override { return false; }
2019-03-26 18:28:37 +00:00
protected:
void consume(Chunk chunk) override
{
2021-10-08 08:48:08 +00:00
(void)(queue.emplace(std::move(chunk)));
}
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:
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;
2021-10-15 20:18:20 +00:00
ProfileInfo info;
2019-03-26 18:28:37 +00:00
};
}