be/src/format/parquet/vparquet_reader.cpp
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 | | #include "format/parquet/vparquet_reader.h" |
19 | | |
20 | | #include <gen_cpp/Metrics_types.h> |
21 | | #include <gen_cpp/PlanNodes_types.h> |
22 | | #include <gen_cpp/parquet_types.h> |
23 | | #include <glog/logging.h> |
24 | | |
25 | | #include <algorithm> |
26 | | #include <functional> |
27 | | #include <set> |
28 | | #include <unordered_map> |
29 | | #include <utility> |
30 | | |
31 | | #include "common/config.h" |
32 | | #include "common/status.h" |
33 | | #include "core/block/block.h" |
34 | | #include "core/block/column_with_type_and_name.h" |
35 | | #include "core/column/column.h" |
36 | | #include "core/data_type/define_primitive_type.h" |
37 | | #include "core/typeid_cast.h" |
38 | | #include "core/types.h" |
39 | | #include "exec/scan/file_scanner.h" |
40 | | #include "exprs/runtime_filter_expr.h" |
41 | | #include "exprs/vbloom_predicate.h" |
42 | | #include "exprs/vdirect_in_predicate.h" |
43 | | #include "exprs/vexpr.h" |
44 | | #include "exprs/vexpr_context.h" |
45 | | #include "exprs/vin_predicate.h" |
46 | | #include "exprs/vslot_ref.h" |
47 | | #include "exprs/vtopn_pred.h" |
48 | | #include "format/column_type_convert.h" |
49 | | #include "format/parquet/parquet_block_split_bloom_filter.h" |
50 | | #include "format/parquet/parquet_common.h" |
51 | | #include "format/parquet/parquet_predicate.h" |
52 | | #include "format/parquet/parquet_thrift_util.h" |
53 | | #include "format/parquet/schema_desc.h" |
54 | | #include "format/parquet/vparquet_file_metadata.h" |
55 | | #include "format/parquet/vparquet_group_reader.h" |
56 | | #include "format/parquet/vparquet_page_index.h" |
57 | | #include "information_schema/schema_scanner.h" |
58 | | #include "io/file_factory.h" |
59 | | #include "io/fs/buffered_reader.h" |
60 | | #include "io/fs/file_reader.h" |
61 | | #include "io/fs/file_reader_writer_fwd.h" |
62 | | #include "io/fs/tracing_file_reader.h" |
63 | | #include "runtime/descriptors.h" |
64 | | #include "storage/index/zone_map/zonemap_eval_context.h" |
65 | | #include "util/slice.h" |
66 | | #include "util/string_util.h" |
67 | | #include "util/timezone_utils.h" |
68 | | |
69 | | namespace cctz { |
70 | | class time_zone; |
71 | | } // namespace cctz |
72 | | namespace doris { |
73 | | class RowDescriptor; |
74 | | class RuntimeState; |
75 | | class SlotDescriptor; |
76 | | class TupleDescriptor; |
77 | | namespace io { |
78 | | struct IOContext; |
79 | | enum class FileCachePolicy : uint8_t; |
80 | | } // namespace io |
81 | | class Block; |
82 | | } // namespace doris |
83 | | |
84 | | namespace doris { |
85 | | |
86 | | ParquetReader::ParquetReader(RuntimeProfile* profile, const TFileScanRangeParams& params, |
87 | | const TFileRangeDesc& range, size_t batch_size, |
88 | | const cctz::time_zone* ctz, io::IOContext* io_ctx, RuntimeState* state, |
89 | | FileMetaCache* meta_cache, bool enable_lazy_mat) |
90 | 241 | : _profile(profile), |
91 | 241 | _scan_params(params), |
92 | 241 | _scan_range(range), |
93 | 241 | _batch_size(std::max(batch_size, 1UL)), |
94 | 241 | _range_start_offset(range.start_offset), |
95 | 241 | _range_size(range.size), |
96 | 241 | _ctz(ctz), |
97 | 241 | _io_ctx(io_ctx), |
98 | 241 | _state(state), |
99 | 241 | _enable_lazy_mat(enable_lazy_mat), |
100 | | _enable_filter_by_min_max( |
101 | 241 | state == nullptr ? true |
102 | 241 | : state->query_options().enable_parquet_filter_by_min_max), |
103 | | _enable_filter_by_bloom_filter( |
104 | 241 | state == nullptr ? true |
105 | 241 | : state->query_options().enable_parquet_filter_by_bloom_filter) { |
106 | 241 | _meta_cache = meta_cache; |
107 | 241 | _init_profile(); |
108 | 241 | _init_system_properties(); |
109 | 241 | _init_file_description(); |
110 | 241 | } |
111 | | |
112 | 147 | void ParquetReader::set_batch_size(size_t batch_size) { |
113 | 147 | if (_batch_size == batch_size) { |
114 | 4 | return; |
115 | 4 | } |
116 | 143 | _batch_size = batch_size; |
117 | 143 | } |
118 | | |
119 | | ParquetReader::ParquetReader(RuntimeProfile* profile, const TFileScanRangeParams& params, |
120 | | const TFileRangeDesc& range, size_t batch_size, |
121 | | const cctz::time_zone* ctz, |
122 | | std::shared_ptr<io::IOContext> io_ctx_holder, RuntimeState* state, |
123 | | FileMetaCache* meta_cache, bool enable_lazy_mat) |
124 | 0 | : _profile(profile), |
125 | 0 | _scan_params(params), |
126 | 0 | _scan_range(range), |
127 | 0 | _batch_size(std::max(batch_size, 1UL)), |
128 | 0 | _range_start_offset(range.start_offset), |
129 | 0 | _range_size(range.size), |
130 | 0 | _ctz(ctz), |
131 | 0 | _io_ctx(io_ctx_holder ? io_ctx_holder.get() : nullptr), |
132 | 0 | _io_ctx_holder(std::move(io_ctx_holder)), |
133 | 0 | _state(state), |
134 | 0 | _enable_lazy_mat(enable_lazy_mat), |
135 | | _enable_filter_by_min_max( |
136 | 0 | state == nullptr ? true |
137 | 0 | : state->query_options().enable_parquet_filter_by_min_max), |
138 | | _enable_filter_by_bloom_filter( |
139 | 0 | state == nullptr ? true |
140 | 0 | : state->query_options().enable_parquet_filter_by_bloom_filter) { |
141 | 0 | _meta_cache = meta_cache; |
142 | 0 | _init_profile(); |
143 | 0 | _init_system_properties(); |
144 | 0 | _init_file_description(); |
145 | 0 | } |
146 | | |
147 | | ParquetReader::ParquetReader(const TFileScanRangeParams& params, const TFileRangeDesc& range, |
148 | | io::IOContext* io_ctx, RuntimeState* state, FileMetaCache* meta_cache, |
149 | | bool enable_lazy_mat) |
150 | 5 | : _profile(nullptr), |
151 | 5 | _scan_params(params), |
152 | 5 | _scan_range(range), |
153 | 5 | _io_ctx(io_ctx), |
154 | 5 | _state(state), |
155 | 5 | _enable_lazy_mat(enable_lazy_mat), |
156 | | _enable_filter_by_min_max( |
157 | 5 | state == nullptr ? true |
158 | 5 | : state->query_options().enable_parquet_filter_by_min_max), |
159 | | _enable_filter_by_bloom_filter( |
160 | 5 | state == nullptr ? true |
161 | 5 | : state->query_options().enable_parquet_filter_by_bloom_filter) { |
162 | 5 | _meta_cache = meta_cache; |
163 | 5 | _init_system_properties(); |
164 | 5 | _init_file_description(); |
165 | 5 | } |
166 | | |
167 | | ParquetReader::ParquetReader(const TFileScanRangeParams& params, const TFileRangeDesc& range, |
168 | | std::shared_ptr<io::IOContext> io_ctx_holder, RuntimeState* state, |
169 | | FileMetaCache* meta_cache, bool enable_lazy_mat) |
170 | 113 | : _profile(nullptr), |
171 | 113 | _scan_params(params), |
172 | 113 | _scan_range(range), |
173 | 113 | _io_ctx(io_ctx_holder ? io_ctx_holder.get() : nullptr), |
174 | 113 | _io_ctx_holder(std::move(io_ctx_holder)), |
175 | 113 | _state(state), |
176 | 113 | _enable_lazy_mat(enable_lazy_mat), |
177 | | _enable_filter_by_min_max( |
178 | 113 | state == nullptr ? true |
179 | 113 | : state->query_options().enable_parquet_filter_by_min_max), |
180 | | _enable_filter_by_bloom_filter( |
181 | 113 | state == nullptr ? true |
182 | 113 | : state->query_options().enable_parquet_filter_by_bloom_filter) { |
183 | 113 | _meta_cache = meta_cache; |
184 | 113 | _init_system_properties(); |
185 | 113 | _init_file_description(); |
186 | 113 | } |
187 | | |
188 | 359 | ParquetReader::~ParquetReader() { |
189 | 359 | _close_internal(); |
190 | 359 | } |
191 | | |
192 | | #ifdef BE_TEST |
193 | | // for unit test |
194 | | void ParquetReader::set_file_reader(io::FileReaderSPtr file_reader) { |
195 | | _file_reader = file_reader; |
196 | | _tracing_file_reader = file_reader; |
197 | | } |
198 | | #endif |
199 | | |
200 | 241 | void ParquetReader::_init_profile() { |
201 | 241 | if (_profile != nullptr) { |
202 | 184 | static const char* parquet_profile = "ParquetReader"; |
203 | 184 | ADD_TIMER_WITH_LEVEL(_profile, parquet_profile, 1); |
204 | | |
205 | 184 | _parquet_profile.filtered_row_groups = ADD_CHILD_COUNTER_WITH_LEVEL( |
206 | 184 | _profile, "RowGroupsFiltered", TUnit::UNIT, parquet_profile, 1); |
207 | 184 | _parquet_profile.filtered_row_groups_by_min_max = ADD_CHILD_COUNTER_WITH_LEVEL( |
208 | 184 | _profile, "RowGroupsFilteredByMinMax", TUnit::UNIT, parquet_profile, 1); |
209 | 184 | _parquet_profile.filtered_row_groups_by_expr_zonemap = ADD_CHILD_COUNTER_WITH_LEVEL( |
210 | 184 | _profile, "ParquetExprZoneMapFilteredRowGroups", TUnit::UNIT, parquet_profile, 1); |
211 | 184 | _parquet_profile.filtered_row_groups_by_bloom_filter = ADD_CHILD_COUNTER_WITH_LEVEL( |
212 | 184 | _profile, "RowGroupsFilteredByBloomFilter", TUnit::UNIT, parquet_profile, 1); |
213 | 184 | _parquet_profile.to_read_row_groups = ADD_CHILD_COUNTER_WITH_LEVEL( |
214 | 184 | _profile, "RowGroupsReadNum", TUnit::UNIT, parquet_profile, 1); |
215 | 184 | _parquet_profile.total_row_groups = ADD_CHILD_COUNTER_WITH_LEVEL( |
216 | 184 | _profile, "RowGroupsTotalNum", TUnit::UNIT, parquet_profile, 1); |
217 | 184 | _parquet_profile.filtered_group_rows = ADD_CHILD_COUNTER_WITH_LEVEL( |
218 | 184 | _profile, "FilteredRowsByGroup", TUnit::UNIT, parquet_profile, 1); |
219 | 184 | _parquet_profile.filtered_page_rows = ADD_CHILD_COUNTER_WITH_LEVEL( |
220 | 184 | _profile, "FilteredRowsByPage", TUnit::UNIT, parquet_profile, 1); |
221 | 184 | _parquet_profile.lazy_read_filtered_rows = ADD_CHILD_COUNTER_WITH_LEVEL( |
222 | 184 | _profile, "FilteredRowsByLazyRead", TUnit::UNIT, parquet_profile, 1); |
223 | 184 | _parquet_profile.filtered_bytes = ADD_CHILD_COUNTER_WITH_LEVEL( |
224 | 184 | _profile, "FilteredBytes", TUnit::BYTES, parquet_profile, 1); |
225 | 184 | _parquet_profile.raw_rows_read = ADD_CHILD_COUNTER_WITH_LEVEL( |
226 | 184 | _profile, "RawRowsRead", TUnit::UNIT, parquet_profile, 1); |
227 | 184 | _parquet_profile.column_read_time = |
228 | 184 | ADD_CHILD_TIMER_WITH_LEVEL(_profile, "ColumnReadTime", parquet_profile, 1); |
229 | 184 | _parquet_profile.parse_meta_time = |
230 | 184 | ADD_CHILD_TIMER_WITH_LEVEL(_profile, "ParseMetaTime", parquet_profile, 1); |
231 | 184 | _parquet_profile.parse_footer_time = |
232 | 184 | ADD_CHILD_TIMER_WITH_LEVEL(_profile, "ParseFooterTime", parquet_profile, 1); |
233 | 184 | _parquet_profile.file_reader_create_time = |
234 | 184 | ADD_CHILD_TIMER_WITH_LEVEL(_profile, "FileReaderCreateTime", parquet_profile, 1); |
235 | 184 | _parquet_profile.open_file_num = |
236 | 184 | ADD_CHILD_COUNTER_WITH_LEVEL(_profile, "FileNum", TUnit::UNIT, parquet_profile, 1); |
237 | 184 | _parquet_profile.page_index_read_calls = |
238 | 184 | ADD_COUNTER_WITH_LEVEL(_profile, "PageIndexReadCalls", TUnit::UNIT, 1); |
239 | 184 | _parquet_profile.page_index_filter_time = |
240 | 184 | ADD_CHILD_TIMER_WITH_LEVEL(_profile, "PageIndexFilterTime", parquet_profile, 1); |
241 | 184 | _parquet_profile.read_page_index_time = |
242 | 184 | ADD_CHILD_TIMER_WITH_LEVEL(_profile, "PageIndexReadTime", parquet_profile, 1); |
243 | 184 | _parquet_profile.parse_page_index_time = |
244 | 184 | ADD_CHILD_TIMER_WITH_LEVEL(_profile, "PageIndexParseTime", parquet_profile, 1); |
245 | 184 | _parquet_profile.row_group_filter_time = |
246 | 184 | ADD_CHILD_TIMER_WITH_LEVEL(_profile, "RowGroupFilterTime", parquet_profile, 1); |
247 | 184 | _parquet_profile.expr_zonemap_unsupported = ADD_CHILD_COUNTER_WITH_LEVEL( |
248 | 184 | _profile, "ExprZoneMapUnsupportedExprs", TUnit::UNIT, parquet_profile, 1); |
249 | 184 | _parquet_profile.expr_zonemap_type_mismatch = ADD_CHILD_COUNTER_WITH_LEVEL( |
250 | 184 | _profile, "ExprZoneMapTypeMismatch", TUnit::UNIT, parquet_profile, 1); |
251 | 184 | _parquet_profile.in_zonemap_point_check = ADD_CHILD_COUNTER_WITH_LEVEL( |
252 | 184 | _profile, "InZoneMapPointCheckCount", TUnit::UNIT, parquet_profile, 1); |
253 | 184 | _parquet_profile.in_zonemap_range_only = ADD_CHILD_COUNTER_WITH_LEVEL( |
254 | 184 | _profile, "InZoneMapRangeOnlyCount", TUnit::UNIT, parquet_profile, 1); |
255 | 184 | _parquet_profile.in_zonemap_point_check_skipped = |
256 | 184 | ADD_CHILD_COUNTER_WITH_LEVEL(_profile, "InZoneMapPointCheckSkippedDueToThreshold", |
257 | 184 | TUnit::UNIT, parquet_profile, 1); |
258 | 184 | _parquet_profile.file_footer_read_calls = |
259 | 184 | ADD_COUNTER_WITH_LEVEL(_profile, "FileFooterReadCalls", TUnit::UNIT, 1); |
260 | 184 | _parquet_profile.file_footer_hit_cache = |
261 | 184 | ADD_COUNTER_WITH_LEVEL(_profile, "FileFooterHitCache", TUnit::UNIT, 1); |
262 | 184 | _parquet_profile.decompress_time = |
263 | 184 | ADD_CHILD_TIMER_WITH_LEVEL(_profile, "DecompressTime", parquet_profile, 1); |
264 | 184 | _parquet_profile.decompress_cnt = ADD_CHILD_COUNTER_WITH_LEVEL( |
265 | 184 | _profile, "DecompressCount", TUnit::UNIT, parquet_profile, 1); |
266 | 184 | _parquet_profile.page_read_counter = ADD_CHILD_COUNTER_WITH_LEVEL( |
267 | 184 | _profile, "PageReadCount", TUnit::UNIT, parquet_profile, 1); |
268 | 184 | _parquet_profile.page_cache_write_counter = ADD_CHILD_COUNTER_WITH_LEVEL( |
269 | 184 | _profile, "PageCacheWriteCount", TUnit::UNIT, parquet_profile, 1); |
270 | 184 | _parquet_profile.page_cache_compressed_write_counter = ADD_CHILD_COUNTER_WITH_LEVEL( |
271 | 184 | _profile, "PageCacheCompressedWriteCount", TUnit::UNIT, parquet_profile, 1); |
272 | 184 | _parquet_profile.page_cache_decompressed_write_counter = ADD_CHILD_COUNTER_WITH_LEVEL( |
273 | 184 | _profile, "PageCacheDecompressedWriteCount", TUnit::UNIT, parquet_profile, 1); |
274 | 184 | _parquet_profile.page_cache_hit_counter = ADD_CHILD_COUNTER_WITH_LEVEL( |
275 | 184 | _profile, "PageCacheHitCount", TUnit::UNIT, parquet_profile, 1); |
276 | 184 | _parquet_profile.page_cache_missing_counter = ADD_CHILD_COUNTER_WITH_LEVEL( |
277 | 184 | _profile, "PageCacheMissingCount", TUnit::UNIT, parquet_profile, 1); |
278 | 184 | _parquet_profile.page_cache_compressed_hit_counter = ADD_CHILD_COUNTER_WITH_LEVEL( |
279 | 184 | _profile, "PageCacheCompressedHitCount", TUnit::UNIT, parquet_profile, 1); |
280 | 184 | _parquet_profile.page_cache_decompressed_hit_counter = ADD_CHILD_COUNTER_WITH_LEVEL( |
281 | 184 | _profile, "PageCacheDecompressedHitCount", TUnit::UNIT, parquet_profile, 1); |
282 | 184 | _parquet_profile.decode_header_time = |
283 | 184 | ADD_CHILD_TIMER_WITH_LEVEL(_profile, "PageHeaderDecodeTime", parquet_profile, 1); |
284 | 184 | _parquet_profile.read_page_header_time = |
285 | 184 | ADD_CHILD_TIMER_WITH_LEVEL(_profile, "PageHeaderReadTime", parquet_profile, 1); |
286 | 184 | _parquet_profile.decode_value_time = |
287 | 184 | ADD_CHILD_TIMER_WITH_LEVEL(_profile, "DecodeValueTime", parquet_profile, 1); |
288 | 184 | _parquet_profile.decode_dict_time = |
289 | 184 | ADD_CHILD_TIMER_WITH_LEVEL(_profile, "DecodeDictTime", parquet_profile, 1); |
290 | 184 | _parquet_profile.decode_level_time = |
291 | 184 | ADD_CHILD_TIMER_WITH_LEVEL(_profile, "DecodeLevelTime", parquet_profile, 1); |
292 | 184 | _parquet_profile.decode_null_map_time = |
293 | 184 | ADD_CHILD_TIMER_WITH_LEVEL(_profile, "DecodeNullMapTime", parquet_profile, 1); |
294 | 184 | _parquet_profile.skip_page_header_num = ADD_CHILD_COUNTER_WITH_LEVEL( |
295 | 184 | _profile, "SkipPageHeaderNum", TUnit::UNIT, parquet_profile, 1); |
296 | 184 | _parquet_profile.parse_page_header_num = ADD_CHILD_COUNTER_WITH_LEVEL( |
297 | 184 | _profile, "ParsePageHeaderNum", TUnit::UNIT, parquet_profile, 1); |
298 | 184 | _parquet_profile.predicate_filter_time = |
299 | 184 | ADD_CHILD_TIMER_WITH_LEVEL(_profile, "PredicateFilterTime", parquet_profile, 1); |
300 | 184 | _parquet_profile.dict_filter_rewrite_time = |
301 | 184 | ADD_CHILD_TIMER_WITH_LEVEL(_profile, "DictFilterRewriteTime", parquet_profile, 1); |
302 | 184 | _parquet_profile.convert_time = |
303 | 184 | ADD_CHILD_TIMER_WITH_LEVEL(_profile, "ConvertTime", parquet_profile, 1); |
304 | 184 | _parquet_profile.bloom_filter_read_time = |
305 | 184 | ADD_CHILD_TIMER_WITH_LEVEL(_profile, "BloomFilterReadTime", parquet_profile, 1); |
306 | 184 | } |
307 | 241 | } |
308 | | |
309 | 148 | Status ParquetReader::close() { |
310 | 148 | _close_internal(); |
311 | 148 | return Status::OK(); |
312 | 148 | } |
313 | | |
314 | 507 | void ParquetReader::_close_internal() { |
315 | 507 | if (!_closed) { |
316 | 359 | _current_group_reader.reset(); |
317 | 359 | _tracing_file_reader.reset(); |
318 | 359 | _file_reader.reset(); |
319 | 359 | _closed = true; |
320 | 359 | } |
321 | 507 | } |
322 | | |
323 | 496 | Status ParquetReader::_open_file() { |
324 | 496 | if (UNLIKELY(_io_ctx && _io_ctx->should_stop)) { |
325 | 0 | return Status::EndOfFile("stop"); |
326 | 0 | } |
327 | 496 | if (_file_reader == nullptr) { |
328 | 262 | SCOPED_RAW_TIMER(&_reader_statistics.file_reader_create_time); |
329 | 262 | ++_reader_statistics.open_file_num; |
330 | 262 | _file_description.mtime = |
331 | 262 | _scan_range.__isset.modification_time ? _scan_range.modification_time : 0; |
332 | 262 | io::FileReaderOptions reader_options = |
333 | 262 | FileFactory::get_reader_options(_state, _file_description); |
334 | 262 | _file_reader = DORIS_TRY(io::DelegateReader::create_file_reader( |
335 | 262 | _profile, _system_properties, _file_description, reader_options, |
336 | 262 | io::DelegateReader::AccessMode::RANDOM, _io_ctx)); |
337 | 262 | _tracing_file_reader = _io_ctx ? std::make_shared<io::TracingFileReader>( |
338 | 262 | _file_reader, _io_ctx->file_reader_stats) |
339 | 262 | : _file_reader; |
340 | 262 | } |
341 | | |
342 | 496 | if (_file_metadata == nullptr) { |
343 | 340 | SCOPED_RAW_TIMER(&_reader_statistics.parse_footer_time); |
344 | 340 | if (_tracing_file_reader->size() <= sizeof(PARQUET_VERSION_NUMBER)) { |
345 | | // Some system may generate parquet file with only 4 bytes: PAR1 |
346 | | // Should consider it as empty file. |
347 | 0 | return Status::EndOfFile("open file failed, empty parquet file {} with size: {}", |
348 | 0 | _scan_range.path, _tracing_file_reader->size()); |
349 | 0 | } |
350 | 340 | size_t meta_size = 0; |
351 | 340 | bool enable_mapping_varbinary = _scan_params.__isset.enable_mapping_varbinary |
352 | 340 | ? _scan_params.enable_mapping_varbinary |
353 | 340 | : false; |
354 | 340 | bool enable_mapping_timestamp_tz = _scan_params.__isset.enable_mapping_timestamp_tz |
355 | 340 | ? _scan_params.enable_mapping_timestamp_tz |
356 | 340 | : false; |
357 | 340 | if (_meta_cache == nullptr) { |
358 | | // wrap _file_metadata with unique ptr, so that it can be released finally. |
359 | 170 | RETURN_IF_ERROR(parse_thrift_footer(_tracing_file_reader, &_file_metadata_ptr, |
360 | 170 | &meta_size, _io_ctx, enable_mapping_varbinary, |
361 | 170 | enable_mapping_timestamp_tz)); |
362 | 169 | _file_metadata = _file_metadata_ptr.get(); |
363 | | // parse magic number & parse meta data |
364 | 169 | _reader_statistics.file_footer_read_calls += 1; |
365 | 170 | } else { |
366 | 170 | const auto& file_meta_cache_key = |
367 | 170 | FileMetaCache::get_key(_tracing_file_reader, _file_description); |
368 | 170 | if (!_meta_cache->lookup(file_meta_cache_key, &_meta_cache_handle)) { |
369 | 134 | RETURN_IF_ERROR(parse_thrift_footer(_tracing_file_reader, &_file_metadata_ptr, |
370 | 134 | &meta_size, _io_ctx, enable_mapping_varbinary, |
371 | 134 | enable_mapping_timestamp_tz)); |
372 | | // _file_metadata_ptr.release() : move control of _file_metadata to _meta_cache_handle |
373 | 134 | _meta_cache->insert(file_meta_cache_key, _file_metadata_ptr.release(), |
374 | 134 | &_meta_cache_handle); |
375 | 134 | _file_metadata = _meta_cache_handle.data<FileMetaData>(); |
376 | 134 | _reader_statistics.file_footer_read_calls += 1; |
377 | 134 | } else { |
378 | 36 | _reader_statistics.file_footer_hit_cache++; |
379 | 36 | } |
380 | 170 | _file_metadata = _meta_cache_handle.data<FileMetaData>(); |
381 | 170 | } |
382 | | |
383 | 339 | if (_file_metadata == nullptr) { |
384 | 0 | return Status::InternalError("failed to get file meta data: {}", |
385 | 0 | _file_description.path); |
386 | 0 | } |
387 | 339 | } |
388 | 495 | return Status::OK(); |
389 | 496 | } |
390 | | |
391 | 174 | Status ParquetReader::get_file_metadata_schema(const FieldDescriptor** ptr) { |
392 | 174 | RETURN_IF_ERROR(_open_file()); |
393 | 174 | DCHECK(_file_metadata != nullptr); |
394 | 174 | *ptr = &_file_metadata->schema(); |
395 | 174 | return Status::OK(); |
396 | 174 | } |
397 | | |
398 | 359 | void ParquetReader::_init_system_properties() { |
399 | 359 | if (_scan_range.__isset.file_type) { |
400 | | // for compatibility |
401 | 227 | _system_properties.system_type = _scan_range.file_type; |
402 | 227 | } else { |
403 | 132 | _system_properties.system_type = _scan_params.file_type; |
404 | 132 | } |
405 | 359 | _system_properties.properties = _scan_params.properties; |
406 | 359 | _system_properties.hdfs_params = _scan_params.hdfs_params; |
407 | 359 | if (_scan_params.__isset.broker_addresses) { |
408 | 20 | _system_properties.broker_addresses.assign(_scan_params.broker_addresses.begin(), |
409 | 20 | _scan_params.broker_addresses.end()); |
410 | 20 | } |
411 | 359 | } |
412 | | |
413 | 359 | void ParquetReader::_init_file_description() { |
414 | 359 | _file_description.path = _scan_range.path; |
415 | 359 | _file_description.file_size = _scan_range.__isset.file_size ? _scan_range.file_size : -1; |
416 | 359 | if (_scan_range.__isset.fs_name) { |
417 | 0 | _file_description.fs_name = _scan_range.fs_name; |
418 | 0 | } |
419 | 359 | if (_scan_range.__isset.file_cache_admission) { |
420 | 114 | _file_description.file_cache_admission = _scan_range.file_cache_admission; |
421 | 114 | } |
422 | 359 | } |
423 | | |
424 | 143 | Status ParquetReader::on_before_init_reader(ReaderInitContext* ctx) { |
425 | 143 | _column_descs = ctx->column_descs; |
426 | 143 | _fill_col_name_to_block_idx = ctx->col_name_to_block_idx; |
427 | 143 | RETURN_IF_ERROR( |
428 | 143 | _extract_partition_values(*ctx->range, ctx->tuple_descriptor, _fill_partition_values)); |
429 | 940 | for (auto& desc : *ctx->column_descs) { |
430 | 940 | if (desc.category == ColumnCategory::REGULAR || |
431 | 940 | desc.category == ColumnCategory::GENERATED) { |
432 | 930 | ctx->column_names.push_back(desc.name); |
433 | 930 | } else if (desc.category == ColumnCategory::SYNTHESIZED && |
434 | 10 | desc.name.starts_with(BeConsts::GLOBAL_ROWID_COL)) { |
435 | 8 | auto topn_row_id_column_iter = _create_topn_row_id_column_iterator(); |
436 | 8 | this->register_synthesized_column_handler( |
437 | 8 | desc.name, |
438 | 8 | [iter = std::move(topn_row_id_column_iter), this, &desc]( |
439 | 13 | Block* block, size_t rows) -> Status { |
440 | 13 | return fill_topn_row_id(iter, desc.name, block, rows); |
441 | 13 | }); |
442 | 8 | continue; |
443 | 8 | } |
444 | 940 | } |
445 | | |
446 | | // Build table_info_node from Parquet file metadata with case-insensitive recursive matching. |
447 | | // File is already opened by init_reader before this hook, so metadata is available. |
448 | | // tuple_descriptor may be null in unit tests that only set column_descs. |
449 | 143 | if (ctx->tuple_descriptor != nullptr) { |
450 | 141 | const FieldDescriptor* field_desc = nullptr; |
451 | 141 | RETURN_IF_ERROR(get_file_metadata_schema(&field_desc)); |
452 | 141 | RETURN_IF_ERROR(TableSchemaChangeHelper::BuildTableInfoUtil::by_parquet_name( |
453 | 141 | ctx->tuple_descriptor, *field_desc, ctx->table_info_node)); |
454 | 141 | } |
455 | | |
456 | 143 | return Status::OK(); |
457 | 143 | } |
458 | | |
459 | 209 | Status ParquetReader::_open_file_reader(ReaderInitContext* /*ctx*/) { |
460 | 209 | return _open_file(); |
461 | 209 | } |
462 | | |
463 | 209 | Status ParquetReader::_do_init_reader(ReaderInitContext* base_ctx) { |
464 | 209 | auto* ctx = checked_context_cast<ParquetInitContext>(base_ctx); |
465 | 209 | _col_name_to_block_idx = base_ctx->col_name_to_block_idx; |
466 | 209 | _tuple_descriptor = ctx->tuple_descriptor; |
467 | 209 | _row_descriptor = ctx->row_descriptor; |
468 | 209 | _colname_to_slot_id = ctx->colname_to_slot_id; |
469 | 209 | _not_single_slot_filter_conjuncts = ctx->not_single_slot_filter_conjuncts; |
470 | 209 | _slot_id_to_filter_conjuncts = ctx->slot_id_to_filter_conjuncts; |
471 | 209 | _filter_groups = ctx->filter_groups; |
472 | 209 | _table_info_node_ptr = base_ctx->table_info_node; |
473 | 209 | _column_ids = base_ctx->column_ids; |
474 | 209 | _filter_column_ids = base_ctx->filter_column_ids; |
475 | | |
476 | | // _open_file_reader (called by init_reader NVI before hooks) must have opened the file. |
477 | 209 | DCHECK(_file_metadata != nullptr) |
478 | 0 | << "ParquetReader::_do_init_reader called without _open_file_reader"; |
479 | 209 | _t_metadata = &(_file_metadata->to_thrift()); |
480 | | |
481 | 209 | SCOPED_RAW_TIMER(&_reader_statistics.parse_meta_time); |
482 | 209 | _total_groups = _t_metadata->row_groups.size(); |
483 | 209 | if (_total_groups == 0) { |
484 | 0 | return Status::EndOfFile("init reader failed, empty parquet file: " + _scan_range.path); |
485 | 0 | } |
486 | 209 | _current_row_group_index = RowGroupReader::RowGroupIndex {-1, 0, 0}; |
487 | | |
488 | | // Compute missing columns and file↔table column mapping. |
489 | | // This runs in _do_init_reader (not on_before_init_reader) because table-format readers |
490 | | // (Iceberg, Paimon, Hive, Hudi) override on_before_init_reader completely. |
491 | 209 | if (has_column_descs()) { |
492 | 158 | _fill_missing_cols.clear(); |
493 | 158 | _fill_missing_defaults.clear(); |
494 | 983 | for (const auto& col_name : base_ctx->column_names) { |
495 | 983 | if (!_table_info_node_ptr->children_column_exists(col_name)) { |
496 | 6 | _fill_missing_cols.insert(col_name); |
497 | 6 | } |
498 | 983 | } |
499 | 158 | if (_column_descs && !_fill_missing_cols.empty()) { |
500 | 16 | for (const auto& desc : *_column_descs) { |
501 | 16 | if (_fill_missing_cols.contains(desc.name) && |
502 | 16 | !_fill_partition_values.contains(desc.name)) { |
503 | 1 | _fill_missing_defaults[desc.name] = desc.default_expr; |
504 | 1 | } |
505 | 16 | } |
506 | 6 | } |
507 | 158 | } |
508 | | // Resolve file-column ↔ table-column mapping in file-schema order. |
509 | | // _init_read_columns handles both normal path (missing cols populated above) |
510 | | // and standalone path (_fill_missing_cols empty, _table_info_node_ptr may be null). |
511 | 209 | _init_read_columns(base_ctx->column_names); |
512 | | |
513 | | // build column predicates for column lazy read |
514 | 209 | if (ctx->conjuncts != nullptr) { |
515 | 209 | _lazy_read_ctx.conjuncts = *ctx->conjuncts; |
516 | 209 | } |
517 | 209 | if (ctx->slot_id_to_predicates != nullptr) { |
518 | 209 | _lazy_read_ctx.slot_id_to_predicates = *ctx->slot_id_to_predicates; |
519 | 209 | } |
520 | | |
521 | | // ---- Inlined set_fill_columns logic (partition/missing/synthesized classification) ---- |
522 | | |
523 | | // 1. Collect predicate columns from conjuncts for lazy materialization |
524 | 209 | std::unordered_map<std::string, std::pair<uint32_t, int>> predicate_columns; |
525 | 209 | _collect_predicate_columns_from_conjuncts(predicate_columns); |
526 | | |
527 | | // 2. Classify read/partition/missing/synthesized columns into lazy vs predicate groups |
528 | 209 | _classify_columns_for_lazy_read(predicate_columns, _fill_partition_values, |
529 | 209 | _fill_missing_defaults); |
530 | | |
531 | | // 3. Populate col_names vectors for ColumnProcessor path |
532 | 209 | for (auto& kv : _lazy_read_ctx.predicate_partition_columns) { |
533 | 5 | _lazy_read_ctx.predicate_partition_col_names.emplace_back(kv.first); |
534 | 5 | } |
535 | 209 | for (auto& kv : _lazy_read_ctx.predicate_missing_columns) { |
536 | 0 | _lazy_read_ctx.predicate_missing_col_names.emplace_back(kv.first); |
537 | 0 | } |
538 | 209 | for (auto& kv : _lazy_read_ctx.partition_columns) { |
539 | 5 | _lazy_read_ctx.partition_col_names.emplace_back(kv.first); |
540 | 5 | } |
541 | 209 | for (auto& kv : _lazy_read_ctx.missing_columns) { |
542 | 1 | _lazy_read_ctx.missing_col_names.emplace_back(kv.first); |
543 | 1 | } |
544 | | |
545 | 209 | if (_filter_groups && (_total_groups == 0 || _t_metadata->num_rows == 0 || _range_size < 0)) { |
546 | 0 | return Status::EndOfFile("No row group to read"); |
547 | 0 | } |
548 | | |
549 | 209 | return Status::OK(); |
550 | 209 | } |
551 | | |
552 | 209 | void ParquetReader::_init_read_columns(const std::vector<std::string>& column_names) { |
553 | | // Build file_col_name → table_col_name map, skipping missing columns. |
554 | | // Must iterate file schema in physical order so that _generate_random_access_ranges |
555 | | // sees monotonically increasing chunk offsets. |
556 | 209 | auto schema_desc = _file_metadata->schema(); |
557 | 209 | std::map<std::string, std::string> required_file_columns; |
558 | 1.43k | for (const auto& col_name : column_names) { |
559 | 1.43k | if (_fill_missing_cols.contains(col_name)) { |
560 | 6 | continue; |
561 | 6 | } |
562 | 1.42k | std::string file_col = col_name; |
563 | 1.42k | if (_table_info_node_ptr && _table_info_node_ptr->children_column_exists(col_name)) { |
564 | 1.42k | file_col = _table_info_node_ptr->children_file_column_name(col_name); |
565 | 1.42k | } |
566 | 1.42k | required_file_columns[file_col] = col_name; |
567 | 1.42k | } |
568 | 2.09k | for (int i = 0; i < schema_desc.size(); ++i) { |
569 | 1.88k | const auto& name = schema_desc.get_column(i)->name; |
570 | 1.88k | if (required_file_columns.contains(name)) { |
571 | 1.42k | _read_file_columns.emplace_back(name); |
572 | 1.42k | _read_table_columns.emplace_back(required_file_columns[name]); |
573 | 1.42k | _read_table_columns_set.insert(required_file_columns[name]); |
574 | 1.42k | } |
575 | 1.88k | } |
576 | 209 | } |
577 | | |
578 | 31 | bool ParquetReader::_exists_in_file(const std::string& expr_name) const { |
579 | | // `_read_table_columns_set` is used to ensure that only columns actually read are subject to min-max filtering. |
580 | | // This primarily handles cases where partition columns also exist in a file. The reason it's not modified |
581 | | // in `_table_info_node_ptr` is that Iceberg、Hudi has inconsistent requirements for this node; |
582 | | // Iceberg partition evolution need read partition columns from a file. |
583 | | // hudi set `hoodie.datasource.write.drop.partition.columns=false` not need read partition columns from a file. |
584 | 31 | return _table_info_node_ptr->children_column_exists(expr_name) && |
585 | 31 | _read_table_columns_set.contains(expr_name); |
586 | 31 | } |
587 | | |
588 | 26 | bool ParquetReader::_type_matches(const int cid) const { |
589 | 26 | auto* slot = _tuple_descriptor->slots()[cid]; |
590 | 26 | auto table_col_type = remove_nullable(slot->type()); |
591 | | |
592 | 26 | const auto& file_col_name = _table_info_node_ptr->children_file_column_name(slot->col_name()); |
593 | 26 | const auto& file_col_type = |
594 | 26 | remove_nullable(_file_metadata->schema().get_column(file_col_name)->data_type); |
595 | | |
596 | 26 | return (table_col_type->get_primitive_type() == file_col_type->get_primitive_type()) && |
597 | 26 | !is_complex_type(table_col_type->get_primitive_type()); |
598 | 26 | } |
599 | | |
600 | | void ParquetReader::_collect_predicate_columns_from_conjuncts( |
601 | 209 | std::unordered_map<std::string, std::pair<uint32_t, int>>& predicate_columns) { |
602 | 209 | std::function<void(VExpr * expr)> visit_slot = [&](VExpr* expr) { |
603 | 44 | if (expr->is_slot_ref()) { |
604 | 15 | VSlotRef* slot_ref = static_cast<VSlotRef*>(expr); |
605 | 15 | auto expr_name = slot_ref->expr_name(); |
606 | 15 | predicate_columns.emplace(expr_name, |
607 | 15 | std::make_pair(slot_ref->column_id(), slot_ref->slot_id())); |
608 | 15 | if (slot_ref->column_id() == 0) { |
609 | 5 | _lazy_read_ctx.resize_first_column = false; |
610 | 5 | } |
611 | 15 | return; |
612 | 15 | } |
613 | 29 | for (auto& child : expr->children()) { |
614 | 29 | visit_slot(child.get()); |
615 | 29 | } |
616 | 29 | }; |
617 | | |
618 | 209 | for (const auto& conjunct : _lazy_read_ctx.conjuncts) { |
619 | 15 | auto expr = conjunct->root(); |
620 | 15 | if (expr->is_rf_wrapper()) { |
621 | 0 | RuntimeFilterExpr* runtime_filter = assert_cast<RuntimeFilterExpr*>(expr.get()); |
622 | 0 | auto filter_impl = runtime_filter->get_impl(); |
623 | 0 | visit_slot(filter_impl.get()); |
624 | 15 | } else { |
625 | 15 | visit_slot(expr.get()); |
626 | 15 | } |
627 | 15 | } |
628 | | |
629 | 209 | if (!_lazy_read_ctx.slot_id_to_predicates.empty()) { |
630 | 126 | auto and_pred = AndBlockColumnPredicate::create_unique(); |
631 | 873 | for (const auto& entry : _lazy_read_ctx.slot_id_to_predicates) { |
632 | 873 | for (const auto& pred : entry.second) { |
633 | | // Parquet shares _push_down_predicates for row-group/page min-max pruning and |
634 | | // bloom-filter evaluation, so this flag currently gates both predicate paths. |
635 | 2 | if (!has_column_optimization(pred->col_name(), ColumnOptimizationTypes::MIN_MAX)) { |
636 | 0 | continue; |
637 | 0 | } |
638 | 2 | if (!_exists_in_file(pred->col_name()) || !_type_matches(pred->column_id())) { |
639 | 0 | continue; |
640 | 0 | } |
641 | 2 | and_pred->add_column_predicate( |
642 | 2 | SingleColumnBlockPredicate::create_unique(pred->clone(pred->column_id()))); |
643 | 2 | } |
644 | 873 | } |
645 | 126 | if (and_pred->num_of_column_predicate() > 0) { |
646 | 2 | _push_down_predicates.push_back(std::move(and_pred)); |
647 | 2 | } |
648 | 126 | } |
649 | 209 | } |
650 | | |
651 | | void ParquetReader::_classify_columns_for_lazy_read( |
652 | | const std::unordered_map<std::string, std::pair<uint32_t, int>>& |
653 | | predicate_conjuncts_columns, |
654 | | const std::unordered_map<std::string, std::tuple<std::string, const SlotDescriptor*>>& |
655 | | partition_columns, |
656 | 134 | const std::unordered_map<std::string, VExprContextSPtr>& missing_columns) { |
657 | 134 | const FieldDescriptor& schema = _file_metadata->schema(); |
658 | 134 | auto predicate_columns = predicate_conjuncts_columns; |
659 | 134 | #ifndef BE_TEST |
660 | 134 | for (const auto& [col_name, _] : _generated_col_handlers) { |
661 | 0 | int slot_id = -1; |
662 | 0 | for (auto slot : _tuple_descriptor->slots()) { |
663 | 0 | if (slot->col_name() == col_name) { |
664 | 0 | slot_id = slot->id(); |
665 | 0 | break; |
666 | 0 | } |
667 | 0 | } |
668 | 0 | DCHECK(slot_id != -1) << "slot id should not be -1 for generated column: " << col_name; |
669 | 0 | auto column_index = _row_descriptor->get_column_id(slot_id); |
670 | 0 | if (column_index == 0) { |
671 | 0 | _lazy_read_ctx.resize_first_column = false; |
672 | 0 | } |
673 | | // assume generated columns are only used for predicate push down. |
674 | 0 | predicate_columns.emplace(col_name, std::make_pair(column_index, slot_id)); |
675 | 0 | } |
676 | | |
677 | 134 | for (const auto& [col_name, _] : _synthesized_col_handlers) { |
678 | 8 | int slot_id = -1; |
679 | 29 | for (auto slot : _tuple_descriptor->slots()) { |
680 | 29 | if (slot->col_name() == col_name) { |
681 | 8 | slot_id = slot->id(); |
682 | 8 | break; |
683 | 8 | } |
684 | 29 | } |
685 | 8 | DCHECK(slot_id != -1) << "slot id should not be -1 for synthesized column: " << col_name; |
686 | 8 | auto column_index = _row_descriptor->get_column_id(slot_id); |
687 | 8 | if (column_index == 0) { |
688 | 0 | _lazy_read_ctx.resize_first_column = false; |
689 | 0 | } |
690 | | // synthesized columns always fill data on first phase. |
691 | 8 | _lazy_read_ctx.all_predicate_col_ids.emplace_back(column_index); |
692 | 8 | } |
693 | 134 | #endif |
694 | 908 | for (auto& read_table_col : _read_table_columns) { |
695 | 908 | _lazy_read_ctx.all_read_columns.emplace_back(read_table_col); |
696 | | |
697 | 908 | auto file_column_name = _table_info_node_ptr->children_file_column_name(read_table_col); |
698 | 908 | PrimitiveType column_type = |
699 | 908 | schema.get_column(file_column_name)->data_type->get_primitive_type(); |
700 | 908 | if (is_complex_type(column_type)) { |
701 | 210 | _lazy_read_ctx.has_complex_type = true; |
702 | 210 | } |
703 | 908 | if (predicate_columns.size() > 0) { |
704 | 2 | auto iter = predicate_columns.find(read_table_col); |
705 | 2 | if (iter == predicate_columns.end()) { |
706 | 0 | _lazy_read_ctx.lazy_read_columns.emplace_back(read_table_col); |
707 | 2 | } else { |
708 | 2 | _lazy_read_ctx.predicate_columns.first.emplace_back(iter->first); |
709 | 2 | _lazy_read_ctx.predicate_columns.second.emplace_back(iter->second.second); |
710 | 2 | _lazy_read_ctx.all_predicate_col_ids.emplace_back(iter->second.first); |
711 | 2 | } |
712 | 2 | } |
713 | 908 | } |
714 | | |
715 | 134 | for (auto& kv : partition_columns) { |
716 | 2 | auto iter = predicate_columns.find(kv.first); |
717 | 2 | if (iter == predicate_columns.end()) { |
718 | 2 | _lazy_read_ctx.partition_columns.emplace(kv.first, kv.second); |
719 | 2 | } else { |
720 | 0 | _lazy_read_ctx.predicate_partition_columns.emplace(kv.first, kv.second); |
721 | 0 | _lazy_read_ctx.all_predicate_col_ids.emplace_back(iter->second.first); |
722 | 0 | } |
723 | 2 | } |
724 | | |
725 | 134 | for (auto& kv : missing_columns) { |
726 | 1 | auto iter = predicate_columns.find(kv.first); |
727 | 1 | if (iter != predicate_columns.end()) { |
728 | | //For check missing column : missing column == xx, missing column is null,missing column is not null. |
729 | 0 | if (_slot_id_to_filter_conjuncts->find(iter->second.second) != |
730 | 0 | _slot_id_to_filter_conjuncts->end()) { |
731 | 0 | for (auto& ctx : _slot_id_to_filter_conjuncts->find(iter->second.second)->second) { |
732 | 0 | _lazy_read_ctx.missing_columns_conjuncts.emplace_back(ctx); |
733 | 0 | } |
734 | 0 | } |
735 | 0 | _lazy_read_ctx.predicate_missing_columns.emplace(kv.first, kv.second); |
736 | 0 | _lazy_read_ctx.all_predicate_col_ids.emplace_back(iter->second.first); |
737 | 1 | } else { |
738 | 1 | _lazy_read_ctx.missing_columns.emplace(kv.first, kv.second); |
739 | 1 | } |
740 | 1 | } |
741 | | |
742 | 134 | if (_enable_lazy_mat && _lazy_read_ctx.predicate_columns.first.size() > 0 && |
743 | 134 | _lazy_read_ctx.lazy_read_columns.size() > 0) { |
744 | 0 | _lazy_read_ctx.can_lazy_read = true; |
745 | 0 | } |
746 | | |
747 | 134 | if (!_lazy_read_ctx.can_lazy_read) { |
748 | 134 | for (auto& kv : _lazy_read_ctx.predicate_partition_columns) { |
749 | 0 | _lazy_read_ctx.partition_columns.emplace(kv.first, kv.second); |
750 | 0 | } |
751 | 134 | for (auto& kv : _lazy_read_ctx.predicate_missing_columns) { |
752 | 0 | _lazy_read_ctx.missing_columns.emplace(kv.first, kv.second); |
753 | 0 | } |
754 | 134 | } |
755 | 134 | } |
756 | | |
757 | | // init file reader and file metadata for parsing schema |
758 | 113 | Status ParquetReader::init_schema_reader() { |
759 | 113 | RETURN_IF_ERROR(_open_file()); |
760 | 112 | _t_metadata = &(_file_metadata->to_thrift()); |
761 | 112 | return Status::OK(); |
762 | 113 | } |
763 | | |
764 | | Status ParquetReader::get_parsed_schema(std::vector<std::string>* col_names, |
765 | 112 | std::vector<DataTypePtr>* col_types) { |
766 | 112 | _total_groups = _t_metadata->row_groups.size(); |
767 | 112 | auto schema_desc = _file_metadata->schema(); |
768 | 675 | for (int i = 0; i < schema_desc.size(); ++i) { |
769 | | // Get the Column Reader for the boolean column |
770 | 563 | col_names->emplace_back(schema_desc.get_column(i)->name); |
771 | 563 | col_types->emplace_back(make_nullable(schema_desc.get_column(i)->data_type)); |
772 | 563 | } |
773 | 112 | return Status::OK(); |
774 | 112 | } |
775 | | |
776 | | Status ParquetReader::_get_columns_impl( |
777 | 148 | std::unordered_map<std::string, DataTypePtr>* name_to_type) { |
778 | 148 | const auto& schema_desc = _file_metadata->schema(); |
779 | 148 | std::unordered_set<std::string> column_names; |
780 | 148 | schema_desc.get_column_names(&column_names); |
781 | 1.33k | for (auto& name : column_names) { |
782 | 1.33k | auto field = schema_desc.get_column(name); |
783 | 1.33k | name_to_type->emplace(name, field->data_type); |
784 | 1.33k | } |
785 | 148 | return Status::OK(); |
786 | 148 | } |
787 | | |
788 | 252 | Status ParquetReader::_do_get_next_block(Block* block, size_t* read_rows, bool* eof) { |
789 | 252 | if (_current_group_reader == nullptr || _row_group_eof) { |
790 | 186 | Status st = _next_row_group_reader(); |
791 | 186 | if (!st.ok() && !st.is<ErrorCode::END_OF_FILE>()) { |
792 | 0 | return st; |
793 | 0 | } |
794 | 186 | if (_current_group_reader == nullptr || _row_group_eof || st.is<ErrorCode::END_OF_FILE>()) { |
795 | 4 | _current_group_reader.reset(nullptr); |
796 | 4 | _row_group_eof = true; |
797 | 4 | *read_rows = 0; |
798 | 4 | *eof = true; |
799 | 4 | return Status::OK(); |
800 | 4 | } |
801 | 186 | } |
802 | | |
803 | | // Limit memory per batch for load paths. |
804 | | // _load_bytes_per_row is updated after each batch so the *next* call pre-shrinks _batch_size |
805 | | // before reading, ensuring the current batch is already within the limit (from call 2 onward). |
806 | 248 | const int64_t max_block_bytes = |
807 | 248 | (_state != nullptr && _state->query_type() == TQueryType::LOAD && |
808 | 248 | config::load_reader_max_block_bytes > 0) |
809 | 248 | ? config::load_reader_max_block_bytes |
810 | 248 | : 0; |
811 | 248 | if (max_block_bytes > 0 && _load_bytes_per_row > 0) { |
812 | 12 | _batch_size = std::max((size_t)1, |
813 | 12 | (size_t)((int64_t)max_block_bytes / (int64_t)_load_bytes_per_row)); |
814 | 12 | } |
815 | | |
816 | 248 | SCOPED_RAW_TIMER(&_reader_statistics.column_read_time); |
817 | 248 | Status batch_st = |
818 | 248 | _current_group_reader->next_batch(block, _batch_size, read_rows, &_row_group_eof); |
819 | 248 | if (batch_st.is<ErrorCode::END_OF_FILE>()) { |
820 | 0 | block->clear_column_data(); |
821 | 0 | _current_group_reader.reset(nullptr); |
822 | 0 | *read_rows = 0; |
823 | 0 | *eof = true; |
824 | 0 | return Status::OK(); |
825 | 0 | } |
826 | | |
827 | 248 | if (!batch_st.ok()) { |
828 | 0 | return Status::InternalError("Read parquet file {} failed, reason = {}", _scan_range.path, |
829 | 0 | batch_st.to_string()); |
830 | 0 | } |
831 | | |
832 | 248 | if (max_block_bytes > 0 && *read_rows > 0) { |
833 | 40 | _load_bytes_per_row = block->bytes() / *read_rows; |
834 | 40 | } |
835 | | |
836 | 248 | if (_row_group_eof) { |
837 | 182 | auto column_st = _current_group_reader->merged_column_statistics(); |
838 | 182 | _column_statistics.merge(column_st); |
839 | 182 | _reader_statistics.lazy_read_filtered_rows += |
840 | 182 | _current_group_reader->lazy_read_filtered_rows(); |
841 | 182 | _reader_statistics.predicate_filter_time += _current_group_reader->predicate_filter_time(); |
842 | 182 | _reader_statistics.dict_filter_rewrite_time += |
843 | 182 | _current_group_reader->dict_filter_rewrite_time(); |
844 | 182 | if (_io_ctx) { |
845 | 163 | _io_ctx->condition_cache_filtered_rows += |
846 | 163 | _current_group_reader->condition_cache_filtered_rows(); |
847 | 163 | } |
848 | | |
849 | 182 | if (_current_row_group_index.row_group_id + 1 == _total_groups) { |
850 | 167 | *eof = true; |
851 | 167 | } else { |
852 | 15 | *eof = false; |
853 | 15 | } |
854 | 182 | } |
855 | 248 | return Status::OK(); |
856 | 248 | } |
857 | | |
858 | | RowGroupReader::PositionDeleteContext ParquetReader::_get_position_delete_ctx( |
859 | 182 | const tparquet::RowGroup& row_group, const RowGroupReader::RowGroupIndex& row_group_index) { |
860 | 182 | if (_delete_rows == nullptr) { |
861 | 182 | return RowGroupReader::PositionDeleteContext(row_group.num_rows, row_group_index.first_row); |
862 | 182 | } |
863 | 0 | const int64_t* delete_rows = &(*_delete_rows)[0]; |
864 | 0 | const int64_t* delete_rows_end = delete_rows + _delete_rows->size(); |
865 | 0 | const int64_t* start_pos = std::lower_bound(delete_rows + _delete_rows_index, delete_rows_end, |
866 | 0 | row_group_index.first_row); |
867 | 0 | int64_t start_index = start_pos - delete_rows; |
868 | 0 | const int64_t* end_pos = std::lower_bound(start_pos, delete_rows_end, row_group_index.last_row); |
869 | 0 | int64_t end_index = end_pos - delete_rows; |
870 | 0 | _delete_rows_index = end_index; |
871 | 0 | return RowGroupReader::PositionDeleteContext(*_delete_rows, row_group.num_rows, |
872 | 0 | row_group_index.first_row, start_index, end_index); |
873 | 182 | } |
874 | | |
875 | 186 | Status ParquetReader::_next_row_group_reader() { |
876 | 186 | if (_current_group_reader != nullptr) { |
877 | 15 | _current_group_reader->collect_profile_before_close(); |
878 | 15 | } |
879 | | |
880 | 186 | RowRanges candidate_row_ranges; |
881 | 191 | while (++_current_row_group_index.row_group_id < _total_groups) { |
882 | 187 | const auto& row_group = _t_metadata->row_groups[_current_row_group_index.row_group_id]; |
883 | 187 | _current_row_group_index.first_row = _current_row_group_index.last_row; |
884 | 187 | _current_row_group_index.last_row = _current_row_group_index.last_row + row_group.num_rows; |
885 | | |
886 | 187 | if (_filter_groups && _is_misaligned_range_group(row_group)) { |
887 | 0 | continue; |
888 | 0 | } |
889 | | |
890 | 187 | candidate_row_ranges.clear(); |
891 | | // The range of lines to be read is determined by the push down predicate. |
892 | 187 | RETURN_IF_ERROR(_process_min_max_bloom_filter( |
893 | 187 | _current_row_group_index, row_group, _push_down_predicates, &candidate_row_ranges)); |
894 | | |
895 | 187 | std::function<int64_t(const FieldSchema*)> column_compressed_size = |
896 | 1.79k | [&row_group, &column_compressed_size](const FieldSchema* field) -> int64_t { |
897 | 1.79k | if (field->physical_column_index >= 0) { |
898 | 1.32k | int parquet_col_id = field->physical_column_index; |
899 | 1.32k | if (row_group.columns[parquet_col_id].__isset.meta_data) { |
900 | 1.32k | return row_group.columns[parquet_col_id].meta_data.total_compressed_size; |
901 | 1.32k | } |
902 | 0 | return 0; |
903 | 1.32k | } |
904 | 478 | int64_t size = 0; |
905 | 602 | for (const FieldSchema& child : field->children) { |
906 | 602 | size += column_compressed_size(&child); |
907 | 602 | } |
908 | 478 | return size; |
909 | 1.79k | }; |
910 | 187 | int64_t group_size = 0; // only calculate the needed columns |
911 | 1.19k | for (auto& read_col : _read_file_columns) { |
912 | 1.19k | const FieldSchema* field = _file_metadata->schema().get_column(read_col); |
913 | 1.19k | group_size += column_compressed_size(field); |
914 | 1.19k | } |
915 | | |
916 | 187 | _reader_statistics.read_rows += candidate_row_ranges.count(); |
917 | 187 | if (_io_ctx) { |
918 | 164 | _io_ctx->file_reader_stats->read_rows += candidate_row_ranges.count(); |
919 | 164 | } |
920 | | |
921 | 187 | if (candidate_row_ranges.count() != 0) { |
922 | | // need read this row group. |
923 | 182 | _reader_statistics.read_row_groups++; |
924 | 182 | _reader_statistics.filtered_page_rows += |
925 | 182 | row_group.num_rows - candidate_row_ranges.count(); |
926 | 182 | break; |
927 | 182 | } else { |
928 | | // this row group be filtered. |
929 | 5 | _reader_statistics.filtered_row_groups++; |
930 | 5 | _reader_statistics.filtered_bytes += group_size; |
931 | 5 | _reader_statistics.filtered_group_rows += row_group.num_rows; |
932 | 5 | } |
933 | 187 | } |
934 | | |
935 | 186 | if (_current_row_group_index.row_group_id == _total_groups) { |
936 | 4 | _row_group_eof = true; |
937 | 4 | _current_group_reader.reset(nullptr); |
938 | 4 | return Status::EndOfFile("No next RowGroupReader"); |
939 | 4 | } |
940 | | |
941 | | // process page index and generate the ranges to read |
942 | 182 | auto& row_group = _t_metadata->row_groups[_current_row_group_index.row_group_id]; |
943 | | |
944 | 182 | RowGroupReader::PositionDeleteContext position_delete_ctx = |
945 | 182 | _get_position_delete_ctx(row_group, _current_row_group_index); |
946 | 182 | io::FileReaderSPtr group_file_reader; |
947 | 182 | if (typeid_cast<io::InMemoryFileReader*>(_file_reader.get())) { |
948 | | // InMemoryFileReader has the ability to merge small IO |
949 | 106 | group_file_reader = _file_reader; |
950 | 106 | } else { |
951 | 76 | size_t avg_io_size = 0; |
952 | 76 | const std::vector<io::PrefetchRange> io_ranges = |
953 | 76 | _generate_random_access_ranges(_current_row_group_index, &avg_io_size); |
954 | 76 | int64_t merged_read_slice_size = -1; |
955 | 76 | if (_state != nullptr && _state->query_options().__isset.merge_read_slice_size) { |
956 | 64 | merged_read_slice_size = _state->query_options().merge_read_slice_size; |
957 | 64 | } |
958 | | // The underlying page reader will prefetch data in column. |
959 | | // Using both MergeRangeFileReader and BufferedStreamReader simultaneously would waste a lot of memory. |
960 | 76 | group_file_reader = |
961 | 76 | avg_io_size < io::MergeRangeFileReader::SMALL_IO |
962 | 76 | ? std::make_shared<io::MergeRangeFileReader>( |
963 | 76 | _profile, _file_reader, io_ranges, merged_read_slice_size) |
964 | 76 | : _file_reader; |
965 | 76 | } |
966 | 182 | _current_group_reader.reset(new RowGroupReader( |
967 | 182 | _io_ctx ? std::make_shared<io::TracingFileReader>(group_file_reader, |
968 | 163 | _io_ctx->file_reader_stats) |
969 | 182 | : group_file_reader, |
970 | 182 | _read_table_columns, _current_row_group_index.row_group_id, row_group, _ctz, _io_ctx, |
971 | 182 | position_delete_ctx, _lazy_read_ctx, _state, _column_ids, _filter_column_ids)); |
972 | 182 | _row_group_eof = false; |
973 | | |
974 | 182 | _current_group_reader->set_current_row_group_idx(_current_row_group_index); |
975 | 182 | _current_group_reader->set_col_name_to_block_idx(_col_name_to_block_idx); |
976 | 182 | if (_condition_cache_ctx) { |
977 | 7 | _current_group_reader->set_condition_cache_context(_condition_cache_ctx); |
978 | 7 | } |
979 | 182 | _current_group_reader->set_table_format_reader(this); |
980 | | |
981 | 182 | _current_group_reader->_table_info_node_ptr = _table_info_node_ptr; |
982 | 182 | return _current_group_reader->init(_file_metadata->schema(), candidate_row_ranges, _col_offsets, |
983 | 182 | _tuple_descriptor, _row_descriptor, _colname_to_slot_id, |
984 | 182 | _not_single_slot_filter_conjuncts, |
985 | 182 | _slot_id_to_filter_conjuncts); |
986 | 186 | } |
987 | | |
988 | | std::vector<io::PrefetchRange> ParquetReader::_generate_random_access_ranges( |
989 | 76 | const RowGroupReader::RowGroupIndex& group, size_t* avg_io_size) { |
990 | 76 | std::vector<io::PrefetchRange> result; |
991 | 76 | int64_t last_chunk_end = -1; |
992 | 76 | size_t total_io_size = 0; |
993 | 76 | std::function<void(const FieldSchema*, const tparquet::RowGroup&)> scalar_range = |
994 | 1.12k | [&](const FieldSchema* field, const tparquet::RowGroup& row_group) { |
995 | 1.12k | if (_column_ids.empty() || |
996 | 1.12k | _column_ids.find(field->get_column_id()) != _column_ids.end()) { |
997 | 1.11k | if (field->data_type->get_primitive_type() == TYPE_ARRAY) { |
998 | 296 | scalar_range(&field->children[0], row_group); |
999 | 822 | } else if (field->data_type->get_primitive_type() == TYPE_MAP) { |
1000 | 38 | scalar_range(&field->children[0], row_group); |
1001 | 38 | scalar_range(&field->children[1], row_group); |
1002 | 784 | } else if (field->data_type->get_primitive_type() == TYPE_STRUCT) { |
1003 | 37 | for (int i = 0; i < field->children.size(); ++i) { |
1004 | 26 | scalar_range(&field->children[i], row_group); |
1005 | 26 | } |
1006 | 773 | } else { |
1007 | 773 | const tparquet::ColumnChunk& chunk = |
1008 | 773 | row_group.columns[field->physical_column_index]; |
1009 | 773 | auto& chunk_meta = chunk.meta_data; |
1010 | 773 | int64_t chunk_start = has_dict_page(chunk_meta) |
1011 | 773 | ? chunk_meta.dictionary_page_offset |
1012 | 773 | : chunk_meta.data_page_offset; |
1013 | 773 | int64_t chunk_end = chunk_start + chunk_meta.total_compressed_size; |
1014 | 773 | DCHECK_GE(chunk_start, last_chunk_end); |
1015 | 773 | result.emplace_back(chunk_start, chunk_end); |
1016 | 773 | total_io_size += chunk_meta.total_compressed_size; |
1017 | 773 | last_chunk_end = chunk_end; |
1018 | 773 | } |
1019 | 1.11k | } |
1020 | 1.12k | }; |
1021 | 76 | const tparquet::RowGroup& row_group = _t_metadata->row_groups[group.row_group_id]; |
1022 | 724 | for (const auto& read_col : _read_file_columns) { |
1023 | 724 | const FieldSchema* field = _file_metadata->schema().get_column(read_col); |
1024 | 724 | scalar_range(field, row_group); |
1025 | 724 | } |
1026 | 76 | if (!result.empty()) { |
1027 | 75 | *avg_io_size = total_io_size / result.size(); |
1028 | 75 | } |
1029 | 76 | return result; |
1030 | 76 | } |
1031 | | |
1032 | 195 | bool ParquetReader::_is_misaligned_range_group(const tparquet::RowGroup& row_group) const { |
1033 | 195 | int64_t start_offset = _get_column_start_offset(row_group.columns[0].meta_data); |
1034 | | |
1035 | 195 | auto& last_column = row_group.columns[row_group.columns.size() - 1].meta_data; |
1036 | 195 | int64_t end_offset = _get_column_start_offset(last_column) + last_column.total_compressed_size; |
1037 | | |
1038 | 195 | int64_t row_group_mid = start_offset + (end_offset - start_offset) / 2; |
1039 | 195 | if (!(row_group_mid >= _range_start_offset && |
1040 | 195 | row_group_mid < _range_start_offset + _range_size)) { |
1041 | 0 | return true; |
1042 | 0 | } |
1043 | 195 | return false; |
1044 | 195 | } |
1045 | | |
1046 | 2 | int64_t ParquetReader::get_total_rows() const { |
1047 | 2 | if (!_t_metadata) return 0; |
1048 | 2 | if (!_filter_groups) return _t_metadata->num_rows; |
1049 | 2 | int64_t total = 0; |
1050 | 7 | for (const auto& rg : _t_metadata->row_groups) { |
1051 | 7 | if (!_is_misaligned_range_group(rg)) { |
1052 | 7 | total += rg.num_rows; |
1053 | 7 | } |
1054 | 7 | } |
1055 | 2 | return total; |
1056 | 2 | } |
1057 | | |
1058 | 2 | void ParquetReader::set_condition_cache_context(std::shared_ptr<ConditionCacheContext> ctx) { |
1059 | 2 | _condition_cache_ctx = std::move(ctx); |
1060 | 2 | if (!_condition_cache_ctx || !_t_metadata || !_filter_groups) { |
1061 | 0 | return; |
1062 | 0 | } |
1063 | | // Find the first assigned row group to compute base_granule. |
1064 | 2 | int64_t first_row = 0; |
1065 | 2 | for (const auto& rg : _t_metadata->row_groups) { |
1066 | 2 | if (!_is_misaligned_range_group(rg)) { |
1067 | 2 | _condition_cache_ctx->base_granule = first_row / ConditionCacheContext::GRANULE_SIZE; |
1068 | 2 | return; |
1069 | 2 | } |
1070 | 0 | first_row += rg.num_rows; |
1071 | 0 | } |
1072 | 2 | } |
1073 | | |
1074 | | Status ParquetReader::_process_page_index_filter( |
1075 | | const tparquet::RowGroup& row_group, const RowGroupReader::RowGroupIndex& row_group_index, |
1076 | | const std::vector<std::unique_ptr<MutilColumnBlockPredicate>>& push_down_pred, |
1077 | 151 | RowRanges* candidate_row_ranges) { |
1078 | 151 | if (UNLIKELY(_io_ctx && _io_ctx->should_stop)) { |
1079 | 0 | return Status::EndOfFile("stop"); |
1080 | 0 | } |
1081 | | |
1082 | 151 | std::function<void()> read_whole_row_group = [&]() { |
1083 | 150 | candidate_row_ranges->add(RowRange {0, row_group.num_rows}); |
1084 | 150 | }; |
1085 | | |
1086 | | // Check if the page index is available and if it exists. |
1087 | 151 | PageIndex page_index; |
1088 | 151 | if (!config::enable_parquet_page_index || _colname_to_slot_id == nullptr || |
1089 | 151 | !page_index.check_and_get_page_index_ranges(row_group.columns)) { |
1090 | 144 | read_whole_row_group(); |
1091 | 144 | return Status::OK(); |
1092 | 144 | } |
1093 | | |
1094 | 7 | std::vector<int> parquet_col_ids; |
1095 | 296 | for (size_t idx = 0; idx < _read_table_columns.size(); idx++) { |
1096 | 289 | const auto& read_table_col = _read_table_columns[idx]; |
1097 | 289 | const auto& read_file_col = _read_file_columns[idx]; |
1098 | 289 | if (!_colname_to_slot_id->contains(read_table_col)) { |
1099 | 274 | continue; |
1100 | 274 | } |
1101 | 15 | auto* field = _file_metadata->schema().get_column(read_file_col); |
1102 | | |
1103 | 15 | std::function<void(FieldSchema * field)> f = [&](FieldSchema* field) { |
1104 | 15 | if (!_column_ids.empty() && |
1105 | 15 | _column_ids.find(field->get_column_id()) == _column_ids.end()) { |
1106 | 0 | return; |
1107 | 0 | } |
1108 | | |
1109 | 15 | if (field->data_type->get_primitive_type() == TYPE_ARRAY) { |
1110 | 0 | f(&field->children[0]); |
1111 | 15 | } else if (field->data_type->get_primitive_type() == TYPE_MAP) { |
1112 | 0 | f(&field->children[0]); |
1113 | 0 | f(&field->children[1]); |
1114 | 15 | } else if (field->data_type->get_primitive_type() == TYPE_STRUCT) { |
1115 | 0 | for (int i = 0; i < field->children.size(); ++i) { |
1116 | 0 | f(&field->children[i]); |
1117 | 0 | } |
1118 | 15 | } else { |
1119 | 15 | int parquet_col_id = field->physical_column_index; |
1120 | 15 | if (parquet_col_id >= 0) { |
1121 | 15 | parquet_col_ids.push_back(parquet_col_id); |
1122 | 15 | } |
1123 | 15 | } |
1124 | 15 | }; |
1125 | | |
1126 | 15 | f(field); |
1127 | 15 | } |
1128 | | |
1129 | 7 | auto parse_offset_index = [&]() -> Status { |
1130 | 7 | std::vector<uint8_t> off_index_buff(page_index._offset_index_size); |
1131 | 7 | Slice res(off_index_buff.data(), page_index._offset_index_size); |
1132 | 7 | size_t bytes_read = 0; |
1133 | 7 | { |
1134 | 7 | SCOPED_RAW_TIMER(&_reader_statistics.read_page_index_time); |
1135 | 7 | RETURN_IF_ERROR(_tracing_file_reader->read_at(page_index._offset_index_start, res, |
1136 | 7 | &bytes_read, _io_ctx)); |
1137 | 7 | } |
1138 | 7 | _column_statistics.page_index_read_calls++; |
1139 | 7 | _col_offsets.clear(); |
1140 | | |
1141 | 15 | for (auto parquet_col_id : parquet_col_ids) { |
1142 | 15 | auto& chunk = row_group.columns[parquet_col_id]; |
1143 | 15 | if (chunk.offset_index_length == 0) [[unlikely]] { |
1144 | 0 | continue; |
1145 | 0 | } |
1146 | 15 | tparquet::OffsetIndex offset_index; |
1147 | 15 | SCOPED_RAW_TIMER(&_reader_statistics.parse_page_index_time); |
1148 | 15 | RETURN_IF_ERROR( |
1149 | 15 | page_index.parse_offset_index(chunk, off_index_buff.data(), &offset_index)); |
1150 | 15 | _col_offsets[parquet_col_id] = offset_index; |
1151 | 15 | } |
1152 | 7 | return Status::OK(); |
1153 | 7 | }; |
1154 | | |
1155 | | // from https://github.com/apache/doris/pull/55795 |
1156 | 7 | RETURN_IF_ERROR(parse_offset_index()); |
1157 | | |
1158 | | // Check if page index is needed for min-max or expr-zonemap filter. |
1159 | 7 | const bool has_expr_zonemap_filter = |
1160 | 7 | config::enable_expr_zonemap_filter && !_lazy_read_ctx.conjuncts.empty(); |
1161 | 7 | if (!_enable_filter_by_min_max || (push_down_pred.empty() && !has_expr_zonemap_filter)) { |
1162 | 6 | read_whole_row_group(); |
1163 | 6 | return Status::OK(); |
1164 | 6 | } |
1165 | | |
1166 | | // read column index. |
1167 | 1 | std::vector<uint8_t> col_index_buff(page_index._column_index_size); |
1168 | 1 | size_t bytes_read = 0; |
1169 | 1 | Slice result(col_index_buff.data(), page_index._column_index_size); |
1170 | 1 | { |
1171 | 1 | SCOPED_RAW_TIMER(&_reader_statistics.read_page_index_time); |
1172 | 1 | RETURN_IF_ERROR(_tracing_file_reader->read_at(page_index._column_index_start, result, |
1173 | 1 | &bytes_read, _io_ctx)); |
1174 | 1 | } |
1175 | 1 | _column_statistics.page_index_read_calls++; |
1176 | | |
1177 | 1 | SCOPED_RAW_TIMER(&_reader_statistics.page_index_filter_time); |
1178 | | |
1179 | | // Construct a cacheable page index structure to avoid repeatedly reading the page index of the same column. |
1180 | 1 | ParquetPredicate::CachedPageIndexStat cached_page_index; |
1181 | 1 | cached_page_index.ctz = _ctz; |
1182 | 1 | std::function<bool(ParquetPredicate::PageIndexStat**, int)> get_stat_func = |
1183 | 1 | [&](ParquetPredicate::PageIndexStat** ans, const int cid) -> bool { |
1184 | 1 | if (cached_page_index.stats.contains(cid)) { |
1185 | 0 | *ans = &cached_page_index.stats[cid]; |
1186 | 0 | return (*ans)->available; |
1187 | 0 | } |
1188 | 1 | cached_page_index.stats.emplace(cid, ParquetPredicate::PageIndexStat {}); |
1189 | 1 | auto& sig_stat = cached_page_index.stats[cid]; |
1190 | | |
1191 | 1 | auto* slot = _tuple_descriptor->slots()[cid]; |
1192 | 1 | if (!_table_info_node_ptr->children_column_exists(slot->col_name())) { |
1193 | | // table column not exist in file, may be schema change. |
1194 | 0 | return false; |
1195 | 0 | } |
1196 | | |
1197 | 1 | const auto& file_col_name = |
1198 | 1 | _table_info_node_ptr->children_file_column_name(slot->col_name()); |
1199 | 1 | const FieldSchema* col_schema = _file_metadata->schema().get_column(file_col_name); |
1200 | 1 | int parquet_col_id = col_schema->physical_column_index; |
1201 | | |
1202 | 1 | if (parquet_col_id < 0) { |
1203 | | // complex type, not support page index yet. |
1204 | 0 | return false; |
1205 | 0 | } |
1206 | 1 | if (!_col_offsets.contains(parquet_col_id)) { |
1207 | | // If the file contains partition columns and the query applies filters on those |
1208 | | // partition columns, then reading the page index is unnecessary. |
1209 | 0 | return false; |
1210 | 0 | } |
1211 | | |
1212 | 1 | auto& column_chunk = row_group.columns[parquet_col_id]; |
1213 | 1 | if (column_chunk.column_index_length == 0 || column_chunk.offset_index_length == 0) { |
1214 | | // column no page index. |
1215 | 0 | return false; |
1216 | 0 | } |
1217 | | |
1218 | 1 | tparquet::ColumnIndex column_index; |
1219 | 1 | { |
1220 | 1 | SCOPED_RAW_TIMER(&_reader_statistics.parse_page_index_time); |
1221 | 1 | RETURN_IF_ERROR(page_index.parse_column_index(column_chunk, col_index_buff.data(), |
1222 | 1 | &column_index)); |
1223 | 1 | } |
1224 | 1 | const int64_t num_of_pages = column_index.null_pages.size(); |
1225 | 1 | if (num_of_pages <= 0) [[unlikely]] { |
1226 | | // no page. (maybe this row group no data.) |
1227 | 0 | return false; |
1228 | 0 | } |
1229 | 1 | DCHECK_EQ(column_index.min_values.size(), column_index.max_values.size()); |
1230 | 1 | if (!column_index.__isset.null_counts) { |
1231 | | // not set null or null counts; |
1232 | 0 | return false; |
1233 | 0 | } |
1234 | | |
1235 | 1 | auto& offset_index = _col_offsets[parquet_col_id]; |
1236 | 1 | const auto& page_locations = offset_index.page_locations; |
1237 | | |
1238 | 1 | sig_stat.col_schema = col_schema; |
1239 | 1 | sig_stat.num_of_pages = num_of_pages; |
1240 | 1 | sig_stat.encoded_min_value = column_index.min_values; |
1241 | 1 | sig_stat.encoded_max_value = column_index.max_values; |
1242 | 1 | sig_stat.is_all_null.resize(num_of_pages); |
1243 | 1 | sig_stat.has_null.resize(num_of_pages); |
1244 | 1 | sig_stat.ranges.resize(num_of_pages); |
1245 | | |
1246 | 2 | for (int page_id = 0; page_id < num_of_pages; page_id++) { |
1247 | 1 | sig_stat.is_all_null[page_id] = column_index.null_pages[page_id]; |
1248 | 1 | sig_stat.has_null[page_id] = column_index.null_counts[page_id] > 0; |
1249 | | |
1250 | 1 | int64_t from = page_locations[page_id].first_row_index; |
1251 | 1 | int64_t to = 0; |
1252 | 1 | if (page_id == page_locations.size() - 1) { |
1253 | 1 | to = row_group_index.last_row; |
1254 | 1 | } else { |
1255 | 0 | to = page_locations[page_id + 1].first_row_index; |
1256 | 0 | } |
1257 | 1 | sig_stat.ranges[page_id] = RowRange {from, to}; |
1258 | 1 | } |
1259 | | |
1260 | 1 | sig_stat.available = true; |
1261 | 1 | *ans = &sig_stat; |
1262 | 1 | return true; |
1263 | 1 | }; |
1264 | 1 | cached_page_index.row_group_range = {0, row_group.num_rows}; |
1265 | 1 | cached_page_index.get_stat_func = get_stat_func; |
1266 | | |
1267 | 1 | candidate_row_ranges->add({0, row_group.num_rows}); |
1268 | 1 | for (const auto& predicate : push_down_pred) { |
1269 | 0 | RowRanges tmp_row_range; |
1270 | 0 | if (!predicate->evaluate_and(&cached_page_index, &tmp_row_range)) { |
1271 | | // no need read this row group. |
1272 | 0 | candidate_row_ranges->clear(); |
1273 | 0 | return Status::OK(); |
1274 | 0 | } |
1275 | 0 | RowRanges::ranges_intersection(*candidate_row_ranges, tmp_row_range, candidate_row_ranges); |
1276 | 0 | } |
1277 | 1 | RETURN_IF_ERROR(_process_expr_zonemap_page_filter(&cached_page_index, candidate_row_ranges)); |
1278 | 1 | return Status::OK(); |
1279 | 1 | } |
1280 | | |
1281 | | Status ParquetReader::_process_expr_zonemap_page_filter( |
1282 | 8 | ParquetPredicate::CachedPageIndexStat* cached_page_index, RowRanges* candidate_row_ranges) { |
1283 | 8 | DORIS_CHECK(cached_page_index != nullptr); |
1284 | 8 | DORIS_CHECK(candidate_row_ranges != nullptr); |
1285 | 8 | const auto& all_conjuncts = _lazy_read_ctx.conjuncts; |
1286 | 8 | if (!config::enable_expr_zonemap_filter || all_conjuncts.empty() || |
1287 | 8 | candidate_row_ranges->is_empty()) { |
1288 | 2 | return Status::OK(); |
1289 | 2 | } |
1290 | | |
1291 | 6 | std::unordered_map<int, VExprContextSPtrs> ctxs_by_column; |
1292 | 9 | for (const auto& conjunct : all_conjuncts) { |
1293 | 9 | if (conjunct == nullptr || conjunct->root() == nullptr) { |
1294 | 0 | continue; |
1295 | 0 | } |
1296 | 9 | std::set<int> column_ids; |
1297 | 9 | conjunct->root()->collect_slot_column_ids(column_ids); |
1298 | 9 | if (column_ids.size() == 1 && conjunct->root()->can_evaluate_zonemap_filter()) { |
1299 | 8 | ctxs_by_column[*column_ids.begin()].emplace_back(conjunct); |
1300 | 8 | } |
1301 | 9 | } |
1302 | | |
1303 | 8 | for (const auto& [cid, conjuncts] : ctxs_by_column) { |
1304 | 8 | if (cid < 0 || cid >= _tuple_descriptor->slots().size()) { |
1305 | 1 | continue; |
1306 | 1 | } |
1307 | 7 | auto* slot = _tuple_descriptor->slots()[cid]; |
1308 | 7 | if (!_exists_in_file(slot->col_name()) || !_type_matches(cid)) { |
1309 | 0 | continue; |
1310 | 0 | } |
1311 | 7 | ParquetPredicate::PageIndexStat* stat = nullptr; |
1312 | 7 | if (!cached_page_index->get_stat_func(&stat, cid) || stat == nullptr || !stat->available) { |
1313 | 1 | continue; |
1314 | 1 | } |
1315 | 6 | RowRanges expr_ranges; |
1316 | 6 | ZoneMapEvalStats page_stats; |
1317 | 20 | for (int64_t page_id = 0; page_id < stat->num_of_pages; ++page_id) { |
1318 | 14 | DORIS_CHECK(page_id < stat->ranges.size()); |
1319 | 14 | DORIS_CHECK(page_id < stat->has_null.size()); |
1320 | 14 | DORIS_CHECK(page_id < stat->is_all_null.size()); |
1321 | 14 | const auto& page_range = stat->ranges[page_id]; |
1322 | 14 | DORIS_CHECK(page_range.is_valid()); |
1323 | | |
1324 | 14 | ZoneMapEvalContext ctx; |
1325 | 14 | ZoneMapEvalContext::SlotZoneMap slot_zone_map; |
1326 | 14 | slot_zone_map.data_type = slot->type(); |
1327 | 14 | segment_v2::ZoneMap zone_map; |
1328 | 14 | zone_map.has_null = stat->has_null[page_id]; |
1329 | 14 | zone_map.has_not_null = !stat->is_all_null[page_id]; |
1330 | 14 | if (!stat->is_all_null[page_id]) { |
1331 | 13 | DORIS_CHECK(page_id < stat->encoded_min_value.size()); |
1332 | 13 | DORIS_CHECK(page_id < stat->encoded_max_value.size()); |
1333 | 13 | Status status = ParquetPredicate::parse_min_max_value( |
1334 | 13 | stat->col_schema, stat->encoded_min_value[page_id], |
1335 | 13 | stat->encoded_max_value[page_id], *cached_page_index->ctz, |
1336 | 13 | &zone_map.min_value, &zone_map.max_value); |
1337 | 13 | if (status.ok()) { |
1338 | 13 | slot_zone_map.zone_map = std::move(zone_map); |
1339 | 13 | } |
1340 | 13 | } else { |
1341 | 1 | slot_zone_map.zone_map = std::move(zone_map); |
1342 | 1 | } |
1343 | 14 | ctx.slots.emplace(cid, std::move(slot_zone_map)); |
1344 | 14 | const auto result = VExprContext::evaluate_zonemap_filter(conjuncts, ctx); |
1345 | 14 | page_stats.merge_page_eval_stats(ctx.stats); |
1346 | 14 | if (result != ZoneMapFilterResult::kNoMatch) { |
1347 | 8 | expr_ranges.add(page_range); |
1348 | 8 | } |
1349 | 14 | } |
1350 | 6 | page_stats.accumulate_to(&_reader_statistics); |
1351 | 6 | RowRanges::ranges_intersection(*candidate_row_ranges, expr_ranges, candidate_row_ranges); |
1352 | 6 | if (candidate_row_ranges->is_empty()) { |
1353 | 1 | return Status::OK(); |
1354 | 1 | } |
1355 | 6 | } |
1356 | 5 | return Status::OK(); |
1357 | 6 | } |
1358 | | |
1359 | | Status ParquetReader::_process_min_max_bloom_filter( |
1360 | | const RowGroupReader::RowGroupIndex& row_group_index, const tparquet::RowGroup& row_group, |
1361 | | const std::vector<std::unique_ptr<MutilColumnBlockPredicate>>& push_down_pred, |
1362 | 187 | RowRanges* row_ranges) { |
1363 | 187 | SCOPED_RAW_TIMER(&_reader_statistics.row_group_filter_time); |
1364 | 187 | if (!_filter_groups) { |
1365 | | // No row group filtering is needed; |
1366 | | // for example, Iceberg reads position delete files. |
1367 | 1 | row_ranges->add({0, row_group.num_rows}); |
1368 | 1 | return Status::OK(); |
1369 | 1 | } |
1370 | | |
1371 | 186 | if (_read_by_rows) { |
1372 | 32 | auto group_start = row_group_index.first_row; |
1373 | 32 | auto group_end = row_group_index.last_row; |
1374 | | |
1375 | 77 | while (!_row_ids.empty()) { |
1376 | 50 | auto v = _row_ids.front(); |
1377 | 50 | if (v < group_start) { |
1378 | 0 | continue; |
1379 | 50 | } else if (v < group_end) { |
1380 | 45 | row_ranges->add(RowRange {v - group_start, v - group_start + 1}); |
1381 | 45 | _row_ids.pop_front(); |
1382 | 45 | } else { |
1383 | 5 | break; |
1384 | 5 | } |
1385 | 50 | } |
1386 | 154 | } else { |
1387 | 154 | bool filter_this_row_group = false; |
1388 | 154 | bool filtered_by_min_max = false; |
1389 | 154 | bool filtered_by_bloom_filter = false; |
1390 | 154 | RETURN_IF_ERROR(_process_column_stat_filter(row_group, push_down_pred, |
1391 | 154 | &filter_this_row_group, &filtered_by_min_max, |
1392 | 154 | &filtered_by_bloom_filter)); |
1393 | 154 | if (!filter_this_row_group) { |
1394 | 154 | RETURN_IF_ERROR(_process_expr_zonemap_filter(row_group, &filter_this_row_group)); |
1395 | 154 | } |
1396 | | // Update statistics based on filter type |
1397 | 154 | if (filter_this_row_group) { |
1398 | 4 | if (filtered_by_min_max) { |
1399 | 0 | _reader_statistics.filtered_row_groups_by_min_max++; |
1400 | 0 | } |
1401 | 4 | if (filtered_by_bloom_filter) { |
1402 | 0 | _reader_statistics.filtered_row_groups_by_bloom_filter++; |
1403 | 0 | } |
1404 | 4 | } |
1405 | | |
1406 | 154 | if (!filter_this_row_group) { |
1407 | 150 | RETURN_IF_ERROR(_process_page_index_filter(row_group, row_group_index, push_down_pred, |
1408 | 150 | row_ranges)); |
1409 | 150 | } |
1410 | 154 | } |
1411 | | |
1412 | 186 | return Status::OK(); |
1413 | 186 | } |
1414 | | |
1415 | | Status ParquetReader::_process_column_stat_filter( |
1416 | | const tparquet::RowGroup& row_group, |
1417 | | const std::vector<std::unique_ptr<MutilColumnBlockPredicate>>& push_down_pred, |
1418 | 156 | bool* filter_group, bool* filtered_by_min_max, bool* filtered_by_bloom_filter) { |
1419 | | // If both filters are disabled, skip filtering |
1420 | 156 | if (!_enable_filter_by_min_max && !_enable_filter_by_bloom_filter) { |
1421 | 0 | return Status::OK(); |
1422 | 0 | } |
1423 | | |
1424 | | // Cache bloom filters for each column to avoid reading the same bloom filter multiple times |
1425 | | // when there are multiple predicates on the same column |
1426 | 156 | std::unordered_map<int, std::unique_ptr<ParquetBlockSplitBloomFilter>> bloom_filter_cache; |
1427 | | |
1428 | | // Initialize output parameters |
1429 | 156 | *filtered_by_min_max = false; |
1430 | 156 | *filtered_by_bloom_filter = false; |
1431 | | |
1432 | 156 | for (const auto& predicate : _push_down_predicates) { |
1433 | 9 | std::function<bool(ParquetPredicate::ColumnStat*, int)> get_stat_func = |
1434 | 11 | [&](ParquetPredicate::ColumnStat* stat, const int cid) { |
1435 | | // Check if min-max filter is enabled |
1436 | 11 | if (!_enable_filter_by_min_max) { |
1437 | 0 | return false; |
1438 | 0 | } |
1439 | 11 | auto* slot = _tuple_descriptor->slots()[cid]; |
1440 | 11 | if (!_table_info_node_ptr->children_column_exists(slot->col_name())) { |
1441 | 0 | return false; |
1442 | 0 | } |
1443 | 11 | const auto& file_col_name = |
1444 | 11 | _table_info_node_ptr->children_file_column_name(slot->col_name()); |
1445 | 11 | const FieldSchema* col_schema = |
1446 | 11 | _file_metadata->schema().get_column(file_col_name); |
1447 | 11 | int parquet_col_id = col_schema->physical_column_index; |
1448 | 11 | auto meta_data = row_group.columns[parquet_col_id].meta_data; |
1449 | 11 | stat->col_schema = col_schema; |
1450 | 11 | return ParquetPredicate::read_column_stats(col_schema, meta_data, |
1451 | 11 | &_ignored_stats, |
1452 | 11 | _t_metadata->created_by, stat) |
1453 | 11 | .ok(); |
1454 | 11 | }; |
1455 | 9 | std::function<bool(ParquetPredicate::ColumnStat*, int)> get_bloom_filter_func = |
1456 | 9 | [&](ParquetPredicate::ColumnStat* stat, const int cid) { |
1457 | 1 | auto* slot = _tuple_descriptor->slots()[cid]; |
1458 | 1 | if (!_table_info_node_ptr->children_column_exists(slot->col_name())) { |
1459 | 0 | return false; |
1460 | 0 | } |
1461 | 1 | const auto& file_col_name = |
1462 | 1 | _table_info_node_ptr->children_file_column_name(slot->col_name()); |
1463 | 1 | const FieldSchema* col_schema = |
1464 | 1 | _file_metadata->schema().get_column(file_col_name); |
1465 | 1 | int parquet_col_id = col_schema->physical_column_index; |
1466 | 1 | auto meta_data = row_group.columns[parquet_col_id].meta_data; |
1467 | 1 | if (!meta_data.__isset.bloom_filter_offset) { |
1468 | 1 | return false; |
1469 | 1 | } |
1470 | 0 | auto primitive_type = |
1471 | 0 | remove_nullable(col_schema->data_type)->get_primitive_type(); |
1472 | 0 | if (!ParquetPredicate::bloom_filter_supported(primitive_type)) { |
1473 | 0 | return false; |
1474 | 0 | } |
1475 | | |
1476 | | // Check if bloom filter is enabled |
1477 | 0 | if (!_enable_filter_by_bloom_filter) { |
1478 | 0 | return false; |
1479 | 0 | } |
1480 | | |
1481 | | // Check cache first |
1482 | 0 | auto cache_iter = bloom_filter_cache.find(parquet_col_id); |
1483 | 0 | if (cache_iter != bloom_filter_cache.end()) { |
1484 | | // Bloom filter already loaded for this column, reuse it |
1485 | 0 | stat->bloom_filter = std::move(cache_iter->second); |
1486 | 0 | bloom_filter_cache.erase(cache_iter); |
1487 | 0 | return stat->bloom_filter != nullptr; |
1488 | 0 | } |
1489 | | |
1490 | 0 | if (!stat->bloom_filter) { |
1491 | 0 | SCOPED_RAW_TIMER(&_reader_statistics.bloom_filter_read_time); |
1492 | 0 | auto st = ParquetPredicate::read_bloom_filter( |
1493 | 0 | meta_data, _tracing_file_reader, _io_ctx, stat); |
1494 | 0 | if (!st.ok()) { |
1495 | 0 | LOG(WARNING) << "Failed to read bloom filter for column " |
1496 | 0 | << col_schema->name << " in file " << _scan_range.path |
1497 | 0 | << ", status: " << st.to_string(); |
1498 | 0 | stat->bloom_filter.reset(); |
1499 | 0 | return false; |
1500 | 0 | } |
1501 | 0 | } |
1502 | 0 | return stat->bloom_filter != nullptr; |
1503 | 0 | }; |
1504 | 9 | ParquetPredicate::ColumnStat stat; |
1505 | 9 | stat.ctz = _ctz; |
1506 | 9 | stat.get_stat_func = &get_stat_func; |
1507 | 9 | stat.get_bloom_filter_func = &get_bloom_filter_func; |
1508 | | |
1509 | 9 | if (!predicate->evaluate_and(&stat)) { |
1510 | 1 | *filter_group = true; |
1511 | | |
1512 | | // Track which filter was used for filtering |
1513 | | // If bloom filter was loaded, it means bloom filter was used |
1514 | 1 | if (stat.bloom_filter) { |
1515 | 0 | *filtered_by_bloom_filter = true; |
1516 | 0 | } |
1517 | | // If col_schema was set but no bloom filter, it means min-max stats were used |
1518 | 1 | if (stat.col_schema && !stat.bloom_filter) { |
1519 | 1 | *filtered_by_min_max = true; |
1520 | 1 | } |
1521 | | |
1522 | 1 | return Status::OK(); |
1523 | 1 | } |
1524 | | |
1525 | | // After evaluating, if the bloom filter was used, cache it for subsequent predicates |
1526 | 8 | if (stat.bloom_filter) { |
1527 | | // Find the column id for caching |
1528 | 0 | for (auto* slot : _tuple_descriptor->slots()) { |
1529 | 0 | if (_table_info_node_ptr->children_column_exists(slot->col_name())) { |
1530 | 0 | const auto& file_col_name = |
1531 | 0 | _table_info_node_ptr->children_file_column_name(slot->col_name()); |
1532 | 0 | const FieldSchema* col_schema = |
1533 | 0 | _file_metadata->schema().get_column(file_col_name); |
1534 | 0 | int parquet_col_id = col_schema->physical_column_index; |
1535 | 0 | if (stat.col_schema == col_schema) { |
1536 | 0 | bloom_filter_cache[parquet_col_id] = std::move(stat.bloom_filter); |
1537 | 0 | break; |
1538 | 0 | } |
1539 | 0 | } |
1540 | 0 | } |
1541 | 0 | } |
1542 | 8 | } |
1543 | | |
1544 | | // Update filter statistics if this row group was not filtered |
1545 | | // The statistics will be updated in _init_row_groups when filter_group is true |
1546 | 155 | return Status::OK(); |
1547 | 156 | } |
1548 | | |
1549 | | Status ParquetReader::_process_expr_zonemap_filter(const tparquet::RowGroup& row_group, |
1550 | 156 | bool* filter_group) { |
1551 | 156 | DORIS_CHECK(filter_group != nullptr); |
1552 | 156 | const auto& all_conjuncts = _lazy_read_ctx.conjuncts; |
1553 | 156 | if (!config::enable_expr_zonemap_filter || all_conjuncts.empty() || |
1554 | 156 | !_enable_filter_by_min_max) { |
1555 | 140 | return Status::OK(); |
1556 | 140 | } |
1557 | | |
1558 | 16 | std::set<int> column_ids; |
1559 | 22 | for (const auto& conjunct : all_conjuncts) { |
1560 | 22 | if (conjunct->root() != nullptr && conjunct->root()->can_evaluate_zonemap_filter()) { |
1561 | 22 | conjunct->root()->collect_slot_column_ids(column_ids); |
1562 | 22 | } |
1563 | 22 | } |
1564 | 16 | if (column_ids.empty()) { |
1565 | 0 | return Status::OK(); |
1566 | 0 | } |
1567 | | |
1568 | 16 | ZoneMapEvalContext ctx; |
1569 | 22 | for (const int cid : column_ids) { |
1570 | 22 | if (cid < 0 || cid >= _tuple_descriptor->slots().size()) { |
1571 | 0 | continue; |
1572 | 0 | } |
1573 | 22 | auto* slot = _tuple_descriptor->slots()[cid]; |
1574 | 22 | ZoneMapEvalContext::SlotZoneMap slot_zone_map; |
1575 | 22 | slot_zone_map.data_type = slot->type(); |
1576 | 22 | if (!_exists_in_file(slot->col_name()) || !_type_matches(cid)) { |
1577 | 6 | ctx.slots.emplace(cid, std::move(slot_zone_map)); |
1578 | 6 | continue; |
1579 | 6 | } |
1580 | 16 | const auto& file_col_name = |
1581 | 16 | _table_info_node_ptr->children_file_column_name(slot->col_name()); |
1582 | 16 | const FieldSchema* col_schema = _file_metadata->schema().get_column(file_col_name); |
1583 | 16 | int parquet_col_id = col_schema->physical_column_index; |
1584 | 16 | if (parquet_col_id < 0) { |
1585 | | // Complex parent fields do not map to a physical Parquet column. |
1586 | 1 | ctx.slots.emplace(cid, std::move(slot_zone_map)); |
1587 | 1 | continue; |
1588 | 1 | } |
1589 | 15 | const auto& meta_data = row_group.columns[parquet_col_id].meta_data; |
1590 | | |
1591 | 15 | ParquetPredicate::ColumnStat stat; |
1592 | 15 | stat.ctz = _ctz; |
1593 | 15 | auto status = ParquetPredicate::read_column_stats(col_schema, meta_data, &_ignored_stats, |
1594 | 15 | _t_metadata->created_by, &stat); |
1595 | 15 | if (!status.ok()) { |
1596 | 1 | ctx.slots.emplace(cid, std::move(slot_zone_map)); |
1597 | 1 | continue; |
1598 | 1 | } |
1599 | | |
1600 | 14 | segment_v2::ZoneMap zone_map; |
1601 | 14 | zone_map.has_null = stat.has_null; |
1602 | 14 | zone_map.has_not_null = !stat.is_all_null; |
1603 | 14 | if (!stat.is_all_null) { |
1604 | 12 | status = ParquetPredicate::parse_min_max_value( |
1605 | 12 | col_schema, stat.encoded_min_value, stat.encoded_max_value, *_ctz, |
1606 | 12 | &zone_map.min_value, &zone_map.max_value); |
1607 | 12 | if (!status.ok()) { |
1608 | 0 | ctx.slots.emplace(cid, std::move(slot_zone_map)); |
1609 | 0 | continue; |
1610 | 0 | } |
1611 | 12 | } |
1612 | 14 | slot_zone_map.zone_map = std::move(zone_map); |
1613 | 14 | ctx.slots.emplace(cid, std::move(slot_zone_map)); |
1614 | 14 | } |
1615 | | |
1616 | 16 | const auto result = VExprContext::evaluate_zonemap_filter(all_conjuncts, ctx); |
1617 | 16 | ctx.stats.accumulate_to(&_reader_statistics); |
1618 | 16 | if (result == ZoneMapFilterResult::kNoMatch) { |
1619 | 4 | *filter_group = true; |
1620 | 4 | ++_reader_statistics.filtered_row_groups_by_expr_zonemap; |
1621 | 4 | } |
1622 | 16 | return Status::OK(); |
1623 | 16 | } |
1624 | | |
1625 | 390 | int64_t ParquetReader::_get_column_start_offset(const tparquet::ColumnMetaData& column) const { |
1626 | 390 | return has_dict_page(column) ? column.dictionary_page_offset : column.data_page_offset; |
1627 | 390 | } |
1628 | | |
1629 | 148 | void ParquetReader::_collect_profile() { |
1630 | 148 | if (_profile == nullptr) { |
1631 | 0 | return; |
1632 | 0 | } |
1633 | | |
1634 | 148 | if (_current_group_reader != nullptr) { |
1635 | 148 | _current_group_reader->collect_profile_before_close(); |
1636 | 148 | } |
1637 | 148 | COUNTER_UPDATE(_parquet_profile.filtered_row_groups, _reader_statistics.filtered_row_groups); |
1638 | 148 | COUNTER_UPDATE(_parquet_profile.filtered_row_groups_by_min_max, |
1639 | 148 | _reader_statistics.filtered_row_groups_by_min_max); |
1640 | 148 | COUNTER_UPDATE(_parquet_profile.filtered_row_groups_by_expr_zonemap, |
1641 | 148 | _reader_statistics.filtered_row_groups_by_expr_zonemap); |
1642 | 148 | COUNTER_UPDATE(_parquet_profile.filtered_row_groups_by_bloom_filter, |
1643 | 148 | _reader_statistics.filtered_row_groups_by_bloom_filter); |
1644 | 148 | COUNTER_UPDATE(_parquet_profile.to_read_row_groups, _reader_statistics.read_row_groups); |
1645 | 148 | COUNTER_UPDATE(_parquet_profile.total_row_groups, _total_groups); |
1646 | 148 | COUNTER_UPDATE(_parquet_profile.filtered_group_rows, _reader_statistics.filtered_group_rows); |
1647 | 148 | COUNTER_UPDATE(_parquet_profile.filtered_page_rows, _reader_statistics.filtered_page_rows); |
1648 | 148 | COUNTER_UPDATE(_parquet_profile.lazy_read_filtered_rows, |
1649 | 148 | _reader_statistics.lazy_read_filtered_rows); |
1650 | 148 | COUNTER_UPDATE(_parquet_profile.filtered_bytes, _reader_statistics.filtered_bytes); |
1651 | 148 | COUNTER_UPDATE(_parquet_profile.raw_rows_read, _reader_statistics.read_rows); |
1652 | 148 | COUNTER_UPDATE(_parquet_profile.column_read_time, _reader_statistics.column_read_time); |
1653 | 148 | COUNTER_UPDATE(_parquet_profile.parse_meta_time, _reader_statistics.parse_meta_time); |
1654 | 148 | COUNTER_UPDATE(_parquet_profile.parse_footer_time, _reader_statistics.parse_footer_time); |
1655 | 148 | COUNTER_UPDATE(_parquet_profile.file_reader_create_time, |
1656 | 148 | _reader_statistics.file_reader_create_time); |
1657 | 148 | COUNTER_UPDATE(_parquet_profile.open_file_num, _reader_statistics.open_file_num); |
1658 | 148 | COUNTER_UPDATE(_parquet_profile.page_index_filter_time, |
1659 | 148 | _reader_statistics.page_index_filter_time); |
1660 | 148 | COUNTER_UPDATE(_parquet_profile.read_page_index_time, _reader_statistics.read_page_index_time); |
1661 | 148 | COUNTER_UPDATE(_parquet_profile.parse_page_index_time, |
1662 | 148 | _reader_statistics.parse_page_index_time); |
1663 | 148 | COUNTER_UPDATE(_parquet_profile.row_group_filter_time, |
1664 | 148 | _reader_statistics.row_group_filter_time); |
1665 | 148 | COUNTER_UPDATE(_parquet_profile.expr_zonemap_unsupported, |
1666 | 148 | _reader_statistics.expr_zonemap_unsupported_exprs); |
1667 | 148 | COUNTER_UPDATE(_parquet_profile.expr_zonemap_type_mismatch, |
1668 | 148 | _reader_statistics.expr_zonemap_type_mismatch); |
1669 | 148 | COUNTER_UPDATE(_parquet_profile.in_zonemap_point_check, |
1670 | 148 | _reader_statistics.in_zonemap_point_check_count); |
1671 | 148 | COUNTER_UPDATE(_parquet_profile.in_zonemap_range_only, |
1672 | 148 | _reader_statistics.in_zonemap_range_only_count); |
1673 | 148 | COUNTER_UPDATE(_parquet_profile.in_zonemap_point_check_skipped, |
1674 | 148 | _reader_statistics.in_zonemap_point_check_skipped_due_to_threshold); |
1675 | 148 | COUNTER_UPDATE(_parquet_profile.file_footer_read_calls, |
1676 | 148 | _reader_statistics.file_footer_read_calls); |
1677 | 148 | COUNTER_UPDATE(_parquet_profile.file_footer_hit_cache, |
1678 | 148 | _reader_statistics.file_footer_hit_cache); |
1679 | | |
1680 | 148 | COUNTER_UPDATE(_parquet_profile.skip_page_header_num, _column_statistics.skip_page_header_num); |
1681 | 148 | COUNTER_UPDATE(_parquet_profile.parse_page_header_num, |
1682 | 148 | _column_statistics.parse_page_header_num); |
1683 | 148 | COUNTER_UPDATE(_parquet_profile.predicate_filter_time, |
1684 | 148 | _reader_statistics.predicate_filter_time); |
1685 | 148 | COUNTER_UPDATE(_parquet_profile.dict_filter_rewrite_time, |
1686 | 148 | _reader_statistics.dict_filter_rewrite_time); |
1687 | 148 | COUNTER_UPDATE(_parquet_profile.convert_time, _column_statistics.convert_time); |
1688 | 148 | COUNTER_UPDATE(_parquet_profile.bloom_filter_read_time, |
1689 | 148 | _reader_statistics.bloom_filter_read_time); |
1690 | 148 | COUNTER_UPDATE(_parquet_profile.page_index_read_calls, |
1691 | 148 | _column_statistics.page_index_read_calls); |
1692 | 148 | COUNTER_UPDATE(_parquet_profile.decompress_time, _column_statistics.decompress_time); |
1693 | 148 | COUNTER_UPDATE(_parquet_profile.decompress_cnt, _column_statistics.decompress_cnt); |
1694 | 148 | COUNTER_UPDATE(_parquet_profile.page_read_counter, _column_statistics.page_read_counter); |
1695 | 148 | COUNTER_UPDATE(_parquet_profile.page_cache_write_counter, |
1696 | 148 | _column_statistics.page_cache_write_counter); |
1697 | 148 | COUNTER_UPDATE(_parquet_profile.page_cache_compressed_write_counter, |
1698 | 148 | _column_statistics.page_cache_compressed_write_counter); |
1699 | 148 | COUNTER_UPDATE(_parquet_profile.page_cache_decompressed_write_counter, |
1700 | 148 | _column_statistics.page_cache_decompressed_write_counter); |
1701 | 148 | COUNTER_UPDATE(_parquet_profile.page_cache_hit_counter, |
1702 | 148 | _column_statistics.page_cache_hit_counter); |
1703 | 148 | COUNTER_UPDATE(_parquet_profile.page_cache_missing_counter, |
1704 | 148 | _column_statistics.page_cache_missing_counter); |
1705 | 148 | COUNTER_UPDATE(_parquet_profile.page_cache_compressed_hit_counter, |
1706 | 148 | _column_statistics.page_cache_compressed_hit_counter); |
1707 | 148 | COUNTER_UPDATE(_parquet_profile.page_cache_decompressed_hit_counter, |
1708 | 148 | _column_statistics.page_cache_decompressed_hit_counter); |
1709 | 148 | COUNTER_UPDATE(_parquet_profile.decode_header_time, _column_statistics.decode_header_time); |
1710 | 148 | COUNTER_UPDATE(_parquet_profile.read_page_header_time, |
1711 | 148 | _column_statistics.read_page_header_time); |
1712 | 148 | COUNTER_UPDATE(_parquet_profile.decode_value_time, _column_statistics.decode_value_time); |
1713 | 148 | COUNTER_UPDATE(_parquet_profile.decode_dict_time, _column_statistics.decode_dict_time); |
1714 | 148 | COUNTER_UPDATE(_parquet_profile.decode_level_time, _column_statistics.decode_level_time); |
1715 | 148 | COUNTER_UPDATE(_parquet_profile.decode_null_map_time, _column_statistics.decode_null_map_time); |
1716 | 148 | } |
1717 | | |
1718 | 148 | void ParquetReader::_collect_profile_before_close() { |
1719 | 148 | _collect_profile(); |
1720 | 148 | } |
1721 | | |
1722 | | } // namespace doris |