Repository navigation
Expand file tree
/
Copy pathBufferChunksTransform.cpp
More file actions
103 lines (87 loc) · 2.43 KB
/
Copy pathBufferChunksTransform.cpp
File metadata and controls
103 lines (87 loc) · 2.43 KB
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#include <Processors/QueryPlan/BufferChunksTransform.h>
#include <Processors/Merges/Algorithms/MergeTreeReadInfo.h>
#include <Processors/Port.h>
namespace DB
{
BufferChunksTransform::BufferChunksTransform(
SharedHeader header_,
size_t max_rows_to_buffer_,
size_t max_bytes_to_buffer_,
size_t limit_)
: IProcessor({header_}, {header_})
, input(inputs.front())
, output(outputs.front())
, max_rows_to_buffer(max_rows_to_buffer_)
, max_bytes_to_buffer(max_bytes_to_buffer_)
, limit(limit_)
{
}
IProcessor::Status BufferChunksTransform::prepare()
{
if (output.isFinished())
{
chunks = {};
input.close();
return Status::Finished;
}
if (input.isFinished() && chunks.empty())
{
output.finish();
return Status::Finished;
}
if (output.canPush())
{
input.setNeeded();
if (!chunks.empty())
{
auto chunk = std::move(chunks.front());
chunks.pop();
num_buffered_rows -= chunk.getNumRows();
num_buffered_bytes -= chunk.bytes();
output.push(std::move(chunk));
}
else if (input.hasData())
{
bool virtual_row;
auto chunk = pullChunk(virtual_row);
output.push(std::move(chunk));
if (virtual_row)
{
input.setNotNeeded();
return Status::PortFull;
}
}
}
if (input.hasData() && (num_buffered_rows < max_rows_to_buffer || num_buffered_bytes < max_bytes_to_buffer))
{
bool virtual_row;
auto chunk = pullChunk(virtual_row);
if (virtual_row)
{
output.push(std::move(chunk));
input.setNotNeeded();
return Status::PortFull;
}
num_buffered_rows += chunk.getNumRows();
num_buffered_bytes += chunk.bytes();
chunks.push(std::move(chunk));
}
if (num_buffered_rows >= max_rows_to_buffer && num_buffered_bytes >= max_bytes_to_buffer)
{
input.setNotNeeded();
return Status::PortFull;
}
input.setNeeded();
return Status::NeedData;
}
Chunk BufferChunksTransform::pullChunk(bool & virtual_row)
{
auto chunk = input.pull();
virtual_row = isVirtualRow(chunk);
if (!virtual_row)
num_processed_rows += chunk.getNumRows();
if (limit && num_processed_rows >= limit)
input.close();
return chunk;
}
}