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 <utility> |
26 | | #include <vector> |
27 | | |
28 | | #include "common/status.h" |
29 | | #include "core/column/column_dictionary.h" |
30 | | #include "core/data_type/define_primitive_type.h" |
31 | | #include "core/data_type/primitive_type.h" |
32 | | #include "core/types.h" |
33 | | #include "format/orc/vorc_reader.h" |
34 | | #include "format/parquet/vparquet_reader.h" |
35 | | #include "format/table/iceberg_reader_mixin.h" |
36 | | #include "storage/olap_common.h" |
37 | | |
38 | | namespace tparquet { |
39 | | class KeyValue; |
40 | | class ColumnMetaData; |
41 | | } // namespace tparquet |
42 | | |
43 | | namespace doris { |
44 | | class RowDescriptor; |
45 | | class RuntimeState; |
46 | | class SlotDescriptor; |
47 | | class TFileRangeDesc; |
48 | | class TFileScanRangeParams; |
49 | | class TIcebergDeleteFileDesc; |
50 | | class TupleDescriptor; |
51 | | |
52 | | namespace io { |
53 | | struct IOContext; |
54 | | } // namespace io |
55 | | template <typename T> |
56 | | class ColumnStr; |
57 | | using ColumnString = ColumnStr<UInt32>; |
58 | | class Block; |
59 | | class GenericReader; |
60 | | class ShardedKVCache; |
61 | | class VExprContext; |
62 | | |
63 | | struct IcebergTableReader { |
64 | | static bool _is_fully_dictionary_encoded(const tparquet::ColumnMetaData& column_metadata); |
65 | | }; |
66 | | |
67 | | // IcebergParquetReader: inherits ParquetReader via IcebergReaderMixin CRTP |
68 | | class IcebergParquetReader final : public IcebergReaderMixin<ParquetReader> { |
69 | | public: |
70 | | ENABLE_FACTORY_CREATOR(IcebergParquetReader); |
71 | | |
72 | | IcebergParquetReader(ShardedKVCache* kv_cache, RuntimeProfile* profile, |
73 | | const TFileScanRangeParams& params, const TFileRangeDesc& range, |
74 | | size_t batch_size, const cctz::time_zone* ctz, io::IOContext* io_ctx, |
75 | | RuntimeState* state, FileMetaCache* meta_cache) |
76 | 7 | : IcebergReaderMixin<ParquetReader>(kv_cache, profile, params, range, batch_size, ctz, |
77 | 7 | io_ctx, state, meta_cache) {} |
78 | | |
79 | | IcebergParquetReader(ShardedKVCache* kv_cache, RuntimeProfile* profile, |
80 | | const TFileScanRangeParams& params, const TFileRangeDesc& range, |
81 | | size_t batch_size, const cctz::time_zone* ctz, |
82 | | std::shared_ptr<io::IOContext> io_ctx_holder, RuntimeState* state, |
83 | | FileMetaCache* meta_cache) |
84 | 0 | : IcebergReaderMixin<ParquetReader>(kv_cache, profile, params, range, batch_size, ctz, |
85 | 0 | std::move(io_ctx_holder), state, meta_cache) {} |
86 | | |
87 | 0 | void set_delete_rows() final { |
88 | | // Call ParquetReader's set_delete_rows(const vector<int64_t>*) |
89 | 0 | ParquetReader::set_delete_rows(_iceberg_delete_rows); |
90 | 0 | } |
91 | | |
92 | | protected: |
93 | | // Parquet-specific schema matching via on_before_init_reader hook |
94 | | Status on_before_init_reader(ReaderInitContext* ctx) override; |
95 | | |
96 | | std::unique_ptr<GenericReader> _create_equality_reader( |
97 | 0 | const TFileRangeDesc& delete_desc) final { |
98 | 0 | auto reader = ParquetReader::create_unique( |
99 | 0 | this->get_profile(), this->get_scan_params(), delete_desc, |
100 | 0 | READ_DELETE_FILE_BATCH_SIZE, &this->get_state()->timezone_obj(), this->get_io_ctx(), |
101 | 0 | this->get_state(), this->_meta_cache); |
102 | 0 | reader->set_enable_file_meta_memory_cache(this->_enable_file_meta_memory_cache); |
103 | 0 | return reader; |
104 | 0 | } |
105 | | |
106 | | static ColumnIdResult _create_column_ids(const FieldDescriptor* field_desc, |
107 | | const TupleDescriptor* tuple_descriptor); |
108 | | |
109 | | private: |
110 | | Status _read_position_delete_file(const TFileRangeDesc* delete_range, |
111 | | DeleteFile* position_delete) final; |
112 | | }; |
113 | | |
114 | | // IcebergOrcReader: inherits OrcReader via IcebergReaderMixin CRTP |
115 | | class IcebergOrcReader final : public IcebergReaderMixin<OrcReader> { |
116 | | public: |
117 | | ENABLE_FACTORY_CREATOR(IcebergOrcReader); |
118 | | |
119 | | IcebergOrcReader(ShardedKVCache* kv_cache, RuntimeProfile* profile, RuntimeState* state, |
120 | | const TFileScanRangeParams& params, const TFileRangeDesc& range, |
121 | | size_t batch_size, const std::string& ctz, io::IOContext* io_ctx, |
122 | | FileMetaCache* meta_cache) |
123 | 7 | : IcebergReaderMixin<OrcReader>(kv_cache, profile, state, params, range, batch_size, |
124 | 7 | ctz, io_ctx, meta_cache) {} |
125 | | |
126 | | IcebergOrcReader(ShardedKVCache* kv_cache, RuntimeProfile* profile, RuntimeState* state, |
127 | | const TFileScanRangeParams& params, const TFileRangeDesc& range, |
128 | | size_t batch_size, const std::string& ctz, |
129 | | std::shared_ptr<io::IOContext> io_ctx_holder, FileMetaCache* meta_cache) |
130 | 0 | : IcebergReaderMixin<OrcReader>(kv_cache, profile, state, params, range, batch_size, |
131 | 0 | ctz, std::move(io_ctx_holder), meta_cache) {} |
132 | | |
133 | 0 | void set_delete_rows() final { |
134 | | // Call OrcReader's set_position_delete_rowids |
135 | 0 | this->set_position_delete_rowids(_iceberg_delete_rows); |
136 | 0 | } |
137 | | |
138 | | protected: |
139 | | // ORC-specific schema matching via on_before_init_reader hook |
140 | | Status on_before_init_reader(ReaderInitContext* ctx) override; |
141 | | |
142 | | std::unique_ptr<GenericReader> _create_equality_reader( |
143 | 0 | const TFileRangeDesc& delete_desc) override { |
144 | 0 | auto reader = OrcReader::create_unique( |
145 | 0 | this->get_profile(), this->get_state(), this->get_scan_params(), delete_desc, |
146 | 0 | READ_DELETE_FILE_BATCH_SIZE, this->get_state()->timezone(), this->get_io_ctx(), |
147 | 0 | this->_meta_cache); |
148 | 0 | reader->set_enable_file_meta_memory_cache(this->_enable_file_meta_memory_cache); |
149 | 0 | return reader; |
150 | 0 | } |
151 | | |
152 | | static ColumnIdResult _create_column_ids(const orc::Type* orc_type, |
153 | | const TupleDescriptor* tuple_descriptor); |
154 | | |
155 | | static const std::string ICEBERG_ORC_ATTRIBUTE; |
156 | | |
157 | | private: |
158 | | Status _read_position_delete_file(const TFileRangeDesc* delete_range, |
159 | | DeleteFile* position_delete) final; |
160 | | }; |
161 | | |
162 | | } // namespace doris |