| 1 | #pragma once |
|---|---|
| 2 | |
| 3 | #include <DataStreams/IBlockStream_fwd.h> |
| 4 | |
| 5 | #include <functional> |
| 6 | |
| 7 | #include <Processors/QueryPipeline.h> |
| 8 | |
| 9 | |
| 10 | namespace DB |
| 11 | { |
| 12 | |
| 13 | class ProcessListEntry; |
| 14 | |
| 15 | struct BlockIO |
| 16 | { |
| 17 | BlockIO() = default; |
| 18 | BlockIO(const BlockIO &) = default; |
| 19 | ~BlockIO() = default; |
| 20 | |
| 21 | /** process_list_entry should be destroyed after in and after out, |
| 22 | * since in and out contain pointer to objects inside process_list_entry (query-level MemoryTracker for example), |
| 23 | * which could be used before destroying of in and out. |
| 24 | */ |
| 25 | std::shared_ptr<ProcessListEntry> process_list_entry; |
| 26 | |
| 27 | BlockOutputStreamPtr out; |
| 28 | BlockInputStreamPtr in; |
| 29 | |
| 30 | QueryPipeline pipeline; |
| 31 | |
| 32 | /// Callbacks for query logging could be set here. |
| 33 | std::function<void(IBlockInputStream *, IBlockOutputStream *)> finish_callback; |
| 34 | std::function<void()> exception_callback; |
| 35 | |
| 36 | /// When it is true, don't bother sending any non-empty blocks to the out stream |
| 37 | bool null_format = false; |
| 38 | |
| 39 | /// Call these functions if you want to log the request. |
| 40 | void onFinish() |
| 41 | { |
| 42 | if (finish_callback) |
| 43 | finish_callback(in.get(), out.get()); |
| 44 | } |
| 45 | |
| 46 | void onException() |
| 47 | { |
| 48 | if (exception_callback) |
| 49 | exception_callback(); |
| 50 | } |
| 51 | |
| 52 | BlockIO & operator= (const BlockIO & rhs) |
| 53 | { |
| 54 | if (this == &rhs) |
| 55 | return *this; |
| 56 | |
| 57 | out.reset(); |
| 58 | in.reset(); |
| 59 | process_list_entry.reset(); |
| 60 | |
| 61 | process_list_entry = rhs.process_list_entry; |
| 62 | in = rhs.in; |
| 63 | out = rhs.out; |
| 64 | pipeline = rhs.pipeline; |
| 65 | |
| 66 | finish_callback = rhs.finish_callback; |
| 67 | exception_callback = rhs.exception_callback; |
| 68 | |
| 69 | return *this; |
| 70 | } |
| 71 | }; |
| 72 | |
| 73 | } |
| 74 |