Coverage Report

Created: 2026-10-20 22:38

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