Coverage Report

Created: 2026-09-29 18:23

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