Coverage Report

Created: 2026-07-02 23:26

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
be/src/format_v2/parquet/parquet_scan.h
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
//   http://www.apache.org/licenses/LICENSE-2.0
9
// Unless required by applicable law or agreed to in writing,
10
// software distributed under the License is distributed on an
11
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
12
// KIND, either express or implied.  See the License for the
13
// specific language governing permissions and limitations
14
// under the License.
15
16
#pragma once
17
18
#include <cstddef>
19
#include <cstdint>
20
#include <map>
21
#include <memory>
22
#include <optional>
23
#include <vector>
24
25
#include "common/status.h"
26
#include "core/column/column.h"
27
#include "format_v2/file_reader.h"
28
#include "format_v2/parquet/parquet_profile.h"
29
#include "format_v2/parquet/parquet_statistics.h"
30
#include "format_v2/parquet/reader/column_reader.h"
31
#include "format_v2/parquet/selection_vector.h"
32
#include "runtime/runtime_profile.h"
33
#include "storage/segment/condition_cache.h"
34
35
namespace parquet {
36
class FileMetaData;
37
class ParquetFileReader;
38
class RowGroupReader;
39
} // namespace parquet
40
41
namespace cctz {
42
class time_zone;
43
} // namespace cctz
44
45
namespace doris {
46
class Block;
47
48
namespace format {
49
struct FileScanRequest;
50
} // namespace format
51
} // namespace doris
52
53
namespace doris::format::parquet {
54
55
struct ParquetFileContext;
56
struct ParquetColumnSchema;
57
58
// ============================================================================
59
// ============================================================================
60
61
struct ParquetScanRange {
62
    int64_t start_offset = 0;
63
    int64_t size = -1;      // -1 means read the whole file
64
    int64_t file_size = -1; // -1 means unknown
65
};
66
67
struct RowGroupReadPlan {
68
    int row_group_id = -1;                 // row group id
69
    int64_t first_file_row = 0;            // first file row for this row group (0-based)
70
    int64_t row_group_rows = 0;            // row count of this row group
71
    std::vector<RowRange> selected_ranges; // row ranges to read after page-index pruning
72
    std::map<int, ParquetPageSkipPlan>
73
            page_skip_plans; // leaf_column_id -> data pages that can be skipped completely
74
};
75
76
struct RowGroupScanPlan {
77
    std::vector<RowGroupReadPlan> row_groups; // row groups selected after pruning
78
    ParquetPruningStats pruning_stats;        // pruning statistics
79
};
80
81
// ============================================================================
82
// ============================================================================
83
84
Status plan_parquet_row_groups(const ::parquet::FileMetaData& metadata,
85
                               ::parquet::ParquetFileReader* file_reader,
86
                               const std::vector<std::unique_ptr<ParquetColumnSchema>>& file_schema,
87
                               const format::FileScanRequest& request,
88
                               const ParquetScanRange& scan_range, bool enable_bloom_filter,
89
                               RowGroupScanPlan* plan, const cctz::time_zone* timezone = nullptr);
90
91
IColumn::Filter selection_to_filter(const SelectionVector& selection, uint16_t selected_rows,
92
                                    int64_t batch_rows);
93
94
Status execute_batch_filters(const format::FileScanRequest& request, int64_t batch_rows,
95
                             Block* file_block, SelectionVector* selection, uint16_t* selected_rows,
96
                             int64_t* conjunct_filtered_rows = nullptr);
97
98
// ============================================================================
99
// ============================================================================
100
//   while true:
101
//     3. read_current_row_group_batch(batch_rows)
102
// ============================================================================
103
class ParquetScanScheduler {
104
public:
105
    static constexpr int64_t DEFAULT_READ_BATCH_SIZE = 4096;
106
107
    void set_plan(RowGroupScanPlan plan);
108
104
    void set_page_skip_profile(ParquetPageSkipProfile page_skip_profile) {
109
104
        _page_skip_profile = page_skip_profile;
110
104
    }
111
104
    void set_scan_profile(ParquetScanProfile scan_profile) { _scan_profile = scan_profile; }
112
104
    void set_global_rowid_context(std::optional<format::GlobalRowIdContext> context) {
113
104
        _global_rowid_context = context;
114
104
    }
115
    void set_condition_cache_context(std::shared_ptr<ConditionCacheContext> ctx);
116
108
    void set_timezone(const cctz::time_zone* timezone) { _timezone = timezone; }
117
108
    void set_enable_strict_mode(bool enable_strict_mode) {
118
108
        _enable_strict_mode = enable_strict_mode;
119
108
    }
120
    // Upper scanner owns adaptive memory feedback; scheduler only applies the current row cap when
121
    // splitting selected row ranges into physical read batches.
122
108
    void set_batch_size(size_t batch_size) {
123
108
        _batch_size = batch_size == 0 ? 1 : static_cast<int64_t>(batch_size);
124
108
    }
125
    void reset();
126
104
    bool empty() const { return _row_group_plans.empty(); }
127
1
    int64_t condition_cache_filtered_rows() const { return _condition_cache_filtered_rows; }
128
177
    int64_t predicate_filtered_rows() const { return _predicate_filtered_rows; }
129
130
    Status read_next_batch(ParquetFileContext& file_context,
131
                           const std::vector<std::unique_ptr<ParquetColumnSchema>>& file_schema,
132
                           const format::FileScanRequest& request, Block* file_block, size_t* rows,
133
                           bool* eof);
134
135
private:
136
    void reset_current_row_group();
137
138
    Status open_next_row_group(ParquetFileContext& file_context,
139
                               const std::vector<std::unique_ptr<ParquetColumnSchema>>& file_schema,
140
                               const format::FileScanRequest& request, bool* has_row_group);
141
142
    Status skip_current_row_group_rows(int64_t rows);
143
144
    Status read_filter_columns(int64_t batch_rows, const format::FileScanRequest& request,
145
                               Block* file_block, SelectionVector* selection,
146
                               uint16_t* selected_rows, int64_t* conjunct_filtered_rows);
147
148
    Status read_current_row_group_batch(int64_t batch_rows, const format::FileScanRequest& request,
149
                                        int64_t batch_first_file_row, Block* file_block,
150
                                        size_t* rows);
151
152
    void mark_condition_cache_granules(const SelectionVector& selection, uint16_t selected_rows,
153
                                       int64_t batch_first_file_row);
154
155
    std::vector<RowGroupReadPlan> _row_group_plans; // row group queue to scan
156
    size_t _next_row_group_plan_idx = 0;            // index of the next row group to process
157
158
    std::shared_ptr<::parquet::RowGroupReader> _current_row_group; // Arrow RowGroup reader
159
    std::map<ColumnId, std::unique_ptr<ParquetColumnReader>>
160
            _current_predicate_columns; // predicate ColumnReaders
161
    std::map<ColumnId, std::unique_ptr<ParquetColumnReader>>
162
            _current_non_predicate_columns;   // non-predicate ColumnReaders
163
    int64_t _current_row_group_rows = 0;      // current row group row count
164
    int64_t _current_row_group_rows_read = 0; // rows read in the current row group (cursor)
165
    int64_t _current_row_group_first_row = 0; // first file row of the current row group
166
    std::vector<RowRange>
167
            _current_selected_ranges; // selected ranges for the current row group after page-index pruning
168
    size_t _current_range_idx = 0;        // current selected_range index
169
    int64_t _current_range_rows_read = 0; // rows read in the current range
170
171
    ParquetPageSkipProfile _page_skip_profile;
172
    ParquetScanProfile _scan_profile;
173
    std::optional<format::GlobalRowIdContext> _global_rowid_context;
174
    const cctz::time_zone* _timezone = nullptr;
175
    bool _enable_strict_mode = false;
176
    int64_t _batch_size = DEFAULT_READ_BATCH_SIZE;
177
    std::shared_ptr<ConditionCacheContext> _condition_cache_ctx;
178
    int64_t _condition_cache_filtered_rows = 0;
179
    int64_t _predicate_filtered_rows = 0;
180
};
181
182
} // namespace doris::format::parquet