blob: 05d8e2aeac89d5ffb57921ff1906a4c2415a3950 (
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
|
#pragma once
#include <IO/Progress.h>
#include <Processors/Transforms/ExceptionKeepingTransform.h>
#include <Access/EnabledQuota.h>
namespace DB
{
class QueryStatus;
using QueryStatusPtr = std::shared_ptr<QueryStatus>;
class ThreadStatus;
/// Proxy class which counts number of written block, rows, bytes
class CountingTransform final : public ExceptionKeepingTransform
{
public:
explicit CountingTransform(
const Block & header,
ThreadStatus * thread_status_ = nullptr,
std::shared_ptr<const EnabledQuota> quota_ = nullptr)
: ExceptionKeepingTransform(header, header)
, thread_status(thread_status_), quota(std::move(quota_)) {}
String getName() const override { return "CountingTransform"; }
void setProgressCallback(const ProgressCallback & callback)
{
progress_callback = callback;
}
void setProcessListElement(QueryStatusPtr elem)
{
process_elem = elem;
}
const Progress & getProgress() const
{
return progress;
}
void onConsume(Chunk chunk) override;
GenerateResult onGenerate() override
{
GenerateResult res;
res.chunk = std::move(cur_chunk);
return res;
}
protected:
Progress progress;
ProgressCallback progress_callback;
QueryStatusPtr process_elem;
ThreadStatus * thread_status = nullptr;
/// Quota is used to limit amount of written bytes.
std::shared_ptr<const EnabledQuota> quota;
Chunk cur_chunk;
};
}
|