be/src/format/generic_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 "common/status.h" |
23 | | #include "exprs/vexpr_fwd.h" |
24 | | #include "runtime/descriptors.h" |
25 | | #include "storage/predicate/block_column_predicate.h" |
26 | | #include "util/profile_collector.h" |
27 | | |
28 | | namespace doris { |
29 | | class ColumnPredicate; |
30 | | } // namespace doris |
31 | | |
32 | | namespace doris { |
33 | | #include "common/compile_check_begin.h" |
34 | | |
35 | | class Block; |
36 | | class VSlotRef; |
37 | | // This a reader interface for all file readers. |
38 | | // A GenericReader is responsible for reading a file and return |
39 | | // a set of blocks with specified schema, |
40 | | class GenericReader : public ProfileCollector { |
41 | | public: |
42 | 3.48k | GenericReader() : _push_down_agg_type(TPushAggOp::type::NONE) {} |
43 | 2.87k | void set_push_down_agg_type(TPushAggOp::type push_down_agg_type) { |
44 | 2.87k | _push_down_agg_type = push_down_agg_type; |
45 | 2.87k | } |
46 | | |
47 | | virtual Status get_next_block(Block* block, size_t* read_rows, bool* eof) = 0; |
48 | | |
49 | | // Type is always nullable to process illegal values. |
50 | | virtual Status get_columns(std::unordered_map<std::string, DataTypePtr>* name_to_type, |
51 | 0 | std::unordered_set<std::string>* missing_cols) { |
52 | 0 | return Status::NotSupported("get_columns is not implemented"); |
53 | 0 | } |
54 | | |
55 | | // This method is responsible for initializing the resource for parsing schema. |
56 | | // It will be called before `get_parsed_schema`. |
57 | 0 | virtual Status init_schema_reader() { |
58 | 0 | return Status::NotSupported("init_schema_reader is not implemented for this reader."); |
59 | 0 | } |
60 | | // `col_types` is always nullable to process illegal values. |
61 | | virtual Status get_parsed_schema(std::vector<std::string>* col_names, |
62 | 0 | std::vector<DataTypePtr>* col_types) { |
63 | 0 | return Status::NotSupported("get_parsed_schema is not implemented for this reader."); |
64 | 0 | } |
65 | 3.48k | ~GenericReader() override = default; |
66 | | |
67 | | /// If the underlying FileReader has filled the partition&missing columns, |
68 | | /// The FileScanner does not need to fill |
69 | 5.85k | virtual bool fill_all_columns() const { return _fill_all_columns; } |
70 | | |
71 | | /// Tell the underlying FileReader the partition&missing columns, |
72 | | /// and the FileReader determine to fill columns or not. |
73 | | /// Should set _fill_all_columns = true, if fill the columns. |
74 | | virtual Status set_fill_columns( |
75 | | const std::unordered_map<std::string, std::tuple<std::string, const SlotDescriptor*>>& |
76 | | partition_columns, |
77 | 2.46k | const std::unordered_map<std::string, VExprContextSPtr>& missing_columns) { |
78 | 2.46k | return Status::OK(); |
79 | 2.46k | } |
80 | | |
81 | 565 | virtual Status close() { return Status::OK(); } |
82 | | |
83 | 52 | Status read_by_rows(const std::list<int64_t>& row_ids) { |
84 | 52 | _read_by_rows = true; |
85 | 52 | _row_ids = row_ids; |
86 | 52 | return _set_read_one_line_impl(); |
87 | 52 | } |
88 | | |
89 | | /// The reader is responsible for counting the number of rows read, |
90 | | /// because some readers, such as parquet/orc, |
91 | | /// can skip some pages/rowgroups through indexes. |
92 | 5.54k | virtual bool count_read_rows() { return false; } |
93 | | |
94 | | protected: |
95 | 0 | virtual Status _set_read_one_line_impl() { |
96 | 0 | return Status::NotSupported("read_by_rows is not implemented for this reader."); |
97 | 0 | } |
98 | | |
99 | | const size_t _MIN_BATCH_SIZE = 4064; // 4094 - 32(padding) |
100 | | |
101 | | /// Whether the underlying FileReader has filled the partition&missing columns |
102 | | bool _fill_all_columns = false; |
103 | | TPushAggOp::type _push_down_agg_type {}; |
104 | | |
105 | | // For TopN queries, rows will be read according to row ids produced by TopN result. |
106 | | bool _read_by_rows = false; |
107 | | std::list<int64_t> _row_ids; |
108 | | |
109 | | // Cache to save some common part such as file footer. |
110 | | // Maybe null if not used |
111 | | FileMetaCache* _meta_cache = nullptr; |
112 | | }; |
113 | | |
114 | | #include "common/compile_check_end.h" |
115 | | } // namespace doris |