be/src/format/table/transactional_hive_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 <cstddef> |
21 | | #include <cstdint> |
22 | | #include <string> |
23 | | #include <unordered_map> |
24 | | #include <unordered_set> |
25 | | #include <vector> |
26 | | |
27 | | #include "common/factory_creator.h" |
28 | | #include "common/status.h" |
29 | | #include "exec/common/hash_table/phmap_fwd_decl.h" |
30 | | #include "format/table/table_format_reader.h" |
31 | | #include "storage/olap_scan_common.h" |
32 | | |
33 | | namespace doris { |
34 | | #include "common/compile_check_begin.h" |
35 | | class RuntimeState; |
36 | | class SlotDescriptor; |
37 | | class TFileRangeDesc; |
38 | | class TFileScanRangeParams; |
39 | | |
40 | | namespace io { |
41 | | struct IOContext; |
42 | | } // namespace io |
43 | | |
44 | | class Block; |
45 | | class GenericReader; |
46 | | class ShardedKVCache; |
47 | | class VExprContext; |
48 | | |
49 | | class TransactionalHiveReader : public TableFormatReader, public TableSchemaChangeHelper { |
50 | | ENABLE_FACTORY_CREATOR(TransactionalHiveReader); |
51 | | |
52 | | public: |
53 | | struct AcidRowID { |
54 | | int64_t original_transaction; |
55 | | int64_t bucket; |
56 | | int64_t row_id; |
57 | | |
58 | | struct Hash { |
59 | 0 | size_t operator()(const AcidRowID& transactional_row_id) const { |
60 | 0 | size_t hash_value = 0; |
61 | 0 | hash_value ^= std::hash<int64_t> {}(transactional_row_id.original_transaction) + |
62 | 0 | 0x9e3779b9 + (hash_value << 6) + (hash_value >> 2); |
63 | 0 | hash_value ^= std::hash<int64_t> {}(transactional_row_id.bucket) + 0x9e3779b9 + |
64 | 0 | (hash_value << 6) + (hash_value >> 2); |
65 | 0 | hash_value ^= std::hash<int64_t> {}(transactional_row_id.row_id) + 0x9e3779b9 + |
66 | 0 | (hash_value << 6) + (hash_value >> 2); |
67 | 0 | return hash_value; |
68 | 0 | } |
69 | | }; |
70 | | |
71 | | struct Eq { |
72 | 0 | bool operator()(const AcidRowID& lhs, const AcidRowID& rhs) const { |
73 | 0 | return lhs.original_transaction == rhs.original_transaction && |
74 | 0 | lhs.bucket == rhs.bucket && lhs.row_id == rhs.row_id; |
75 | 0 | } |
76 | | }; |
77 | | }; |
78 | | |
79 | | using AcidRowIDSet = flat_hash_set<AcidRowID, AcidRowID::Hash, AcidRowID::Eq>; |
80 | | |
81 | | TransactionalHiveReader(std::unique_ptr<GenericReader> file_format_reader, |
82 | | RuntimeProfile* profile, RuntimeState* state, |
83 | | const TFileScanRangeParams& params, const TFileRangeDesc& range, |
84 | | io::IOContext* io_ctx, FileMetaCache* meta_cache); |
85 | 0 | ~TransactionalHiveReader() override = default; |
86 | | |
87 | | Status init_row_filters() final; |
88 | | |
89 | | Status get_next_block_inner(Block* block, size_t* read_rows, bool* eof) final; |
90 | | |
91 | | Status init_reader( |
92 | | const std::vector<std::string>& column_names, |
93 | | std::unordered_map<std::string, uint32_t>* col_name_to_block_idx, |
94 | | const VExprContextSPtrs& conjuncts, const TupleDescriptor* tuple_descriptor, |
95 | | const RowDescriptor* row_descriptor, |
96 | | const VExprContextSPtrs* not_single_slot_filter_conjuncts, |
97 | | const std::unordered_map<int, VExprContextSPtrs>* slot_id_to_filter_conjuncts); |
98 | | |
99 | | private: |
100 | | struct TransactionalHiveProfile { |
101 | | RuntimeProfile::Counter* num_delete_files = nullptr; |
102 | | RuntimeProfile::Counter* num_delete_rows = nullptr; |
103 | | RuntimeProfile::Counter* delete_files_read_time = nullptr; |
104 | | }; |
105 | | |
106 | | TransactionalHiveProfile _transactional_orc_profile; |
107 | | AcidRowIDSet _delete_rows; |
108 | | std::unique_ptr<IColumn::Filter> _delete_rows_filter_ptr; |
109 | | std::vector<std::string> _col_names; |
110 | | // Column name to block index map, passed from FileScanner |
111 | | std::unordered_map<std::string, uint32_t>* _col_name_to_block_idx = nullptr; |
112 | | }; |
113 | | |
114 | | inline bool operator<(const TransactionalHiveReader::AcidRowID& lhs, |
115 | 0 | const TransactionalHiveReader::AcidRowID& rhs) { |
116 | 0 | if (lhs.original_transaction != rhs.original_transaction) { |
117 | 0 | return lhs.original_transaction < rhs.original_transaction; |
118 | 0 | } else if (lhs.bucket != rhs.bucket) { |
119 | 0 | return lhs.bucket < rhs.bucket; |
120 | 0 | } else if (lhs.row_id != rhs.row_id) { |
121 | 0 | return lhs.row_id < rhs.row_id; |
122 | 0 | } else { |
123 | 0 | return false; |
124 | 0 | } |
125 | 0 | } |
126 | | |
127 | | #include "common/compile_check_end.h" |
128 | | } // namespace doris |