be/src/exec/spill/spill_reader.h
Line | Count | Source |
1 | | // Licensed to the Apache Software Foundation (ASF) under one |
2 | | // or more contributor license agreements. See the NOTICE file |
3 | | // distributed with this work for additional information |
4 | | // regarding copyright ownership. The ASF licenses this file |
5 | | // to you under the Apache License, Version 2.0 (the |
6 | | // "License"); you may not use this file except in compliance |
7 | | // with the License. You may obtain a copy of the License at |
8 | | // |
9 | | // http://www.apache.org/licenses/LICENSE-2.0 |
10 | | // |
11 | | // Unless required by applicable law or agreed to in writing, |
12 | | // software distributed under the License is distributed on an |
13 | | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
14 | | // KIND, either express or implied. See the License for the |
15 | | // specific language governing permissions and limitations |
16 | | // under the License. |
17 | | |
18 | | #pragma once |
19 | | |
20 | | #include <gen_cpp/data.pb.h> |
21 | | |
22 | | #include <memory> |
23 | | #include <string> |
24 | | #include <vector> |
25 | | |
26 | | #include "common/status.h" |
27 | | #include "core/pod_array.h" |
28 | | #include "core/pod_array_fwd.h" |
29 | | #include "io/fs/file_reader_writer_fwd.h" |
30 | | #include "runtime/runtime_profile.h" |
31 | | #include "runtime/workload_management/resource_context.h" |
32 | | |
33 | | namespace doris { |
34 | | #include "common/compile_check_begin.h" |
35 | | class Block; |
36 | | class SpillReader { |
37 | | public: |
38 | | SpillReader(std::shared_ptr<ResourceContext> resource_context, int64_t stream_id, |
39 | | std::string file_path) |
40 | 2.12k | : stream_id_(stream_id), |
41 | 2.12k | file_path_(std::move(file_path)), |
42 | 2.12k | _resource_ctx(std::move(resource_context)) {} |
43 | | |
44 | 2.10k | ~SpillReader() { (void)close(); } |
45 | | |
46 | | Status open(); |
47 | | |
48 | | Status close(); |
49 | | |
50 | | Status read(Block* block, bool* eos); |
51 | | |
52 | | void seek(size_t block_index); |
53 | | |
54 | 0 | int64_t get_id() const { return stream_id_; } |
55 | | |
56 | 0 | std::string get_path() const { return file_path_; } |
57 | | |
58 | 0 | size_t block_count() const { return block_count_; } |
59 | | |
60 | 2.02k | void set_counters(RuntimeProfile* operator_profile) { |
61 | 2.02k | RuntimeProfile* custom_profile = operator_profile->get_child("CustomCounters"); |
62 | | DCHECK(custom_profile != nullptr); |
63 | 2.02k | _read_file_timer = custom_profile->get_counter("SpillReadFileTime"); |
64 | 2.02k | _deserialize_timer = custom_profile->get_counter("SpillReadDeserializeBlockTime"); |
65 | 2.02k | _read_block_count = custom_profile->get_counter("SpillReadBlockCount"); |
66 | 2.02k | _read_block_data_size = custom_profile->get_counter("SpillReadBlockBytes"); |
67 | 2.02k | _read_file_size = custom_profile->get_counter("SpillReadFileBytes"); |
68 | 2.02k | _read_rows_count = custom_profile->get_counter("SpillReadRows"); |
69 | 2.02k | _read_file_count = custom_profile->get_counter("SpillReadFileCount"); |
70 | 2.02k | } |
71 | | |
72 | | private: |
73 | | int64_t stream_id_; |
74 | | std::string file_path_; |
75 | | io::FileReaderSPtr file_reader_; |
76 | | |
77 | | size_t block_count_ = 0; |
78 | | size_t read_block_index_ = 0; |
79 | | size_t max_sub_block_size_ = 0; |
80 | | PaddedPODArray<char> read_buff_; |
81 | | std::vector<size_t> block_start_offsets_; |
82 | | |
83 | | PBlock pb_block_; |
84 | | |
85 | | RuntimeProfile::Counter* _read_file_timer = nullptr; |
86 | | RuntimeProfile::Counter* _deserialize_timer = nullptr; |
87 | | RuntimeProfile::Counter* _read_block_count = nullptr; |
88 | | RuntimeProfile::Counter* _read_block_data_size = nullptr; |
89 | | RuntimeProfile::Counter* _read_file_size = nullptr; |
90 | | RuntimeProfile::Counter* _read_rows_count = nullptr; |
91 | | RuntimeProfile::Counter* _read_file_count = nullptr; |
92 | | |
93 | | std::shared_ptr<ResourceContext> _resource_ctx = nullptr; |
94 | | }; |
95 | | |
96 | | using SpillReaderUPtr = std::unique_ptr<SpillReader>; |
97 | | |
98 | | } // namespace doris |
99 | | #include "common/compile_check_end.h" |