blob: 9cf609ed2d7ce0f15aa3f2221303493daf31fe8e (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
|
#pragma once
#include <Processors/Formats/IOutputFormat.h>
#include <Common/ConcurrentBoundedQueue.h>
#include <QueryPipeline/ProfileInfo.h>
#include <IO/WriteBuffer.h>
namespace DB
{
/// LazyOutputFormat is used to retrieve ready data from executing pipeline.
/// You can periodically call `getChunk` from separate thread.
/// Used in PullingAsyncPipelineExecutor.
class LazyOutputFormat : public IOutputFormat
{
public:
explicit LazyOutputFormat(const Block & header)
: IOutputFormat(header, out), queue(2) {}
String getName() const override { return "LazyOutputFormat"; }
Chunk getChunk(UInt64 milliseconds = 0);
Chunk getTotals();
Chunk getExtremes();
bool isFinished() { return queue.isFinishedAndEmpty(); }
ProfileInfo & getProfileInfo() { return info; }
void setRowsBeforeLimit(size_t rows_before_limit) override;
void onCancel() override
{
queue.clearAndFinish();
}
void finalizeImpl() override
{
queue.finish();
}
bool expectMaterializedColumns() const override { return false; }
protected:
void consume(Chunk chunk) override
{
(void)(queue.emplace(std::move(chunk)));
}
void consumeTotals(Chunk chunk) override { totals = std::move(chunk); }
void consumeExtremes(Chunk chunk) override { extremes = std::move(chunk); }
private:
ConcurrentBoundedQueue<Chunk> queue;
Chunk totals;
Chunk extremes;
/// Is not used.
static WriteBufferFromPointer out;
ProfileInfo info;
};
}
|