Coverage Report

Created: 2026-10-26 08:40

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