Coverage Report

Created: 2026-10-22 05:32

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