1 | #pragma once |
---|---|
2 | #include <DataStreams/IBlockInputStream.h> |
3 | #include <Storages/MergeTree/MergeTreeData.h> |
4 | #include <Storages/MergeTree/MergeTreeReader.h> |
5 | #include <Storages/MergeTree/MarkRange.h> |
6 | #include <memory> |
7 | |
8 | namespace DB |
9 | { |
10 | |
11 | /// Lightweight (in terms of logic) stream for reading single part from MergeTree |
12 | class MergeTreeSequentialBlockInputStream : public IBlockInputStream |
13 | { |
14 | public: |
15 | MergeTreeSequentialBlockInputStream( |
16 | const MergeTreeData & storage_, |
17 | const MergeTreeData::DataPartPtr & data_part_, |
18 | Names columns_to_read_, |
19 | bool read_with_direct_io_, |
20 | bool take_column_types_from_storage, |
21 | bool quiet = false |
22 | ); |
23 | |
24 | ~MergeTreeSequentialBlockInputStream() override; |
25 | |
26 | String getName() const override { return "MergeTreeSequentialBlockInputStream"; } |
27 | |
28 | Block getHeader() const override; |
29 | |
30 | /// Closes readers and unlock part locks |
31 | void finish(); |
32 | |
33 | size_t getCurrentMark() const { return current_mark; } |
34 | |
35 | size_t getCurrentRow() const { return current_row; } |
36 | |
37 | protected: |
38 | Block readImpl() override; |
39 | |
40 | private: |
41 | |
42 | const MergeTreeData & storage; |
43 | |
44 | Block header; |
45 | |
46 | /// Data part will not be removed if the pointer owns it |
47 | MergeTreeData::DataPartPtr data_part; |
48 | |
49 | /// Forbids to change columns list of the part during reading |
50 | std::shared_lock<std::shared_mutex> part_columns_lock; |
51 | |
52 | /// Columns we have to read (each Block from read will contain them) |
53 | Names columns_to_read; |
54 | |
55 | /// Should read using direct IO |
56 | bool read_with_direct_io; |
57 | |
58 | Logger * log = &Logger::get("MergeTreeSequentialBlockInputStream"); |
59 | |
60 | std::shared_ptr<MarkCache> mark_cache; |
61 | using MergeTreeReaderPtr = std::unique_ptr<MergeTreeReader>; |
62 | MergeTreeReaderPtr reader; |
63 | |
64 | /// current mark at which we stop reading |
65 | size_t current_mark = 0; |
66 | |
67 | /// current row at which we stop reading |
68 | size_t current_row = 0; |
69 | |
70 | private: |
71 | void fixHeader(Block & header_block) const; |
72 | |
73 | }; |
74 | |
75 | } |
76 |