be/src/format/native/native_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/PlanNodes_types.h> |
21 | | |
22 | | #include <cstddef> |
23 | | #include <string> |
24 | | #include <unordered_map> |
25 | | #include <unordered_set> |
26 | | |
27 | | #include "common/status.h" |
28 | | #include "format/generic_reader.h" |
29 | | #include "io/fs/file_reader_writer_fwd.h" |
30 | | |
31 | | namespace doris { |
32 | | class RuntimeProfile; |
33 | | class RuntimeState; |
34 | | |
35 | | namespace io { |
36 | | struct IOContext; |
37 | | } // namespace io |
38 | | } // namespace doris |
39 | | |
40 | | namespace doris { |
41 | | class Block; |
42 | | |
43 | | #include "common/compile_check_begin.h" |
44 | | |
45 | | // Doris Native format reader. |
46 | | // it will read a sequence of Blocks encoded in Doris Native binary format. |
47 | | // |
48 | | // NOTE: current implementation is just a skeleton and will be filled step by step. |
49 | | class NativeReader : public GenericReader { |
50 | | public: |
51 | | ENABLE_FACTORY_CREATOR(NativeReader); |
52 | | |
53 | | NativeReader(RuntimeProfile* profile, const TFileScanRangeParams& params, |
54 | | const TFileRangeDesc& range, io::IOContext* io_ctx, RuntimeState* state); |
55 | | |
56 | | ~NativeReader() override; |
57 | | |
58 | | // Initialize underlying file reader and any format specific state. |
59 | | Status init_reader(); |
60 | | |
61 | | Status get_next_block(Block* block, size_t* read_rows, bool* eof) override; |
62 | | |
63 | | Status get_columns(std::unordered_map<std::string, DataTypePtr>* name_to_type, |
64 | | std::unordered_set<std::string>* missing_cols) override; |
65 | | |
66 | | Status init_schema_reader() override; |
67 | | |
68 | | Status get_parsed_schema(std::vector<std::string>* col_names, |
69 | | std::vector<DataTypePtr>* col_types) override; |
70 | | |
71 | | Status close() override; |
72 | | |
73 | 8 | bool count_read_rows() override { return true; } |
74 | | |
75 | | protected: |
76 | 3 | void _collect_profile_before_close() override {} |
77 | | |
78 | | private: |
79 | | RuntimeProfile* _profile = nullptr; |
80 | | const TFileScanRangeParams& _scan_params; |
81 | | const TFileRangeDesc& _scan_range; |
82 | | |
83 | | io::FileReaderSPtr _file_reader; |
84 | | io::IOContext* _io_ctx = nullptr; |
85 | | RuntimeState* _state = nullptr; |
86 | | |
87 | | bool _eof = false; |
88 | | |
89 | | // Current read offset in the underlying file. |
90 | | int64_t _current_offset = 0; |
91 | | int64_t _file_size = 0; |
92 | | |
93 | | // Cached schema information from the first PBlock. |
94 | | bool _schema_inited = false; |
95 | | std::vector<std::string> _schema_col_names; |
96 | | std::vector<DataTypePtr> _schema_col_types; |
97 | | |
98 | | // Cached first block (serialized) to allow schema probing before data scan. |
99 | | std::string _first_block_buf; |
100 | | bool _first_block_loaded = false; |
101 | | bool _first_block_consumed = false; |
102 | | |
103 | | Status _read_next_pblock(std::string* buff, bool* eof); |
104 | | Status _init_schema_from_pblock(const PBlock& pblock); |
105 | | }; |
106 | | |
107 | | #include "common/compile_check_end.h" |
108 | | } // namespace doris |