Coverage Report

Created: 2026-10-28 12:14

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
be/src/format/table/iceberg_reader_mixin.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
//
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
#pragma once
19
20
#include <gen_cpp/ExternalTableSchema_types.h>
21
22
#include <algorithm>
23
#include <cstddef>
24
#include <cstdint>
25
#include <memory>
26
#include <string>
27
#include <unordered_map>
28
#include <vector>
29
30
#include "common/consts.h"
31
#include "common/status.h"
32
#include "core/block/block.h"
33
#include "core/column/column_dictionary.h"
34
#include "core/column/column_nullable.h"
35
#include "core/column/column_string.h"
36
#include "core/column/column_struct.h"
37
#include "core/data_type/data_type_number.h"
38
#include "core/data_type/data_type_string.h"
39
#include "core/data_type/data_type_struct.h"
40
#include "core/data_type/primitive_type.h"
41
#include "format/generic_reader.h"
42
#include "format/table/equality_delete.h"
43
#include "format/table/iceberg_default_value.h"
44
#include "format/table/iceberg_delete_file_reader_helper.h"
45
#include "format/table/iceberg_scan_semantics.h"
46
#include "format/table/table_schema_change_helper.h"
47
#include "runtime/runtime_profile.h"
48
#include "runtime/runtime_state.h"
49
#include "storage/olap_common.h"
50
#include "util/string_util.h"
51
52
namespace doris {
53
class TIcebergDeleteFileDesc;
54
} // namespace doris
55
56
namespace doris {
57
58
class ShardedKVCache;
59
60
// CRTP mixin for Iceberg reader functionality.
61
// BaseReader should be ParquetReader or OrcReader.
62
// Inherits BaseReader + TableSchemaChangeHelper, providing shared Iceberg logic
63
// (delete files, deletion vectors, equality delete, $row_id synthesis).
64
//
65
// Inheritance chain:
66
//   IcebergParquetReader -> IcebergReaderMixin<ParquetReader> -> ParquetReader -> GenericReader
67
//   IcebergOrcReader     -> IcebergReaderMixin<OrcReader>     -> OrcReader     -> GenericReader
68
template <typename BaseReader>
69
class IcebergReaderMixin : public BaseReader, public TableSchemaChangeHelper {
70
public:
71
    struct PositionDeleteRange {
72
        std::vector<std::string> data_file_path;
73
        std::vector<std::pair<int, int>> range;
74
    };
75
76
    // Forward BaseReader constructor arguments + Iceberg-specific kv_cache
77
    template <typename... Args>
78
    IcebergReaderMixin(ShardedKVCache* kv_cache, Args&&... args)
79
74
            : BaseReader(std::forward<Args>(args)...), _kv_cache(kv_cache) {
80
74
        static const char* iceberg_profile = "IcebergProfile";
81
74
        ADD_TIMER(this->get_profile(), iceberg_profile);
82
74
        _iceberg_profile.num_delete_files = ADD_CHILD_COUNTER(this->get_profile(), "NumDeleteFiles",
83
74
                                                              TUnit::UNIT, iceberg_profile);
84
74
        _iceberg_profile.num_delete_rows = ADD_CHILD_COUNTER(this->get_profile(), "NumDeleteRows",
85
74
                                                             TUnit::UNIT, iceberg_profile);
86
74
        _iceberg_profile.delete_files_read_time =
87
74
                ADD_CHILD_TIMER(this->get_profile(), "DeleteFileReadTime", iceberg_profile);
88
74
        _iceberg_profile.delete_rows_sort_time =
89
74
                ADD_CHILD_TIMER(this->get_profile(), "DeleteRowsSortTime", iceberg_profile);
90
74
        _iceberg_profile.parse_delete_file_time =
91
74
                ADD_CHILD_TIMER(this->get_profile(), "ParseDeleteFileTime", iceberg_profile);
92
74
        _iceberg_profile.decoded_cache_hit_count =
93
74
                ADD_CHILD_COUNTER(this->get_profile(), "DeletionVectorDecodedCacheHitCount",
94
74
                                  TUnit::UNIT, iceberg_profile);
95
74
        _iceberg_profile.decoded_cache_miss_count =
96
74
                ADD_CHILD_COUNTER(this->get_profile(), "DeletionVectorDecodedCacheMissCount",
97
74
                                  TUnit::UNIT, iceberg_profile);
98
74
        _iceberg_profile.file_cache_hit_count =
99
74
                ADD_CHILD_COUNTER(this->get_profile(), "DeletionVectorFileCacheHitCount",
100
74
                                  TUnit::UNIT, iceberg_profile);
101
74
        _iceberg_profile.file_cache_miss_count =
102
74
                ADD_CHILD_COUNTER(this->get_profile(), "DeletionVectorFileCacheMissCount",
103
74
                                  TUnit::UNIT, iceberg_profile);
104
74
        _iceberg_profile.file_cache_peer_read_count =
105
74
                ADD_CHILD_COUNTER(this->get_profile(), "DeletionVectorFileCachePeerReadCount",
106
74
                                  TUnit::UNIT, iceberg_profile);
107
74
    }
_ZN5doris18IcebergReaderMixinINS_13ParquetReaderEEC2IJRPNS_14RuntimeProfileERKNS_20TFileScanRangeParamsERKNS_14TFileRangeDescERmRPKN4cctz9time_zoneERPNS_2io9IOContextERPNS_12RuntimeStateERPNS_13FileMetaCacheEEEEPNS_14ShardedKVCacheEDpOT_
Line
Count
Source
79
47
            : BaseReader(std::forward<Args>(args)...), _kv_cache(kv_cache) {
80
47
        static const char* iceberg_profile = "IcebergProfile";
81
47
        ADD_TIMER(this->get_profile(), iceberg_profile);
82
47
        _iceberg_profile.num_delete_files = ADD_CHILD_COUNTER(this->get_profile(), "NumDeleteFiles",
83
47
                                                              TUnit::UNIT, iceberg_profile);
84
47
        _iceberg_profile.num_delete_rows = ADD_CHILD_COUNTER(this->get_profile(), "NumDeleteRows",
85
47
                                                             TUnit::UNIT, iceberg_profile);
86
47
        _iceberg_profile.delete_files_read_time =
87
47
                ADD_CHILD_TIMER(this->get_profile(), "DeleteFileReadTime", iceberg_profile);
88
47
        _iceberg_profile.delete_rows_sort_time =
89
47
                ADD_CHILD_TIMER(this->get_profile(), "DeleteRowsSortTime", iceberg_profile);
90
47
        _iceberg_profile.parse_delete_file_time =
91
47
                ADD_CHILD_TIMER(this->get_profile(), "ParseDeleteFileTime", iceberg_profile);
92
47
        _iceberg_profile.decoded_cache_hit_count =
93
47
                ADD_CHILD_COUNTER(this->get_profile(), "DeletionVectorDecodedCacheHitCount",
94
47
                                  TUnit::UNIT, iceberg_profile);
95
47
        _iceberg_profile.decoded_cache_miss_count =
96
47
                ADD_CHILD_COUNTER(this->get_profile(), "DeletionVectorDecodedCacheMissCount",
97
47
                                  TUnit::UNIT, iceberg_profile);
98
47
        _iceberg_profile.file_cache_hit_count =
99
47
                ADD_CHILD_COUNTER(this->get_profile(), "DeletionVectorFileCacheHitCount",
100
47
                                  TUnit::UNIT, iceberg_profile);
101
47
        _iceberg_profile.file_cache_miss_count =
102
47
                ADD_CHILD_COUNTER(this->get_profile(), "DeletionVectorFileCacheMissCount",
103
47
                                  TUnit::UNIT, iceberg_profile);
104
47
        _iceberg_profile.file_cache_peer_read_count =
105
47
                ADD_CHILD_COUNTER(this->get_profile(), "DeletionVectorFileCachePeerReadCount",
106
47
                                  TUnit::UNIT, iceberg_profile);
107
47
    }
_ZN5doris18IcebergReaderMixinINS_9OrcReaderEEC2IJRPNS_14RuntimeProfileERPNS_12RuntimeStateERKNS_20TFileScanRangeParamsERKNS_14TFileRangeDescERmRKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEERPNS_2io9IOContextERPNS_13FileMetaCacheEEEEPNS_14ShardedKVCacheEDpOT_
Line
Count
Source
79
26
            : BaseReader(std::forward<Args>(args)...), _kv_cache(kv_cache) {
80
26
        static const char* iceberg_profile = "IcebergProfile";
81
26
        ADD_TIMER(this->get_profile(), iceberg_profile);
82
26
        _iceberg_profile.num_delete_files = ADD_CHILD_COUNTER(this->get_profile(), "NumDeleteFiles",
83
26
                                                              TUnit::UNIT, iceberg_profile);
84
26
        _iceberg_profile.num_delete_rows = ADD_CHILD_COUNTER(this->get_profile(), "NumDeleteRows",
85
26
                                                             TUnit::UNIT, iceberg_profile);
86
26
        _iceberg_profile.delete_files_read_time =
87
26
                ADD_CHILD_TIMER(this->get_profile(), "DeleteFileReadTime", iceberg_profile);
88
26
        _iceberg_profile.delete_rows_sort_time =
89
26
                ADD_CHILD_TIMER(this->get_profile(), "DeleteRowsSortTime", iceberg_profile);
90
26
        _iceberg_profile.parse_delete_file_time =
91
26
                ADD_CHILD_TIMER(this->get_profile(), "ParseDeleteFileTime", iceberg_profile);
92
26
        _iceberg_profile.decoded_cache_hit_count =
93
26
                ADD_CHILD_COUNTER(this->get_profile(), "DeletionVectorDecodedCacheHitCount",
94
26
                                  TUnit::UNIT, iceberg_profile);
95
26
        _iceberg_profile.decoded_cache_miss_count =
96
26
                ADD_CHILD_COUNTER(this->get_profile(), "DeletionVectorDecodedCacheMissCount",
97
26
                                  TUnit::UNIT, iceberg_profile);
98
26
        _iceberg_profile.file_cache_hit_count =
99
26
                ADD_CHILD_COUNTER(this->get_profile(), "DeletionVectorFileCacheHitCount",
100
26
                                  TUnit::UNIT, iceberg_profile);
101
26
        _iceberg_profile.file_cache_miss_count =
102
26
                ADD_CHILD_COUNTER(this->get_profile(), "DeletionVectorFileCacheMissCount",
103
26
                                  TUnit::UNIT, iceberg_profile);
104
26
        _iceberg_profile.file_cache_peer_read_count =
105
26
                ADD_CHILD_COUNTER(this->get_profile(), "DeletionVectorFileCachePeerReadCount",
106
26
                                  TUnit::UNIT, iceberg_profile);
107
26
    }
_ZN5doris18IcebergReaderMixinINS_13ParquetReaderEEC2IJRPNS_14RuntimeProfileERKNS_20TFileScanRangeParamsERKNS_14TFileRangeDescERmRPKN4cctz9time_zoneESt10shared_ptrINS_2io9IOContextEERPNS_12RuntimeStateERPNS_13FileMetaCacheEEEEPNS_14ShardedKVCacheEDpOT_
Line
Count
Source
79
1
            : BaseReader(std::forward<Args>(args)...), _kv_cache(kv_cache) {
80
1
        static const char* iceberg_profile = "IcebergProfile";
81
1
        ADD_TIMER(this->get_profile(), iceberg_profile);
82
1
        _iceberg_profile.num_delete_files = ADD_CHILD_COUNTER(this->get_profile(), "NumDeleteFiles",
83
1
                                                              TUnit::UNIT, iceberg_profile);
84
1
        _iceberg_profile.num_delete_rows = ADD_CHILD_COUNTER(this->get_profile(), "NumDeleteRows",
85
1
                                                             TUnit::UNIT, iceberg_profile);
86
1
        _iceberg_profile.delete_files_read_time =
87
1
                ADD_CHILD_TIMER(this->get_profile(), "DeleteFileReadTime", iceberg_profile);
88
1
        _iceberg_profile.delete_rows_sort_time =
89
1
                ADD_CHILD_TIMER(this->get_profile(), "DeleteRowsSortTime", iceberg_profile);
90
1
        _iceberg_profile.parse_delete_file_time =
91
1
                ADD_CHILD_TIMER(this->get_profile(), "ParseDeleteFileTime", iceberg_profile);
92
1
        _iceberg_profile.decoded_cache_hit_count =
93
1
                ADD_CHILD_COUNTER(this->get_profile(), "DeletionVectorDecodedCacheHitCount",
94
1
                                  TUnit::UNIT, iceberg_profile);
95
1
        _iceberg_profile.decoded_cache_miss_count =
96
1
                ADD_CHILD_COUNTER(this->get_profile(), "DeletionVectorDecodedCacheMissCount",
97
1
                                  TUnit::UNIT, iceberg_profile);
98
1
        _iceberg_profile.file_cache_hit_count =
99
1
                ADD_CHILD_COUNTER(this->get_profile(), "DeletionVectorFileCacheHitCount",
100
1
                                  TUnit::UNIT, iceberg_profile);
101
1
        _iceberg_profile.file_cache_miss_count =
102
1
                ADD_CHILD_COUNTER(this->get_profile(), "DeletionVectorFileCacheMissCount",
103
1
                                  TUnit::UNIT, iceberg_profile);
104
1
        _iceberg_profile.file_cache_peer_read_count =
105
1
                ADD_CHILD_COUNTER(this->get_profile(), "DeletionVectorFileCachePeerReadCount",
106
1
                                  TUnit::UNIT, iceberg_profile);
107
1
    }
Unexecuted instantiation: _ZN5doris18IcebergReaderMixinINS_9OrcReaderEEC2IJRPNS_14RuntimeProfileERPNS_12RuntimeStateERKNS_20TFileScanRangeParamsERKNS_14TFileRangeDescERmRKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEESt10shared_ptrINS_2io9IOContextEERPNS_13FileMetaCacheEEEEPNS_14ShardedKVCacheEDpOT_
108
109
74
    ~IcebergReaderMixin() override = default;
_ZN5doris18IcebergReaderMixinINS_13ParquetReaderEED2Ev
Line
Count
Source
109
48
    ~IcebergReaderMixin() override = default;
_ZN5doris18IcebergReaderMixinINS_9OrcReaderEED2Ev
Line
Count
Source
109
26
    ~IcebergReaderMixin() override = default;
110
111
    void set_current_file_info(const std::string& file_path, int32_t partition_spec_id,
112
0
                               const std::string& partition_data_json) {
113
0
        _current_file_path = file_path;
114
0
        _partition_spec_id = partition_spec_id;
115
0
        _partition_data_json = partition_data_json;
116
0
    }
Unexecuted instantiation: _ZN5doris18IcebergReaderMixinINS_13ParquetReaderEE21set_current_file_infoERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEiSA_
Unexecuted instantiation: _ZN5doris18IcebergReaderMixinINS_9OrcReaderEE21set_current_file_infoERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEiSA_
117
118
    enum { DATA, POSITION_DELETE, EQUALITY_DELETE, DELETION_VECTOR };
119
    enum Fileformat { NONE, PARQUET, ORC, AVRO };
120
121
    virtual void set_delete_rows() = 0;
122
    virtual void set_deletion_vector() = 0;
123
124
    // Table-level COUNT(*) is handled by CountReader (created by FileScanner after
125
    // init_reader). If _do_get_next_block is called, COUNT must have been resolved.
126
52
    Status _do_get_next_block(Block* block, size_t* read_rows, bool* eof) override {
127
52
        DCHECK(this->_push_down_agg_type != TPushAggOp::type::COUNT);
128
52
        return BaseReader::_do_get_next_block(block, read_rows, eof);
129
52
    }
_ZN5doris18IcebergReaderMixinINS_13ParquetReaderEE18_do_get_next_blockEPNS_5BlockEPmPb
Line
Count
Source
126
32
    Status _do_get_next_block(Block* block, size_t* read_rows, bool* eof) override {
127
        DCHECK(this->_push_down_agg_type != TPushAggOp::type::COUNT);
128
32
        return BaseReader::_do_get_next_block(block, read_rows, eof);
129
32
    }
_ZN5doris18IcebergReaderMixinINS_9OrcReaderEE18_do_get_next_blockEPNS_5BlockEPmPb
Line
Count
Source
126
20
    Status _do_get_next_block(Block* block, size_t* read_rows, bool* eof) override {
127
        DCHECK(this->_push_down_agg_type != TPushAggOp::type::COUNT);
128
20
        return BaseReader::_do_get_next_block(block, read_rows, eof);
129
20
    }
130
131
    void set_create_row_id_column_iterator_func(
132
1
            std::function<std::shared_ptr<segment_v2::RowIdColumnIteratorV2>()> create_func) {
133
1
        _create_topn_row_id_column_iterator = create_func;
134
1
    }
_ZN5doris18IcebergReaderMixinINS_13ParquetReaderEE38set_create_row_id_column_iterator_funcESt8functionIFSt10shared_ptrINS_10segment_v221RowIdColumnIteratorV2EEvEE
Line
Count
Source
132
1
            std::function<std::shared_ptr<segment_v2::RowIdColumnIteratorV2>()> create_func) {
133
1
        _create_topn_row_id_column_iterator = create_func;
134
1
    }
Unexecuted instantiation: _ZN5doris18IcebergReaderMixinINS_9OrcReaderEE38set_create_row_id_column_iterator_funcESt8functionIFSt10shared_ptrINS_10segment_v221RowIdColumnIteratorV2EEvEE
135
136
    Status TEST_read_deletion_vector(const std::string& data_file_path,
137
1
                                     const TIcebergDeleteFileDesc& delete_file_desc) {
138
1
        return read_deletion_vector(data_file_path, delete_file_desc);
139
1
    }
140
141
    Status TEST_position_delete_base(const std::string& data_file_path,
142
2
                                     const std::vector<TIcebergDeleteFileDesc>& delete_files) {
143
2
        return _position_delete_base(data_file_path, delete_files);
144
2
    }
145
146
1
    Status TEST_read_equality_delete_file(const TIcebergDeleteFileDesc& delete_file) {
147
1
        return _read_equality_delete_file(delete_file);
148
1
    }
149
150
    void TEST_set_column_name_to_block_index(
151
5
            std::unordered_map<std::string, uint32_t>* column_name_to_block_index) {
152
5
        this->col_name_to_block_idx_ref() = column_name_to_block_index;
153
5
    }
154
155
    Status TEST_register_missing_equality_delete_column(int32_t field_id, const std::string& name,
156
6
                                                        const DataTypePtr& delete_key_type) {
157
6
        return _register_missing_equality_delete_column(field_id, name, delete_key_type);
158
6
    }
159
160
3
    Status TEST_materialize_missing_equality_delete_columns(Block* block, size_t rows) {
161
3
        return _materialize_missing_equality_delete_columns(block, rows);
162
3
    }
163
164
8
    const std::vector<int32_t>& TEST_expand_col_field_ids() const { return _expand_col_field_ids; }
_ZNK5doris18IcebergReaderMixinINS_13ParquetReaderEE25TEST_expand_col_field_idsEv
Line
Count
Source
164
4
    const std::vector<int32_t>& TEST_expand_col_field_ids() const { return _expand_col_field_ids; }
_ZNK5doris18IcebergReaderMixinINS_9OrcReaderEE25TEST_expand_col_field_idsEv
Line
Count
Source
164
4
    const std::vector<int32_t>& TEST_expand_col_field_ids() const { return _expand_col_field_ids; }
165
166
protected:
167
    // ---- Hook implementations ----
168
169
    // Called before reading a block: expand block for equality delete columns + detect row_id
170
52
    Status on_before_read_block(Block* block) override {
171
52
        RETURN_IF_ERROR(_expand_block_if_need(block));
172
52
        return Status::OK();
173
52
    }
_ZN5doris18IcebergReaderMixinINS_13ParquetReaderEE20on_before_read_blockEPNS_5BlockE
Line
Count
Source
170
32
    Status on_before_read_block(Block* block) override {
171
32
        RETURN_IF_ERROR(_expand_block_if_need(block));
172
32
        return Status::OK();
173
32
    }
_ZN5doris18IcebergReaderMixinINS_9OrcReaderEE20on_before_read_blockEPNS_5BlockE
Line
Count
Source
170
20
    Status on_before_read_block(Block* block) override {
171
20
        RETURN_IF_ERROR(_expand_block_if_need(block));
172
20
        return Status::OK();
173
20
    }
174
175
    // Iceberg initial defaults belong to the table schema, not to the generic FE slot default.
176
    // V1 keeps master's primitive-default behavior; V2 also materializes missing optional/required
177
    // fields and complex defaults through the recursive Iceberg schema metadata.
178
    Status on_fill_missing_columns(Block* block, size_t rows,
179
61
                                   const std::vector<std::string>& cols) override {
180
61
        if (!supports_iceberg_scan_semantics_v1(&this->get_scan_params())) {
181
5
            return BaseReader::on_fill_missing_columns(block, rows, cols);
182
5
        }
183
56
        const bool use_v2_semantics = supports_iceberg_scan_semantics_v2(&this->get_scan_params());
184
56
        std::vector<std::string> base_reader_columns;
185
56
        for (const auto& col_name : cols) {
186
5
            const auto* field = _find_current_schema_field(col_name);
187
5
            if (field == nullptr || (!use_v2_semantics && !field->__isset.initial_default_value)) {
188
0
                base_reader_columns.push_back(col_name);
189
0
                continue;
190
0
            }
191
192
5
            DORIS_CHECK(this->_fill_col_name_to_block_idx != nullptr);
193
5
            const auto position = this->_fill_col_name_to_block_idx->find(col_name);
194
5
            if (position == this->_fill_col_name_to_block_idx->end()) {
195
0
                return Status::InternalError("Missing column: {} not found in block {}", col_name,
196
0
                                             block->dump_structure());
197
0
            }
198
5
            DORIS_CHECK(position->second < block->columns());
199
200
5
            auto default_value = _missing_initial_default_values.find(col_name);
201
5
            if (default_value == _missing_initial_default_values.end()) {
202
4
                ColumnPtr value;
203
4
                RETURN_IF_ERROR(iceberg::create_initial_default_column(
204
4
                        *field, block->get_by_position(position->second).type, &value));
205
4
                default_value =
206
4
                        _missing_initial_default_values.emplace(col_name, std::move(value)).first;
207
4
            }
208
5
            auto column_guard = block->mutate_column_scoped(position->second);
209
5
            auto& mutable_column = column_guard.mutable_column();
210
5
            mutable_column->insert_many_from(*default_value->second, 0, rows);
211
5
        }
212
56
        return BaseReader::on_fill_missing_columns(block, rows, base_reader_columns);
213
56
    }
_ZN5doris18IcebergReaderMixinINS_13ParquetReaderEE23on_fill_missing_columnsEPNS_5BlockEmRKSt6vectorINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEESaISB_EE
Line
Count
Source
179
40
                                   const std::vector<std::string>& cols) override {
180
40
        if (!supports_iceberg_scan_semantics_v1(&this->get_scan_params())) {
181
4
            return BaseReader::on_fill_missing_columns(block, rows, cols);
182
4
        }
183
36
        const bool use_v2_semantics = supports_iceberg_scan_semantics_v2(&this->get_scan_params());
184
36
        std::vector<std::string> base_reader_columns;
185
36
        for (const auto& col_name : cols) {
186
4
            const auto* field = _find_current_schema_field(col_name);
187
4
            if (field == nullptr || (!use_v2_semantics && !field->__isset.initial_default_value)) {
188
0
                base_reader_columns.push_back(col_name);
189
0
                continue;
190
0
            }
191
192
4
            DORIS_CHECK(this->_fill_col_name_to_block_idx != nullptr);
193
4
            const auto position = this->_fill_col_name_to_block_idx->find(col_name);
194
4
            if (position == this->_fill_col_name_to_block_idx->end()) {
195
0
                return Status::InternalError("Missing column: {} not found in block {}", col_name,
196
0
                                             block->dump_structure());
197
0
            }
198
4
            DORIS_CHECK(position->second < block->columns());
199
200
4
            auto default_value = _missing_initial_default_values.find(col_name);
201
4
            if (default_value == _missing_initial_default_values.end()) {
202
3
                ColumnPtr value;
203
3
                RETURN_IF_ERROR(iceberg::create_initial_default_column(
204
3
                        *field, block->get_by_position(position->second).type, &value));
205
3
                default_value =
206
3
                        _missing_initial_default_values.emplace(col_name, std::move(value)).first;
207
3
            }
208
4
            auto column_guard = block->mutate_column_scoped(position->second);
209
4
            auto& mutable_column = column_guard.mutable_column();
210
4
            mutable_column->insert_many_from(*default_value->second, 0, rows);
211
4
        }
212
36
        return BaseReader::on_fill_missing_columns(block, rows, base_reader_columns);
213
36
    }
_ZN5doris18IcebergReaderMixinINS_9OrcReaderEE23on_fill_missing_columnsEPNS_5BlockEmRKSt6vectorINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEESaISB_EE
Line
Count
Source
179
21
                                   const std::vector<std::string>& cols) override {
180
21
        if (!supports_iceberg_scan_semantics_v1(&this->get_scan_params())) {
181
1
            return BaseReader::on_fill_missing_columns(block, rows, cols);
182
1
        }
183
20
        const bool use_v2_semantics = supports_iceberg_scan_semantics_v2(&this->get_scan_params());
184
20
        std::vector<std::string> base_reader_columns;
185
20
        for (const auto& col_name : cols) {
186
1
            const auto* field = _find_current_schema_field(col_name);
187
1
            if (field == nullptr || (!use_v2_semantics && !field->__isset.initial_default_value)) {
188
0
                base_reader_columns.push_back(col_name);
189
0
                continue;
190
0
            }
191
192
1
            DORIS_CHECK(this->_fill_col_name_to_block_idx != nullptr);
193
1
            const auto position = this->_fill_col_name_to_block_idx->find(col_name);
194
1
            if (position == this->_fill_col_name_to_block_idx->end()) {
195
0
                return Status::InternalError("Missing column: {} not found in block {}", col_name,
196
0
                                             block->dump_structure());
197
0
            }
198
1
            DORIS_CHECK(position->second < block->columns());
199
200
1
            auto default_value = _missing_initial_default_values.find(col_name);
201
1
            if (default_value == _missing_initial_default_values.end()) {
202
1
                ColumnPtr value;
203
1
                RETURN_IF_ERROR(iceberg::create_initial_default_column(
204
1
                        *field, block->get_by_position(position->second).type, &value));
205
1
                default_value =
206
1
                        _missing_initial_default_values.emplace(col_name, std::move(value)).first;
207
1
            }
208
1
            auto column_guard = block->mutate_column_scoped(position->second);
209
1
            auto& mutable_column = column_guard.mutable_column();
210
1
            mutable_column->insert_many_from(*default_value->second, 0, rows);
211
1
        }
212
20
        return BaseReader::on_fill_missing_columns(block, rows, base_reader_columns);
213
20
    }
214
215
    /// Fill Iceberg $row_id synthesized column. Registered as handler during init.
216
0
    Status _fill_iceberg_row_id(Block* block, size_t rows) {
217
0
        int row_id_pos = block->get_position_by_name(BeConsts::ICEBERG_ROWID_COL);
218
0
        DORIS_CHECK(row_id_pos >= 0);
219
220
        // Lazy-init file info: only set when $row_id is actually needed.
221
0
        const auto& table_desc = this->get_scan_range().table_format_params.iceberg_params;
222
0
        std::string file_path = table_desc.original_file_path;
223
0
        int32_t partition_spec_id =
224
0
                table_desc.__isset.partition_spec_id ? table_desc.partition_spec_id : 0;
225
0
        std::string partition_data_json;
226
0
        if (table_desc.__isset.partition_data_json) {
227
0
            partition_data_json = table_desc.partition_data_json;
228
0
        }
229
0
        set_current_file_info(file_path, partition_spec_id, partition_data_json);
230
231
0
        const auto& row_ids = this->current_batch_row_positions();
232
0
        auto& col_with_type = block->get_by_position(static_cast<size_t>(row_id_pos));
233
0
        MutableColumnPtr row_id_column;
234
0
        RETURN_IF_ERROR(_build_iceberg_rowid_column(col_with_type.type, _current_file_path, row_ids,
235
0
                                                    _partition_spec_id, _partition_data_json,
236
0
                                                    &row_id_column));
237
0
        col_with_type.column = std::move(row_id_column);
238
0
        return Status::OK();
239
0
    }
Unexecuted instantiation: _ZN5doris18IcebergReaderMixinINS_13ParquetReaderEE20_fill_iceberg_row_idEPNS_5BlockEm
Unexecuted instantiation: _ZN5doris18IcebergReaderMixinINS_9OrcReaderEE20_fill_iceberg_row_idEPNS_5BlockEm
240
241
0
    void _init_row_lineage_columns() {
242
0
        const auto& table_desc = this->get_scan_range().table_format_params.iceberg_params;
243
0
        if (table_desc.__isset.first_row_id) {
244
0
            _row_lineage_columns.first_row_id = table_desc.first_row_id;
245
0
        }
246
0
        if (table_desc.__isset.last_updated_sequence_number) {
247
0
            _row_lineage_columns.last_updated_sequence_number =
248
0
                    table_desc.last_updated_sequence_number;
249
0
        }
250
0
    }
Unexecuted instantiation: _ZN5doris18IcebergReaderMixinINS_13ParquetReaderEE25_init_row_lineage_columnsEv
Unexecuted instantiation: _ZN5doris18IcebergReaderMixinINS_9OrcReaderEE25_init_row_lineage_columnsEv
251
252
0
    Status _fill_row_lineage_row_id(Block* block, size_t rows) {
253
0
        int col_pos = block->get_position_by_name(ROW_LINEAGE_ROW_ID);
254
0
        DORIS_CHECK(col_pos >= 0);
255
256
0
        if (_row_lineage_columns.first_row_id >= 0) {
257
0
            auto column_guard = block->mutate_column_scoped(col_pos);
258
0
            auto* nullable_column =
259
0
                    assert_cast<ColumnNullable*>(column_guard.mutable_column().get());
260
0
            auto& null_map = nullable_column->get_null_map_data();
261
0
            auto& data =
262
0
                    assert_cast<ColumnInt64&>(*nullable_column->get_nested_column_ptr()).get_data();
263
0
            const auto& row_ids = this->current_batch_row_positions();
264
0
            for (size_t i = 0; i < rows; ++i) {
265
0
                if (null_map[i] != 0) {
266
0
                    null_map[i] = 0;
267
0
                    data[i] = _row_lineage_columns.first_row_id + static_cast<int64_t>(row_ids[i]);
268
0
                }
269
0
            }
270
0
        }
271
0
        return Status::OK();
272
0
    }
Unexecuted instantiation: _ZN5doris18IcebergReaderMixinINS_13ParquetReaderEE24_fill_row_lineage_row_idEPNS_5BlockEm
Unexecuted instantiation: _ZN5doris18IcebergReaderMixinINS_9OrcReaderEE24_fill_row_lineage_row_idEPNS_5BlockEm
273
274
0
    Status _fill_row_lineage_last_updated_sequence_number(Block* block, size_t rows) {
275
0
        int col_pos = block->get_position_by_name(ROW_LINEAGE_LAST_UPDATED_SEQ_NUMBER);
276
0
        DORIS_CHECK(col_pos >= 0);
277
278
0
        if (_row_lineage_columns.last_updated_sequence_number >= 0) {
279
0
            auto column_guard = block->mutate_column_scoped(col_pos);
280
0
            auto* nullable_column =
281
0
                    assert_cast<ColumnNullable*>(column_guard.mutable_column().get());
282
0
            auto& null_map = nullable_column->get_null_map_data();
283
0
            auto& data =
284
0
                    assert_cast<ColumnInt64&>(*nullable_column->get_nested_column_ptr()).get_data();
285
0
            for (size_t i = 0; i < rows; ++i) {
286
0
                if (null_map[i] != 0) {
287
0
                    null_map[i] = 0;
288
0
                    data[i] = _row_lineage_columns.last_updated_sequence_number;
289
0
                }
290
0
            }
291
0
        }
292
0
        return Status::OK();
293
0
    }
Unexecuted instantiation: _ZN5doris18IcebergReaderMixinINS_13ParquetReaderEE46_fill_row_lineage_last_updated_sequence_numberEPNS_5BlockEm
Unexecuted instantiation: _ZN5doris18IcebergReaderMixinINS_9OrcReaderEE46_fill_row_lineage_last_updated_sequence_numberEPNS_5BlockEm
294
295
    // Called after reading a block: apply equality delete filter + shrink block
296
52
    Status on_after_read_block(Block* block, size_t* read_rows) override {
297
52
        RETURN_IF_ERROR(_materialize_missing_equality_delete_columns(block, block->rows()));
298
52
        RETURN_IF_ERROR(_materialize_nested_equality_delete_columns(block));
299
52
        if (!_equality_delete_impls.empty()) {
300
44
            std::unique_ptr<IColumn::Filter> filter =
301
44
                    std::make_unique<IColumn::Filter>(block->rows(), 1);
302
46
            for (auto& equality_delete_impl : _equality_delete_impls) {
303
46
                RETURN_IF_ERROR(equality_delete_impl->filter_data_block(
304
46
                        block, this->col_name_to_block_idx_ref(), _id_to_block_column_name,
305
46
                        *filter));
306
46
            }
307
44
            Block::filter_block_internal(block, *filter, block->columns());
308
44
            *read_rows = block->rows();
309
44
        }
310
52
        return _shrink_block_if_need(block);
311
52
    }
_ZN5doris18IcebergReaderMixinINS_13ParquetReaderEE19on_after_read_blockEPNS_5BlockEPm
Line
Count
Source
296
32
    Status on_after_read_block(Block* block, size_t* read_rows) override {
297
32
        RETURN_IF_ERROR(_materialize_missing_equality_delete_columns(block, block->rows()));
298
32
        RETURN_IF_ERROR(_materialize_nested_equality_delete_columns(block));
299
32
        if (!_equality_delete_impls.empty()) {
300
27
            std::unique_ptr<IColumn::Filter> filter =
301
27
                    std::make_unique<IColumn::Filter>(block->rows(), 1);
302
28
            for (auto& equality_delete_impl : _equality_delete_impls) {
303
28
                RETURN_IF_ERROR(equality_delete_impl->filter_data_block(
304
28
                        block, this->col_name_to_block_idx_ref(), _id_to_block_column_name,
305
28
                        *filter));
306
28
            }
307
27
            Block::filter_block_internal(block, *filter, block->columns());
308
27
            *read_rows = block->rows();
309
27
        }
310
32
        return _shrink_block_if_need(block);
311
32
    }
_ZN5doris18IcebergReaderMixinINS_9OrcReaderEE19on_after_read_blockEPNS_5BlockEPm
Line
Count
Source
296
20
    Status on_after_read_block(Block* block, size_t* read_rows) override {
297
20
        RETURN_IF_ERROR(_materialize_missing_equality_delete_columns(block, block->rows()));
298
20
        RETURN_IF_ERROR(_materialize_nested_equality_delete_columns(block));
299
20
        if (!_equality_delete_impls.empty()) {
300
17
            std::unique_ptr<IColumn::Filter> filter =
301
17
                    std::make_unique<IColumn::Filter>(block->rows(), 1);
302
18
            for (auto& equality_delete_impl : _equality_delete_impls) {
303
18
                RETURN_IF_ERROR(equality_delete_impl->filter_data_block(
304
18
                        block, this->col_name_to_block_idx_ref(), _id_to_block_column_name,
305
18
                        *filter));
306
18
            }
307
17
            Block::filter_block_internal(block, *filter, block->columns());
308
17
            *read_rows = block->rows();
309
17
        }
310
20
        return _shrink_block_if_need(block);
311
20
    }
312
313
    // ---- Shared Iceberg methods ----
314
315
    Status _init_row_filters();
316
    Status _position_delete_base(const std::string data_file_path,
317
                                 const std::vector<TIcebergDeleteFileDesc>& delete_files);
318
    Status _equality_delete_base(const std::vector<TIcebergDeleteFileDesc>& delete_files);
319
    Status read_deletion_vector(const std::string& data_file_path,
320
                                const TIcebergDeleteFileDesc& delete_file_desc);
321
322
    Status _expand_block_if_need(Block* block);
323
    Status _shrink_block_if_need(Block* block);
324
    const schema::external::TStructField* _current_schema_root() const;
325
    const schema::external::TField* _find_current_schema_field(const std::string& name) const;
326
    const schema::external::TField* _find_schema_field(int32_t field_id) const;
327
    static bool _find_schema_field_path_in_field(
328
            const schema::external::TField* field, int32_t field_id,
329
            std::vector<const schema::external::TField*>* path);
330
    static bool _find_schema_field_path_in_root(const schema::external::TStructField* root,
331
                                                int32_t field_id,
332
                                                std::vector<const schema::external::TField*>* path);
333
    std::vector<const schema::external::TField*> _find_schema_field_path(int32_t field_id) const;
334
    Status _create_missing_equality_delete_value(int32_t field_id,
335
                                                 const DataTypePtr& delete_key_type,
336
                                                 size_t physical_path_size,
337
                                                 ColumnPtr* const value) const;
338
    Status _register_missing_equality_delete_column(int32_t field_id, const std::string& name,
339
                                                    const DataTypePtr& delete_key_type);
340
    bool _is_derived_equality_delete_column(const std::string& name) const;
341
    Status _materialize_missing_equality_delete_column(Block* block, const std::string& name,
342
                                                       const ColumnPtr& value, size_t rows);
343
    Status _materialize_missing_equality_delete_columns(Block* block, size_t rows);
344
345
    // Type aliases — must be defined before member function declarations that use them.
346
    using DeleteRows = std::vector<int64_t>;
347
    using DeleteFile = phmap::parallel_flat_hash_map<
348
            std::string, std::unique_ptr<DeleteRows>, std::hash<std::string>, std::equal_to<>,
349
            std::allocator<std::pair<const std::string, std::unique_ptr<DeleteRows>>>, 8,
350
            std::mutex>;
351
352
    PositionDeleteRange _get_range(const ColumnDictI32& file_path_column);
353
    PositionDeleteRange _get_range(const ColumnString& file_path_column);
354
    static void _sort_delete_rows(const std::vector<std::vector<int64_t>*>& delete_rows_array,
355
                                  int64_t num_delete_rows, std::vector<int64_t>& result);
356
    Status _gen_position_delete_file_range(Block& block, DeleteFile* position_delete,
357
                                           size_t read_rows,
358
                                           bool file_path_column_dictionary_coded);
359
    void _generate_equality_delete_block(Block* block,
360
                                         const std::vector<std::string>& equality_delete_col_names,
361
                                         const std::vector<DataTypePtr>& equality_delete_col_types);
362
    struct NestedEqualityDeleteColumn {
363
        int32_t field_id = -1;
364
        std::string block_name;
365
        DataTypePtr leaf_type;
366
        std::vector<size_t> child_indexes;
367
        ColumnPtr missing_value;
368
        // Block column holding the key's root struct. Empty when the key's own column reads the
369
        // root; otherwise the projected root, or the carrier that reads a shared physical root.
370
        std::string source_block_name {};
371
    };
372
    struct EqualityDeleteReadSpec {
373
        NestedEqualityDeleteColumn nested_field;
374
        std::string leaf_name;
375
        std::string root_name;
376
        DataTypePtr root_type;
377
    };
378
    static bool _find_parquet_equality_delete_path(const FieldSchema& field, int32_t field_id,
379
                                                   std::vector<const FieldSchema*>* path,
380
                                                   std::vector<size_t>* child_indexes);
381
    static bool _find_orc_equality_delete_path(const orc::Type* field,
382
                                               const std::string& field_name, int32_t field_id,
383
                                               std::vector<const orc::Type*>* path,
384
                                               std::vector<std::string>* names,
385
                                               std::vector<size_t>* child_indexes);
386
    Status _build_parquet_equality_delete_read_specs(
387
            ParquetReader* reader, const TIcebergDeleteFileDesc& delete_file,
388
            std::vector<EqualityDeleteReadSpec>* read_specs) const;
389
    Status _build_orc_equality_delete_read_specs(
390
            OrcReader* reader, const TIcebergDeleteFileDesc& delete_file,
391
            std::vector<EqualityDeleteReadSpec>* read_specs) const;
392
    Status _build_equality_delete_read_specs(GenericReader* reader,
393
                                             const TIcebergDeleteFileDesc& delete_file,
394
                                             std::vector<EqualityDeleteReadSpec>* read_specs) const;
395
    void _register_equality_delete_read_specs(
396
            const std::vector<EqualityDeleteReadSpec>& read_specs,
397
            std::vector<std::string>* delete_col_names, std::vector<DataTypePtr>* delete_col_types,
398
            std::vector<int>* delete_col_ids, std::vector<std::string>* read_root_names,
399
            std::vector<DataTypePtr>* read_root_types,
400
            std::unordered_map<std::string, uint32_t>* read_root_positions);
401
    static Status _initialize_equality_delete_reader(
402
            GenericReader* reader, const std::vector<std::string>& read_root_names,
403
            std::unordered_map<std::string, uint32_t>* read_root_positions);
404
    Status _merge_equality_delete_rows(
405
            GenericReader* reader, const std::vector<EqualityDeleteReadSpec>& read_specs,
406
            const std::vector<std::string>& read_root_names,
407
            const std::vector<DataTypePtr>& read_root_types,
408
            const std::unordered_map<std::string, uint32_t>& read_root_positions,
409
            Block* eq_file_block) const;
410
    Status _read_equality_delete_file(const TIcebergDeleteFileDesc& delete_file);
411
    Status _extract_nested_equality_delete_column(const ColumnPtr& root_column,
412
                                                  const NestedEqualityDeleteColumn& nested_field,
413
                                                  ColumnPtr* leaf_column) const;
414
    Status _materialize_nested_equality_delete_columns(Block* block);
415
416
    // Pure virtual: format-specific delete file reading
417
    virtual Status _read_position_delete_file(const TFileRangeDesc*, DeleteFile*) = 0;
418
    virtual std::unique_ptr<GenericReader> _create_equality_reader(
419
            const TFileRangeDesc& delete_desc) = 0;
420
421
2
    static std::string _delet_file_cache_key(const std::string& path) { return "delete_" + path; }
_ZN5doris18IcebergReaderMixinINS_13ParquetReaderEE21_delet_file_cache_keyERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE
Line
Count
Source
421
2
    static std::string _delet_file_cache_key(const std::string& path) { return "delete_" + path; }
Unexecuted instantiation: _ZN5doris18IcebergReaderMixinINS_9OrcReaderEE21_delet_file_cache_keyERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE
422
423
    /// Build the Iceberg V2 row-id struct column.
424
    static Status _build_iceberg_rowid_column(const DataTypePtr& type, const std::string& file_path,
425
                                              const std::vector<rowid_t>& row_ids,
426
                                              int32_t partition_spec_id,
427
                                              const std::string& partition_data_json,
428
0
                                              MutableColumnPtr* column_out) {
429
0
        if (type == nullptr || column_out == nullptr) {
430
0
            return Status::InvalidArgument("Invalid iceberg rowid column type or output column");
431
0
        }
432
0
        MutableColumnPtr column = type->create_column();
433
0
        auto* nullable_col = check_and_get_column<ColumnNullable>(column.get());
434
0
        ColumnStruct* struct_col = nullptr;
435
0
        if (nullable_col != nullptr) {
436
0
            struct_col =
437
0
                    check_and_get_column<ColumnStruct>(nullable_col->get_nested_column_ptr().get());
438
0
        } else {
439
0
            struct_col = check_and_get_column<ColumnStruct>(column.get());
440
0
        }
441
0
        if (struct_col == nullptr || struct_col->tuple_size() < 4) {
442
0
            return Status::InternalError("Invalid iceberg rowid column structure");
443
0
        }
444
0
        size_t num_rows = row_ids.size();
445
0
        auto& file_path_col = struct_col->get_column(0);
446
0
        auto& row_pos_col = struct_col->get_column(1);
447
0
        auto& spec_id_col = struct_col->get_column(2);
448
0
        auto& partition_data_col = struct_col->get_column(3);
449
0
        file_path_col.reserve(num_rows);
450
0
        row_pos_col.reserve(num_rows);
451
0
        spec_id_col.reserve(num_rows);
452
0
        partition_data_col.reserve(num_rows);
453
0
        for (size_t i = 0; i < num_rows; ++i) {
454
0
            file_path_col.insert_data(file_path.data(), file_path.size());
455
0
        }
456
0
        for (size_t i = 0; i < num_rows; ++i) {
457
0
            auto row_pos = static_cast<int64_t>(row_ids[i]);
458
0
            row_pos_col.insert_data(reinterpret_cast<const char*>(&row_pos), sizeof(row_pos));
459
0
        }
460
0
        for (size_t i = 0; i < num_rows; ++i) {
461
0
            int32_t spec_id = partition_spec_id;
462
0
            spec_id_col.insert_data(reinterpret_cast<const char*>(&spec_id), sizeof(spec_id));
463
0
        }
464
0
        for (size_t i = 0; i < num_rows; ++i) {
465
0
            partition_data_col.insert_data(partition_data_json.data(), partition_data_json.size());
466
0
        }
467
0
        if (nullable_col != nullptr) {
468
0
            nullable_col->get_null_map_data().resize_fill(num_rows, 0);
469
0
        }
470
0
        *column_out = std::move(column);
471
0
        return Status::OK();
472
0
    }
Unexecuted instantiation: _ZN5doris18IcebergReaderMixinINS_13ParquetReaderEE27_build_iceberg_rowid_columnERKSt10shared_ptrIKNS_9IDataTypeEERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEERKSt6vectorIjSaIjEEiSG_PNS_3COWINS_7IColumnEE11mutable_ptrISN_EE
Unexecuted instantiation: _ZN5doris18IcebergReaderMixinINS_9OrcReaderEE27_build_iceberg_rowid_columnERKSt10shared_ptrIKNS_9IDataTypeEERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEERKSt6vectorIjSaIjEEiSG_PNS_3COWINS_7IColumnEE11mutable_ptrISN_EE
473
474
    struct IcebergProfile {
475
        RuntimeProfile::Counter* num_delete_files;
476
        RuntimeProfile::Counter* num_delete_rows;
477
        RuntimeProfile::Counter* delete_files_read_time;
478
        RuntimeProfile::Counter* delete_rows_sort_time;
479
        RuntimeProfile::Counter* parse_delete_file_time;
480
        RuntimeProfile::Counter* decoded_cache_hit_count;
481
        RuntimeProfile::Counter* decoded_cache_miss_count;
482
        RuntimeProfile::Counter* file_cache_hit_count;
483
        RuntimeProfile::Counter* file_cache_miss_count;
484
        RuntimeProfile::Counter* file_cache_peer_read_count;
485
    };
486
487
    bool _need_row_id_column = false;
488
    std::string _current_file_path;
489
    int32_t _partition_spec_id = 0;
490
    std::string _partition_data_json;
491
492
    ShardedKVCache* _kv_cache;
493
    IcebergProfile _iceberg_profile;
494
    const std::vector<int64_t>* _iceberg_delete_rows = nullptr;
495
    const DeletionVector* _iceberg_deletion_vector = nullptr;
496
    std::vector<std::string> _expand_col_names;
497
    std::vector<int32_t> _expand_col_field_ids;
498
    std::vector<ColumnWithTypeAndName> _expand_columns;
499
    std::unordered_map<std::string, ColumnPtr> _missing_initial_default_values;
500
    std::unordered_map<std::string, ColumnPtr> _missing_equality_delete_values;
501
    std::vector<NestedEqualityDeleteColumn> _nested_equality_delete_columns;
502
    std::vector<std::string> _all_required_col_names;
503
    Fileformat _file_format = Fileformat::NONE;
504
505
    const int64_t MIN_SUPPORT_DELETE_FILES_VERSION = 2;
506
    const std::string ICEBERG_FILE_PATH = "file_path";
507
    const std::string ICEBERG_ROW_POS = "pos";
508
    const std::vector<std::string> delete_file_col_names {ICEBERG_FILE_PATH, ICEBERG_ROW_POS};
509
    const std::unordered_map<std::string, uint32_t> DELETE_COL_NAME_TO_BLOCK_IDX = {
510
            {ICEBERG_FILE_PATH, 0}, {ICEBERG_ROW_POS, 1}};
511
    const int ICEBERG_FILE_PATH_INDEX = 0;
512
    const int ICEBERG_FILE_POS_INDEX = 1;
513
    const int READ_DELETE_FILE_BATCH_SIZE = 102400;
514
515
    // all ids that need read for eq delete (from all eq delete files)
516
    std::set<int> _equality_delete_col_ids;
517
    // eq delete column ids -> location of _equality_delete_blocks / _equality_delete_impls
518
    std::map<std::vector<int>, int> _equality_delete_block_map;
519
    // EqualityDeleteBase stores raw pointers to these blocks, so do not modify this vector after
520
    // creating entries in _equality_delete_impls.
521
    std::vector<Block> _equality_delete_blocks;
522
    std::vector<std::unique_ptr<EqualityDeleteBase>> _equality_delete_impls;
523
524
    // id -> block column name
525
    std::unordered_map<int, std::string> _id_to_block_column_name;
526
527
    std::function<std::shared_ptr<segment_v2::RowIdColumnIteratorV2>()>
528
            _create_topn_row_id_column_iterator;
529
530
    static constexpr const char* ROW_LINEAGE_ROW_ID = "_row_id";
531
    static constexpr const char* ROW_LINEAGE_LAST_UPDATED_SEQ_NUMBER =
532
            "_last_updated_sequence_number";
533
    struct RowLineageColumns {
534
        int64_t first_row_id = -1;
535
        int64_t last_updated_sequence_number = -1;
536
    };
537
    RowLineageColumns _row_lineage_columns;
538
};
539
540
// ============================================================================
541
// Template method implementations (must be in header for templates)
542
// ============================================================================
543
544
template <typename BaseReader>
545
52
Status IcebergReaderMixin<BaseReader>::_init_row_filters() {
546
    // COUNT(*) short-circuit. A table-level row count of 0 (an empty current snapshot) is still a
547
    // valid pushed-down count, so accept >= 0 -- matching FileScanner and the Paimon readers. FE sends
548
    // -1 when there is no table-level count; using > 0 here would drop a genuine 0 into the normal read
549
    // path below and never produce the intended CountReader(0).
550
52
    if (this->_push_down_agg_type == TPushAggOp::type::COUNT &&
551
52
        this->get_scan_range().table_format_params.__isset.table_level_row_count &&
552
52
        this->get_scan_range().table_format_params.table_level_row_count >= 0) {
553
0
        return Status::OK();
554
0
    }
555
556
52
    const auto& table_desc = this->get_scan_range().table_format_params.iceberg_params;
557
52
    const auto& version = table_desc.format_version;
558
52
    if (version < MIN_SUPPORT_DELETE_FILES_VERSION) {
559
6
        return Status::OK();
560
6
    }
561
562
46
    std::vector<TIcebergDeleteFileDesc> position_delete_files;
563
46
    std::vector<TIcebergDeleteFileDesc> equality_delete_files;
564
46
    std::vector<TIcebergDeleteFileDesc> deletion_vector_files;
565
46
    for (const TIcebergDeleteFileDesc& desc : table_desc.delete_files) {
566
46
        if (desc.content == POSITION_DELETE) {
567
0
            position_delete_files.emplace_back(desc);
568
46
        } else if (desc.content == EQUALITY_DELETE) {
569
46
            equality_delete_files.emplace_back(desc);
570
46
        } else if (desc.content == DELETION_VECTOR) {
571
0
            deletion_vector_files.emplace_back(desc);
572
0
        }
573
46
    }
574
575
46
    if (!equality_delete_files.empty()) {
576
44
        RETURN_IF_ERROR(_equality_delete_base(equality_delete_files));
577
44
        this->set_push_down_agg_type(TPushAggOp::NONE);
578
44
    }
579
580
46
    if (!deletion_vector_files.empty()) {
581
0
        if (deletion_vector_files.size() != 1) [[unlikely]] {
582
            /*
583
             * Deletion vectors are a binary representation of deletes for a single data file that is more efficient
584
             * at execution time than position delete files. Unlike equality or position delete files, there can be
585
             * at most one deletion vector for a given data file in a snapshot.
586
             */
587
0
            return Status::DataQualityError("This iceberg data file has multiple DVs.");
588
0
        }
589
0
        RETURN_IF_ERROR(
590
0
                read_deletion_vector(table_desc.original_file_path, deletion_vector_files[0]));
591
0
        this->set_push_down_agg_type(TPushAggOp::NONE);
592
46
    } else if (!position_delete_files.empty()) {
593
0
        RETURN_IF_ERROR(
594
0
                _position_delete_base(table_desc.original_file_path, position_delete_files));
595
0
        this->set_push_down_agg_type(TPushAggOp::NONE);
596
0
    }
597
598
46
    COUNTER_UPDATE(_iceberg_profile.num_delete_files, table_desc.delete_files.size());
599
46
    return Status::OK();
600
46
}
_ZN5doris18IcebergReaderMixinINS_13ParquetReaderEE17_init_row_filtersEv
Line
Count
Source
545
32
Status IcebergReaderMixin<BaseReader>::_init_row_filters() {
546
    // COUNT(*) short-circuit. A table-level row count of 0 (an empty current snapshot) is still a
547
    // valid pushed-down count, so accept >= 0 -- matching FileScanner and the Paimon readers. FE sends
548
    // -1 when there is no table-level count; using > 0 here would drop a genuine 0 into the normal read
549
    // path below and never produce the intended CountReader(0).
550
32
    if (this->_push_down_agg_type == TPushAggOp::type::COUNT &&
551
32
        this->get_scan_range().table_format_params.__isset.table_level_row_count &&
552
32
        this->get_scan_range().table_format_params.table_level_row_count >= 0) {
553
0
        return Status::OK();
554
0
    }
555
556
32
    const auto& table_desc = this->get_scan_range().table_format_params.iceberg_params;
557
32
    const auto& version = table_desc.format_version;
558
32
    if (version < MIN_SUPPORT_DELETE_FILES_VERSION) {
559
4
        return Status::OK();
560
4
    }
561
562
28
    std::vector<TIcebergDeleteFileDesc> position_delete_files;
563
28
    std::vector<TIcebergDeleteFileDesc> equality_delete_files;
564
28
    std::vector<TIcebergDeleteFileDesc> deletion_vector_files;
565
28
    for (const TIcebergDeleteFileDesc& desc : table_desc.delete_files) {
566
28
        if (desc.content == POSITION_DELETE) {
567
0
            position_delete_files.emplace_back(desc);
568
28
        } else if (desc.content == EQUALITY_DELETE) {
569
28
            equality_delete_files.emplace_back(desc);
570
28
        } else if (desc.content == DELETION_VECTOR) {
571
0
            deletion_vector_files.emplace_back(desc);
572
0
        }
573
28
    }
574
575
28
    if (!equality_delete_files.empty()) {
576
27
        RETURN_IF_ERROR(_equality_delete_base(equality_delete_files));
577
27
        this->set_push_down_agg_type(TPushAggOp::NONE);
578
27
    }
579
580
28
    if (!deletion_vector_files.empty()) {
581
0
        if (deletion_vector_files.size() != 1) [[unlikely]] {
582
            /*
583
             * Deletion vectors are a binary representation of deletes for a single data file that is more efficient
584
             * at execution time than position delete files. Unlike equality or position delete files, there can be
585
             * at most one deletion vector for a given data file in a snapshot.
586
             */
587
0
            return Status::DataQualityError("This iceberg data file has multiple DVs.");
588
0
        }
589
0
        RETURN_IF_ERROR(
590
0
                read_deletion_vector(table_desc.original_file_path, deletion_vector_files[0]));
591
0
        this->set_push_down_agg_type(TPushAggOp::NONE);
592
28
    } else if (!position_delete_files.empty()) {
593
0
        RETURN_IF_ERROR(
594
0
                _position_delete_base(table_desc.original_file_path, position_delete_files));
595
0
        this->set_push_down_agg_type(TPushAggOp::NONE);
596
0
    }
597
598
28
    COUNTER_UPDATE(_iceberg_profile.num_delete_files, table_desc.delete_files.size());
599
28
    return Status::OK();
600
28
}
_ZN5doris18IcebergReaderMixinINS_9OrcReaderEE17_init_row_filtersEv
Line
Count
Source
545
20
Status IcebergReaderMixin<BaseReader>::_init_row_filters() {
546
    // COUNT(*) short-circuit. A table-level row count of 0 (an empty current snapshot) is still a
547
    // valid pushed-down count, so accept >= 0 -- matching FileScanner and the Paimon readers. FE sends
548
    // -1 when there is no table-level count; using > 0 here would drop a genuine 0 into the normal read
549
    // path below and never produce the intended CountReader(0).
550
20
    if (this->_push_down_agg_type == TPushAggOp::type::COUNT &&
551
20
        this->get_scan_range().table_format_params.__isset.table_level_row_count &&
552
20
        this->get_scan_range().table_format_params.table_level_row_count >= 0) {
553
0
        return Status::OK();
554
0
    }
555
556
20
    const auto& table_desc = this->get_scan_range().table_format_params.iceberg_params;
557
20
    const auto& version = table_desc.format_version;
558
20
    if (version < MIN_SUPPORT_DELETE_FILES_VERSION) {
559
2
        return Status::OK();
560
2
    }
561
562
18
    std::vector<TIcebergDeleteFileDesc> position_delete_files;
563
18
    std::vector<TIcebergDeleteFileDesc> equality_delete_files;
564
18
    std::vector<TIcebergDeleteFileDesc> deletion_vector_files;
565
18
    for (const TIcebergDeleteFileDesc& desc : table_desc.delete_files) {
566
18
        if (desc.content == POSITION_DELETE) {
567
0
            position_delete_files.emplace_back(desc);
568
18
        } else if (desc.content == EQUALITY_DELETE) {
569
18
            equality_delete_files.emplace_back(desc);
570
18
        } else if (desc.content == DELETION_VECTOR) {
571
0
            deletion_vector_files.emplace_back(desc);
572
0
        }
573
18
    }
574
575
18
    if (!equality_delete_files.empty()) {
576
17
        RETURN_IF_ERROR(_equality_delete_base(equality_delete_files));
577
17
        this->set_push_down_agg_type(TPushAggOp::NONE);
578
17
    }
579
580
18
    if (!deletion_vector_files.empty()) {
581
0
        if (deletion_vector_files.size() != 1) [[unlikely]] {
582
            /*
583
             * Deletion vectors are a binary representation of deletes for a single data file that is more efficient
584
             * at execution time than position delete files. Unlike equality or position delete files, there can be
585
             * at most one deletion vector for a given data file in a snapshot.
586
             */
587
0
            return Status::DataQualityError("This iceberg data file has multiple DVs.");
588
0
        }
589
0
        RETURN_IF_ERROR(
590
0
                read_deletion_vector(table_desc.original_file_path, deletion_vector_files[0]));
591
0
        this->set_push_down_agg_type(TPushAggOp::NONE);
592
18
    } else if (!position_delete_files.empty()) {
593
0
        RETURN_IF_ERROR(
594
0
                _position_delete_base(table_desc.original_file_path, position_delete_files));
595
0
        this->set_push_down_agg_type(TPushAggOp::NONE);
596
0
    }
597
598
18
    COUNTER_UPDATE(_iceberg_profile.num_delete_files, table_desc.delete_files.size());
599
18
    return Status::OK();
600
18
}
601
602
template <typename BaseReader>
603
bool IcebergReaderMixin<BaseReader>::_find_parquet_equality_delete_path(
604
        const FieldSchema& field, int32_t field_id, std::vector<const FieldSchema*>* path,
605
67
        std::vector<size_t>* child_indexes) {
606
67
    DORIS_CHECK(path != nullptr);
607
67
    DORIS_CHECK(child_indexes != nullptr);
608
67
    path->push_back(&field);
609
67
    if (field.field_id == field_id) {
610
36
        return true;
611
36
    }
612
38
    for (size_t index = 0; index < field.children.size(); ++index) {
613
25
        child_indexes->push_back(index);
614
25
        if (_find_parquet_equality_delete_path(field.children[index], field_id, path,
615
25
                                               child_indexes)) {
616
18
            return true;
617
18
        }
618
7
        child_indexes->pop_back();
619
7
    }
620
13
    path->pop_back();
621
13
    return false;
622
31
}
_ZN5doris18IcebergReaderMixinINS_13ParquetReaderEE34_find_parquet_equality_delete_pathERKNS_11FieldSchemaEiPSt6vectorIPS4_SaIS7_EEPS6_ImSaImEE
Line
Count
Source
605
67
        std::vector<size_t>* child_indexes) {
606
67
    DORIS_CHECK(path != nullptr);
607
67
    DORIS_CHECK(child_indexes != nullptr);
608
67
    path->push_back(&field);
609
67
    if (field.field_id == field_id) {
610
36
        return true;
611
36
    }
612
38
    for (size_t index = 0; index < field.children.size(); ++index) {
613
25
        child_indexes->push_back(index);
614
25
        if (_find_parquet_equality_delete_path(field.children[index], field_id, path,
615
25
                                               child_indexes)) {
616
18
            return true;
617
18
        }
618
7
        child_indexes->pop_back();
619
7
    }
620
13
    path->pop_back();
621
13
    return false;
622
31
}
Unexecuted instantiation: _ZN5doris18IcebergReaderMixinINS_9OrcReaderEE34_find_parquet_equality_delete_pathERKNS_11FieldSchemaEiPSt6vectorIPS4_SaIS7_EEPS6_ImSaImEE
623
624
template <typename BaseReader>
625
bool IcebergReaderMixin<BaseReader>::_find_orc_equality_delete_path(
626
        const orc::Type* field, const std::string& field_name, int32_t field_id,
627
        std::vector<const orc::Type*>* path, std::vector<std::string>* names,
628
33
        std::vector<size_t>* child_indexes) {
629
33
    DORIS_CHECK(field != nullptr);
630
33
    DORIS_CHECK(path != nullptr);
631
33
    DORIS_CHECK(names != nullptr);
632
33
    DORIS_CHECK(child_indexes != nullptr);
633
33
    path->push_back(field);
634
33
    names->push_back(field_name);
635
33
    if (field->hasAttributeKey("iceberg.id") &&
636
33
        std::stoi(field->getAttributeValue("iceberg.id")) == field_id) {
637
22
        return true;
638
22
    }
639
11
    for (size_t index = 0; index < field->getSubtypeCount(); ++index) {
640
5
        child_indexes->push_back(index);
641
5
        if (_find_orc_equality_delete_path(field->getSubtype(index), field->getFieldName(index),
642
5
                                           field_id, path, names, child_indexes)) {
643
5
            return true;
644
5
        }
645
0
        child_indexes->pop_back();
646
0
    }
647
6
    path->pop_back();
648
6
    names->pop_back();
649
6
    return false;
650
11
}
Unexecuted instantiation: _ZN5doris18IcebergReaderMixinINS_13ParquetReaderEE30_find_orc_equality_delete_pathEPKN3orc4TypeERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEiPSt6vectorIS6_SaIS6_EEPSF_ISC_SaISC_EEPSF_ImSaImEE
_ZN5doris18IcebergReaderMixinINS_9OrcReaderEE30_find_orc_equality_delete_pathEPKN3orc4TypeERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEiPSt6vectorIS6_SaIS6_EEPSF_ISC_SaISC_EEPSF_ImSaImEE
Line
Count
Source
628
33
        std::vector<size_t>* child_indexes) {
629
33
    DORIS_CHECK(field != nullptr);
630
33
    DORIS_CHECK(path != nullptr);
631
33
    DORIS_CHECK(names != nullptr);
632
33
    DORIS_CHECK(child_indexes != nullptr);
633
33
    path->push_back(field);
634
33
    names->push_back(field_name);
635
33
    if (field->hasAttributeKey("iceberg.id") &&
636
33
        std::stoi(field->getAttributeValue("iceberg.id")) == field_id) {
637
22
        return true;
638
22
    }
639
11
    for (size_t index = 0; index < field->getSubtypeCount(); ++index) {
640
5
        child_indexes->push_back(index);
641
5
        if (_find_orc_equality_delete_path(field->getSubtype(index), field->getFieldName(index),
642
5
                                           field_id, path, names, child_indexes)) {
643
5
            return true;
644
5
        }
645
0
        child_indexes->pop_back();
646
0
    }
647
6
    path->pop_back();
648
6
    names->pop_back();
649
6
    return false;
650
11
}
651
652
template <typename BaseReader>
653
Status IcebergReaderMixin<BaseReader>::_build_parquet_equality_delete_read_specs(
654
        ParquetReader* reader, const TIcebergDeleteFileDesc& delete_file,
655
28
        std::vector<EqualityDeleteReadSpec>* read_specs) const {
656
28
    DORIS_CHECK(reader != nullptr);
657
28
    DORIS_CHECK(read_specs != nullptr);
658
28
    const FieldDescriptor* delete_field_desc = nullptr;
659
28
    RETURN_IF_ERROR(reader->get_file_metadata_schema(&delete_field_desc));
660
28
    DORIS_CHECK(delete_field_desc != nullptr);
661
36
    for (const auto field_id : delete_file.field_ids) {
662
36
        std::vector<const FieldSchema*> path;
663
36
        std::vector<size_t> child_indexes;
664
42
        for (const auto& root : delete_field_desc->get_fields_schema()) {
665
42
            if (_find_parquet_equality_delete_path(root, field_id, &path, &child_indexes)) {
666
36
                break;
667
36
            }
668
42
        }
669
36
        if (path.empty()) {
670
0
            return Status::DataQualityError(
671
0
                    "missing field id {} when reading equality delete file {}", field_id,
672
0
                    delete_file.path);
673
0
        }
674
36
        const auto* root = path.front();
675
36
        const auto* leaf = path.back();
676
36
        if (!leaf->children.empty()) {
677
0
            return Status::NotSupported(
678
0
                    "Iceberg equality delete does not support complex column {}", leaf->name);
679
0
        }
680
36
        read_specs->push_back({
681
36
                .nested_field =
682
36
                        {
683
36
                                .field_id = field_id,
684
36
                                .block_name = leaf->name,
685
36
                                .leaf_type = make_nullable(leaf->data_type),
686
36
                                .child_indexes = std::move(child_indexes),
687
36
                                .missing_value = nullptr,
688
36
                        },
689
36
                .leaf_name = leaf->name,
690
36
                .root_name = root->name,
691
36
                .root_type = make_nullable(root->data_type),
692
36
        });
693
36
    }
694
28
    return Status::OK();
695
28
}
_ZNK5doris18IcebergReaderMixinINS_13ParquetReaderEE41_build_parquet_equality_delete_read_specsEPS1_RKNS_22TIcebergDeleteFileDescEPSt6vectorINS2_22EqualityDeleteReadSpecESaIS8_EE
Line
Count
Source
655
28
        std::vector<EqualityDeleteReadSpec>* read_specs) const {
656
28
    DORIS_CHECK(reader != nullptr);
657
28
    DORIS_CHECK(read_specs != nullptr);
658
28
    const FieldDescriptor* delete_field_desc = nullptr;
659
28
    RETURN_IF_ERROR(reader->get_file_metadata_schema(&delete_field_desc));
660
28
    DORIS_CHECK(delete_field_desc != nullptr);
661
36
    for (const auto field_id : delete_file.field_ids) {
662
36
        std::vector<const FieldSchema*> path;
663
36
        std::vector<size_t> child_indexes;
664
42
        for (const auto& root : delete_field_desc->get_fields_schema()) {
665
42
            if (_find_parquet_equality_delete_path(root, field_id, &path, &child_indexes)) {
666
36
                break;
667
36
            }
668
42
        }
669
36
        if (path.empty()) {
670
0
            return Status::DataQualityError(
671
0
                    "missing field id {} when reading equality delete file {}", field_id,
672
0
                    delete_file.path);
673
0
        }
674
36
        const auto* root = path.front();
675
36
        const auto* leaf = path.back();
676
36
        if (!leaf->children.empty()) {
677
0
            return Status::NotSupported(
678
0
                    "Iceberg equality delete does not support complex column {}", leaf->name);
679
0
        }
680
36
        read_specs->push_back({
681
36
                .nested_field =
682
36
                        {
683
36
                                .field_id = field_id,
684
36
                                .block_name = leaf->name,
685
36
                                .leaf_type = make_nullable(leaf->data_type),
686
36
                                .child_indexes = std::move(child_indexes),
687
36
                                .missing_value = nullptr,
688
36
                        },
689
36
                .leaf_name = leaf->name,
690
36
                .root_name = root->name,
691
36
                .root_type = make_nullable(root->data_type),
692
36
        });
693
36
    }
694
28
    return Status::OK();
695
28
}
Unexecuted instantiation: _ZNK5doris18IcebergReaderMixinINS_9OrcReaderEE41_build_parquet_equality_delete_read_specsEPNS_13ParquetReaderERKNS_22TIcebergDeleteFileDescEPSt6vectorINS2_22EqualityDeleteReadSpecESaIS9_EE
696
697
template <typename BaseReader>
698
Status IcebergReaderMixin<BaseReader>::_build_orc_equality_delete_read_specs(
699
        OrcReader* reader, const TIcebergDeleteFileDesc& delete_file,
700
18
        std::vector<EqualityDeleteReadSpec>* read_specs) const {
701
18
    DORIS_CHECK(reader != nullptr);
702
18
    DORIS_CHECK(read_specs != nullptr);
703
18
    const auto* delete_root = reader->get_file_root_type();
704
18
    DORIS_CHECK(delete_root != nullptr);
705
22
    for (const auto field_id : delete_file.field_ids) {
706
22
        std::vector<const orc::Type*> path;
707
22
        std::vector<std::string> names;
708
22
        std::vector<size_t> child_indexes;
709
28
        for (size_t root_index = 0; root_index < delete_root->getSubtypeCount(); ++root_index) {
710
28
            if (_find_orc_equality_delete_path(delete_root->getSubtype(root_index),
711
28
                                               delete_root->getFieldName(root_index), field_id,
712
28
                                               &path, &names, &child_indexes)) {
713
22
                break;
714
22
            }
715
28
        }
716
22
        if (path.empty()) {
717
0
            return Status::DataQualityError(
718
0
                    "missing field id {} when reading equality delete file {}", field_id,
719
0
                    delete_file.path);
720
0
        }
721
22
        const auto* root = path.front();
722
22
        const auto* leaf = path.back();
723
22
        if (leaf->getSubtypeCount() > 0) {
724
0
            return Status::NotSupported(
725
0
                    "Iceberg equality delete does not support complex column {}", names.back());
726
0
        }
727
22
        read_specs->push_back({
728
22
                .nested_field =
729
22
                        {
730
22
                                .field_id = field_id,
731
22
                                .block_name = names.back(),
732
22
                                .leaf_type = make_nullable(reader->convert_to_doris_type(leaf)),
733
22
                                .child_indexes = std::move(child_indexes),
734
22
                                .missing_value = nullptr,
735
22
                        },
736
22
                .leaf_name = names.back(),
737
22
                .root_name = names.front(),
738
22
                .root_type = make_nullable(reader->convert_to_doris_type(root)),
739
22
        });
740
22
    }
741
18
    return Status::OK();
742
18
}
Unexecuted instantiation: _ZNK5doris18IcebergReaderMixinINS_13ParquetReaderEE37_build_orc_equality_delete_read_specsEPNS_9OrcReaderERKNS_22TIcebergDeleteFileDescEPSt6vectorINS2_22EqualityDeleteReadSpecESaIS9_EE
_ZNK5doris18IcebergReaderMixinINS_9OrcReaderEE37_build_orc_equality_delete_read_specsEPS1_RKNS_22TIcebergDeleteFileDescEPSt6vectorINS2_22EqualityDeleteReadSpecESaIS8_EE
Line
Count
Source
700
18
        std::vector<EqualityDeleteReadSpec>* read_specs) const {
701
18
    DORIS_CHECK(reader != nullptr);
702
18
    DORIS_CHECK(read_specs != nullptr);
703
18
    const auto* delete_root = reader->get_file_root_type();
704
18
    DORIS_CHECK(delete_root != nullptr);
705
22
    for (const auto field_id : delete_file.field_ids) {
706
22
        std::vector<const orc::Type*> path;
707
22
        std::vector<std::string> names;
708
22
        std::vector<size_t> child_indexes;
709
28
        for (size_t root_index = 0; root_index < delete_root->getSubtypeCount(); ++root_index) {
710
28
            if (_find_orc_equality_delete_path(delete_root->getSubtype(root_index),
711
28
                                               delete_root->getFieldName(root_index), field_id,
712
28
                                               &path, &names, &child_indexes)) {
713
22
                break;
714
22
            }
715
28
        }
716
22
        if (path.empty()) {
717
0
            return Status::DataQualityError(
718
0
                    "missing field id {} when reading equality delete file {}", field_id,
719
0
                    delete_file.path);
720
0
        }
721
22
        const auto* root = path.front();
722
22
        const auto* leaf = path.back();
723
22
        if (leaf->getSubtypeCount() > 0) {
724
0
            return Status::NotSupported(
725
0
                    "Iceberg equality delete does not support complex column {}", names.back());
726
0
        }
727
22
        read_specs->push_back({
728
22
                .nested_field =
729
22
                        {
730
22
                                .field_id = field_id,
731
22
                                .block_name = names.back(),
732
22
                                .leaf_type = make_nullable(reader->convert_to_doris_type(leaf)),
733
22
                                .child_indexes = std::move(child_indexes),
734
22
                                .missing_value = nullptr,
735
22
                        },
736
22
                .leaf_name = names.back(),
737
22
                .root_name = names.front(),
738
22
                .root_type = make_nullable(reader->convert_to_doris_type(root)),
739
22
        });
740
22
    }
741
18
    return Status::OK();
742
18
}
743
744
template <typename BaseReader>
745
Status IcebergReaderMixin<BaseReader>::_build_equality_delete_read_specs(
746
        GenericReader* reader, const TIcebergDeleteFileDesc& delete_file,
747
46
        std::vector<EqualityDeleteReadSpec>* read_specs) const {
748
46
    DORIS_CHECK(reader != nullptr);
749
46
    DORIS_CHECK(read_specs != nullptr);
750
46
    if (auto* parquet_reader = typeid_cast<ParquetReader*>(reader)) {
751
28
        return _build_parquet_equality_delete_read_specs(parquet_reader, delete_file, read_specs);
752
28
    }
753
18
    if (auto* orc_reader = typeid_cast<OrcReader*>(reader)) {
754
18
        return _build_orc_equality_delete_read_specs(orc_reader, delete_file, read_specs);
755
18
    }
756
0
    return Status::InternalError("Unsupported format of delete file");
757
18
}
_ZNK5doris18IcebergReaderMixinINS_13ParquetReaderEE33_build_equality_delete_read_specsEPNS_13GenericReaderERKNS_22TIcebergDeleteFileDescEPSt6vectorINS2_22EqualityDeleteReadSpecESaIS9_EE
Line
Count
Source
747
28
        std::vector<EqualityDeleteReadSpec>* read_specs) const {
748
28
    DORIS_CHECK(reader != nullptr);
749
28
    DORIS_CHECK(read_specs != nullptr);
750
28
    if (auto* parquet_reader = typeid_cast<ParquetReader*>(reader)) {
751
28
        return _build_parquet_equality_delete_read_specs(parquet_reader, delete_file, read_specs);
752
28
    }
753
0
    if (auto* orc_reader = typeid_cast<OrcReader*>(reader)) {
754
0
        return _build_orc_equality_delete_read_specs(orc_reader, delete_file, read_specs);
755
0
    }
756
0
    return Status::InternalError("Unsupported format of delete file");
757
0
}
_ZNK5doris18IcebergReaderMixinINS_9OrcReaderEE33_build_equality_delete_read_specsEPNS_13GenericReaderERKNS_22TIcebergDeleteFileDescEPSt6vectorINS2_22EqualityDeleteReadSpecESaIS9_EE
Line
Count
Source
747
18
        std::vector<EqualityDeleteReadSpec>* read_specs) const {
748
18
    DORIS_CHECK(reader != nullptr);
749
18
    DORIS_CHECK(read_specs != nullptr);
750
18
    if (auto* parquet_reader = typeid_cast<ParquetReader*>(reader)) {
751
0
        return _build_parquet_equality_delete_read_specs(parquet_reader, delete_file, read_specs);
752
0
    }
753
18
    if (auto* orc_reader = typeid_cast<OrcReader*>(reader)) {
754
18
        return _build_orc_equality_delete_read_specs(orc_reader, delete_file, read_specs);
755
18
    }
756
0
    return Status::InternalError("Unsupported format of delete file");
757
18
}
758
759
template <typename BaseReader>
760
void IcebergReaderMixin<BaseReader>::_register_equality_delete_read_specs(
761
        const std::vector<EqualityDeleteReadSpec>& read_specs,
762
        std::vector<std::string>* delete_col_names, std::vector<DataTypePtr>* delete_col_types,
763
        std::vector<int>* delete_col_ids, std::vector<std::string>* read_root_names,
764
        std::vector<DataTypePtr>* read_root_types,
765
46
        std::unordered_map<std::string, uint32_t>* read_root_positions) {
766
46
    DORIS_CHECK(delete_col_names != nullptr);
767
46
    DORIS_CHECK(delete_col_types != nullptr);
768
46
    DORIS_CHECK(delete_col_ids != nullptr);
769
46
    DORIS_CHECK(read_root_names != nullptr);
770
46
    DORIS_CHECK(read_root_types != nullptr);
771
46
    DORIS_CHECK(read_root_positions != nullptr);
772
58
    for (const auto& spec : read_specs) {
773
58
        delete_col_ids->push_back(spec.nested_field.field_id);
774
58
        delete_col_names->push_back(spec.leaf_name);
775
58
        delete_col_types->push_back(spec.nested_field.leaf_type);
776
58
        if (!_id_to_block_column_name.contains(spec.nested_field.field_id)) {
777
50
            _id_to_block_column_name.emplace(spec.nested_field.field_id, spec.leaf_name);
778
50
            _expand_col_names.push_back(spec.leaf_name);
779
50
            _expand_col_field_ids.push_back(spec.nested_field.field_id);
780
50
            _expand_columns.emplace_back(spec.nested_field.leaf_type->create_column(),
781
50
                                         spec.nested_field.leaf_type, spec.leaf_name);
782
50
        }
783
58
        if (!read_root_positions->contains(spec.root_name)) {
784
54
            read_root_positions->emplace(spec.root_name, read_root_names->size());
785
54
            read_root_names->push_back(spec.root_name);
786
54
            read_root_types->push_back(spec.root_type);
787
54
        }
788
58
    }
789
46
}
_ZN5doris18IcebergReaderMixinINS_13ParquetReaderEE36_register_equality_delete_read_specsERKSt6vectorINS2_22EqualityDeleteReadSpecESaIS4_EEPS3_INSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEESaISE_EEPS3_ISt10shared_ptrIKNS_9IDataTypeEESaISL_EEPS3_IiSaIiEESH_SO_PSt13unordered_mapISE_jSt4hashISE_ESt8equal_toISE_ESaISt4pairIKSE_jEEE
Line
Count
Source
765
28
        std::unordered_map<std::string, uint32_t>* read_root_positions) {
766
28
    DORIS_CHECK(delete_col_names != nullptr);
767
28
    DORIS_CHECK(delete_col_types != nullptr);
768
28
    DORIS_CHECK(delete_col_ids != nullptr);
769
28
    DORIS_CHECK(read_root_names != nullptr);
770
28
    DORIS_CHECK(read_root_types != nullptr);
771
28
    DORIS_CHECK(read_root_positions != nullptr);
772
36
    for (const auto& spec : read_specs) {
773
36
        delete_col_ids->push_back(spec.nested_field.field_id);
774
36
        delete_col_names->push_back(spec.leaf_name);
775
36
        delete_col_types->push_back(spec.nested_field.leaf_type);
776
36
        if (!_id_to_block_column_name.contains(spec.nested_field.field_id)) {
777
32
            _id_to_block_column_name.emplace(spec.nested_field.field_id, spec.leaf_name);
778
32
            _expand_col_names.push_back(spec.leaf_name);
779
32
            _expand_col_field_ids.push_back(spec.nested_field.field_id);
780
32
            _expand_columns.emplace_back(spec.nested_field.leaf_type->create_column(),
781
32
                                         spec.nested_field.leaf_type, spec.leaf_name);
782
32
        }
783
36
        if (!read_root_positions->contains(spec.root_name)) {
784
32
            read_root_positions->emplace(spec.root_name, read_root_names->size());
785
32
            read_root_names->push_back(spec.root_name);
786
32
            read_root_types->push_back(spec.root_type);
787
32
        }
788
36
    }
789
28
}
_ZN5doris18IcebergReaderMixinINS_9OrcReaderEE36_register_equality_delete_read_specsERKSt6vectorINS2_22EqualityDeleteReadSpecESaIS4_EEPS3_INSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEESaISE_EEPS3_ISt10shared_ptrIKNS_9IDataTypeEESaISL_EEPS3_IiSaIiEESH_SO_PSt13unordered_mapISE_jSt4hashISE_ESt8equal_toISE_ESaISt4pairIKSE_jEEE
Line
Count
Source
765
18
        std::unordered_map<std::string, uint32_t>* read_root_positions) {
766
18
    DORIS_CHECK(delete_col_names != nullptr);
767
18
    DORIS_CHECK(delete_col_types != nullptr);
768
18
    DORIS_CHECK(delete_col_ids != nullptr);
769
18
    DORIS_CHECK(read_root_names != nullptr);
770
18
    DORIS_CHECK(read_root_types != nullptr);
771
18
    DORIS_CHECK(read_root_positions != nullptr);
772
22
    for (const auto& spec : read_specs) {
773
22
        delete_col_ids->push_back(spec.nested_field.field_id);
774
22
        delete_col_names->push_back(spec.leaf_name);
775
22
        delete_col_types->push_back(spec.nested_field.leaf_type);
776
22
        if (!_id_to_block_column_name.contains(spec.nested_field.field_id)) {
777
18
            _id_to_block_column_name.emplace(spec.nested_field.field_id, spec.leaf_name);
778
18
            _expand_col_names.push_back(spec.leaf_name);
779
18
            _expand_col_field_ids.push_back(spec.nested_field.field_id);
780
18
            _expand_columns.emplace_back(spec.nested_field.leaf_type->create_column(),
781
18
                                         spec.nested_field.leaf_type, spec.leaf_name);
782
18
        }
783
22
        if (!read_root_positions->contains(spec.root_name)) {
784
22
            read_root_positions->emplace(spec.root_name, read_root_names->size());
785
22
            read_root_names->push_back(spec.root_name);
786
22
            read_root_types->push_back(spec.root_type);
787
22
        }
788
22
    }
789
18
}
790
791
template <typename BaseReader>
792
Status IcebergReaderMixin<BaseReader>::_initialize_equality_delete_reader(
793
        GenericReader* reader, const std::vector<std::string>& read_root_names,
794
46
        std::unordered_map<std::string, uint32_t>* read_root_positions) {
795
46
    DORIS_CHECK(reader != nullptr);
796
46
    DORIS_CHECK(read_root_positions != nullptr);
797
46
    if (auto* parquet_reader = typeid_cast<ParquetReader*>(reader)) {
798
        // Delete files have TFileRangeDesc.size=-1, which would cause
799
        // set_fill_columns to return EndOfFile("No row group to read") when filtering is enabled.
800
28
        ParquetInitContext context;
801
28
        context.filter_groups = false;
802
28
        context.column_names = read_root_names;
803
28
        context.col_name_to_block_idx = read_root_positions;
804
28
        return parquet_reader->init_reader(&context);
805
28
    }
806
18
    auto* orc_reader = typeid_cast<OrcReader*>(reader);
807
18
    DORIS_CHECK(orc_reader != nullptr);
808
18
    OrcInitContext context;
809
18
    context.column_names = read_root_names;
810
18
    context.col_name_to_block_idx = read_root_positions;
811
18
    return orc_reader->init_reader(&context);
812
46
}
_ZN5doris18IcebergReaderMixinINS_13ParquetReaderEE34_initialize_equality_delete_readerEPNS_13GenericReaderERKSt6vectorINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEESaISB_EEPSt13unordered_mapISB_jSt4hashISB_ESt8equal_toISB_ESaISt4pairIKSB_jEEE
Line
Count
Source
794
28
        std::unordered_map<std::string, uint32_t>* read_root_positions) {
795
28
    DORIS_CHECK(reader != nullptr);
796
28
    DORIS_CHECK(read_root_positions != nullptr);
797
28
    if (auto* parquet_reader = typeid_cast<ParquetReader*>(reader)) {
798
        // Delete files have TFileRangeDesc.size=-1, which would cause
799
        // set_fill_columns to return EndOfFile("No row group to read") when filtering is enabled.
800
28
        ParquetInitContext context;
801
28
        context.filter_groups = false;
802
28
        context.column_names = read_root_names;
803
28
        context.col_name_to_block_idx = read_root_positions;
804
28
        return parquet_reader->init_reader(&context);
805
28
    }
806
0
    auto* orc_reader = typeid_cast<OrcReader*>(reader);
807
0
    DORIS_CHECK(orc_reader != nullptr);
808
0
    OrcInitContext context;
809
0
    context.column_names = read_root_names;
810
0
    context.col_name_to_block_idx = read_root_positions;
811
0
    return orc_reader->init_reader(&context);
812
28
}
_ZN5doris18IcebergReaderMixinINS_9OrcReaderEE34_initialize_equality_delete_readerEPNS_13GenericReaderERKSt6vectorINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEESaISB_EEPSt13unordered_mapISB_jSt4hashISB_ESt8equal_toISB_ESaISt4pairIKSB_jEEE
Line
Count
Source
794
18
        std::unordered_map<std::string, uint32_t>* read_root_positions) {
795
18
    DORIS_CHECK(reader != nullptr);
796
18
    DORIS_CHECK(read_root_positions != nullptr);
797
18
    if (auto* parquet_reader = typeid_cast<ParquetReader*>(reader)) {
798
        // Delete files have TFileRangeDesc.size=-1, which would cause
799
        // set_fill_columns to return EndOfFile("No row group to read") when filtering is enabled.
800
0
        ParquetInitContext context;
801
0
        context.filter_groups = false;
802
0
        context.column_names = read_root_names;
803
0
        context.col_name_to_block_idx = read_root_positions;
804
0
        return parquet_reader->init_reader(&context);
805
0
    }
806
18
    auto* orc_reader = typeid_cast<OrcReader*>(reader);
807
18
    DORIS_CHECK(orc_reader != nullptr);
808
18
    OrcInitContext context;
809
18
    context.column_names = read_root_names;
810
18
    context.col_name_to_block_idx = read_root_positions;
811
18
    return orc_reader->init_reader(&context);
812
18
}
813
814
template <typename BaseReader>
815
Status IcebergReaderMixin<BaseReader>::_merge_equality_delete_rows(
816
        GenericReader* reader, const std::vector<EqualityDeleteReadSpec>& read_specs,
817
        const std::vector<std::string>& read_root_names,
818
        const std::vector<DataTypePtr>& read_root_types,
819
        const std::unordered_map<std::string, uint32_t>& read_root_positions,
820
46
        Block* eq_file_block) const {
821
46
    DORIS_CHECK(reader != nullptr);
822
46
    DORIS_CHECK(eq_file_block != nullptr);
823
46
    bool eof = false;
824
110
    while (!eof) {
825
64
        Block raw_block;
826
140
        for (size_t index = 0; index < read_root_names.size(); ++index) {
827
76
            raw_block.insert({read_root_types[index]->create_column(), read_root_types[index],
828
76
                              read_root_names[index]});
829
76
        }
830
64
        size_t read_rows = 0;
831
64
        RETURN_IF_ERROR(reader->get_next_block(&raw_block, &read_rows, &eof));
832
64
        if (read_rows == 0) {
833
18
            continue;
834
18
        }
835
46
        Block key_block;
836
58
        for (const auto& spec : read_specs) {
837
58
            ColumnPtr key_column;
838
58
            RETURN_IF_ERROR(_extract_nested_equality_delete_column(
839
58
                    raw_block.get_by_position(read_root_positions.at(spec.root_name)).column,
840
58
                    spec.nested_field, &key_column));
841
58
            key_block.insert({std::move(key_column), spec.nested_field.leaf_type, spec.leaf_name});
842
58
        }
843
46
        ScopedMutableBlock scoped_mutable_block(eq_file_block);
844
46
        RETURN_IF_ERROR(scoped_mutable_block.mutable_block().merge(key_block));
845
46
    }
846
46
    return Status::OK();
847
46
}
_ZNK5doris18IcebergReaderMixinINS_13ParquetReaderEE27_merge_equality_delete_rowsEPNS_13GenericReaderERKSt6vectorINS2_22EqualityDeleteReadSpecESaIS6_EERKS5_INSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEESaISG_EERKS5_ISt10shared_ptrIKNS_9IDataTypeEESaISO_EERKSt13unordered_mapISG_jSt4hashISG_ESt8equal_toISG_ESaISt4pairIKSG_jEEEPNS_5BlockE
Line
Count
Source
820
28
        Block* eq_file_block) const {
821
28
    DORIS_CHECK(reader != nullptr);
822
28
    DORIS_CHECK(eq_file_block != nullptr);
823
28
    bool eof = false;
824
56
    while (!eof) {
825
28
        Block raw_block;
826
60
        for (size_t index = 0; index < read_root_names.size(); ++index) {
827
32
            raw_block.insert({read_root_types[index]->create_column(), read_root_types[index],
828
32
                              read_root_names[index]});
829
32
        }
830
28
        size_t read_rows = 0;
831
28
        RETURN_IF_ERROR(reader->get_next_block(&raw_block, &read_rows, &eof));
832
28
        if (read_rows == 0) {
833
0
            continue;
834
0
        }
835
28
        Block key_block;
836
36
        for (const auto& spec : read_specs) {
837
36
            ColumnPtr key_column;
838
36
            RETURN_IF_ERROR(_extract_nested_equality_delete_column(
839
36
                    raw_block.get_by_position(read_root_positions.at(spec.root_name)).column,
840
36
                    spec.nested_field, &key_column));
841
36
            key_block.insert({std::move(key_column), spec.nested_field.leaf_type, spec.leaf_name});
842
36
        }
843
28
        ScopedMutableBlock scoped_mutable_block(eq_file_block);
844
28
        RETURN_IF_ERROR(scoped_mutable_block.mutable_block().merge(key_block));
845
28
    }
846
28
    return Status::OK();
847
28
}
_ZNK5doris18IcebergReaderMixinINS_9OrcReaderEE27_merge_equality_delete_rowsEPNS_13GenericReaderERKSt6vectorINS2_22EqualityDeleteReadSpecESaIS6_EERKS5_INSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEESaISG_EERKS5_ISt10shared_ptrIKNS_9IDataTypeEESaISO_EERKSt13unordered_mapISG_jSt4hashISG_ESt8equal_toISG_ESaISt4pairIKSG_jEEEPNS_5BlockE
Line
Count
Source
820
18
        Block* eq_file_block) const {
821
18
    DORIS_CHECK(reader != nullptr);
822
18
    DORIS_CHECK(eq_file_block != nullptr);
823
18
    bool eof = false;
824
54
    while (!eof) {
825
36
        Block raw_block;
826
80
        for (size_t index = 0; index < read_root_names.size(); ++index) {
827
44
            raw_block.insert({read_root_types[index]->create_column(), read_root_types[index],
828
44
                              read_root_names[index]});
829
44
        }
830
36
        size_t read_rows = 0;
831
36
        RETURN_IF_ERROR(reader->get_next_block(&raw_block, &read_rows, &eof));
832
36
        if (read_rows == 0) {
833
18
            continue;
834
18
        }
835
18
        Block key_block;
836
22
        for (const auto& spec : read_specs) {
837
22
            ColumnPtr key_column;
838
22
            RETURN_IF_ERROR(_extract_nested_equality_delete_column(
839
22
                    raw_block.get_by_position(read_root_positions.at(spec.root_name)).column,
840
22
                    spec.nested_field, &key_column));
841
22
            key_block.insert({std::move(key_column), spec.nested_field.leaf_type, spec.leaf_name});
842
22
        }
843
18
        ScopedMutableBlock scoped_mutable_block(eq_file_block);
844
18
        RETURN_IF_ERROR(scoped_mutable_block.mutable_block().merge(key_block));
845
18
    }
846
18
    return Status::OK();
847
18
}
848
849
template <typename BaseReader>
850
Status IcebergReaderMixin<BaseReader>::_read_equality_delete_file(
851
47
        const TIcebergDeleteFileDesc& delete_file) {
852
47
    if (!delete_file.__isset.field_ids) [[unlikely]] {
853
0
        return Status::InternalError("missing delete field ids when reading equality delete file");
854
0
    }
855
47
    TFileRangeDesc delete_desc;
856
47
    delete_desc.__set_fs_name(this->get_scan_range().fs_name);
857
47
    delete_desc.path = delete_file.path;
858
47
    delete_desc.start_offset = 0;
859
47
    delete_desc.size = -1;
860
47
    delete_desc.file_size = delete_file.__isset.file_size ? delete_file.file_size : -1;
861
862
47
    std::unique_ptr<GenericReader> reader = _create_equality_reader(delete_desc);
863
47
    RETURN_IF_ERROR(reader->init_schema_reader());
864
46
    std::vector<EqualityDeleteReadSpec> read_specs;
865
46
    RETURN_IF_ERROR(_build_equality_delete_read_specs(reader.get(), delete_file, &read_specs));
866
867
46
    std::vector<std::string> delete_col_names;
868
46
    std::vector<DataTypePtr> delete_col_types;
869
46
    std::vector<int> delete_col_ids;
870
46
    std::vector<std::string> read_root_names;
871
46
    std::vector<DataTypePtr> read_root_types;
872
46
    std::unordered_map<std::string, uint32_t> read_root_positions;
873
46
    _register_equality_delete_read_specs(read_specs, &delete_col_names, &delete_col_types,
874
46
                                         &delete_col_ids, &read_root_names, &read_root_types,
875
46
                                         &read_root_positions);
876
46
    RETURN_IF_ERROR(_initialize_equality_delete_reader(reader.get(), read_root_names,
877
46
                                                       &read_root_positions));
878
879
46
    if (!_equality_delete_block_map.contains(delete_col_ids)) {
880
46
        _equality_delete_block_map.emplace(delete_col_ids, _equality_delete_blocks.size());
881
46
        Block block;
882
46
        _generate_equality_delete_block(&block, delete_col_names, delete_col_types);
883
46
        _equality_delete_blocks.emplace_back(std::move(block));
884
46
    }
885
46
    Block& eq_file_block = _equality_delete_blocks[_equality_delete_block_map[delete_col_ids]];
886
46
    return _merge_equality_delete_rows(reader.get(), read_specs, read_root_names, read_root_types,
887
46
                                       read_root_positions, &eq_file_block);
888
46
}
_ZN5doris18IcebergReaderMixinINS_13ParquetReaderEE26_read_equality_delete_fileERKNS_22TIcebergDeleteFileDescE
Line
Count
Source
851
29
        const TIcebergDeleteFileDesc& delete_file) {
852
29
    if (!delete_file.__isset.field_ids) [[unlikely]] {
853
0
        return Status::InternalError("missing delete field ids when reading equality delete file");
854
0
    }
855
29
    TFileRangeDesc delete_desc;
856
29
    delete_desc.__set_fs_name(this->get_scan_range().fs_name);
857
29
    delete_desc.path = delete_file.path;
858
29
    delete_desc.start_offset = 0;
859
29
    delete_desc.size = -1;
860
29
    delete_desc.file_size = delete_file.__isset.file_size ? delete_file.file_size : -1;
861
862
29
    std::unique_ptr<GenericReader> reader = _create_equality_reader(delete_desc);
863
29
    RETURN_IF_ERROR(reader->init_schema_reader());
864
28
    std::vector<EqualityDeleteReadSpec> read_specs;
865
28
    RETURN_IF_ERROR(_build_equality_delete_read_specs(reader.get(), delete_file, &read_specs));
866
867
28
    std::vector<std::string> delete_col_names;
868
28
    std::vector<DataTypePtr> delete_col_types;
869
28
    std::vector<int> delete_col_ids;
870
28
    std::vector<std::string> read_root_names;
871
28
    std::vector<DataTypePtr> read_root_types;
872
28
    std::unordered_map<std::string, uint32_t> read_root_positions;
873
28
    _register_equality_delete_read_specs(read_specs, &delete_col_names, &delete_col_types,
874
28
                                         &delete_col_ids, &read_root_names, &read_root_types,
875
28
                                         &read_root_positions);
876
28
    RETURN_IF_ERROR(_initialize_equality_delete_reader(reader.get(), read_root_names,
877
28
                                                       &read_root_positions));
878
879
28
    if (!_equality_delete_block_map.contains(delete_col_ids)) {
880
28
        _equality_delete_block_map.emplace(delete_col_ids, _equality_delete_blocks.size());
881
28
        Block block;
882
28
        _generate_equality_delete_block(&block, delete_col_names, delete_col_types);
883
28
        _equality_delete_blocks.emplace_back(std::move(block));
884
28
    }
885
28
    Block& eq_file_block = _equality_delete_blocks[_equality_delete_block_map[delete_col_ids]];
886
28
    return _merge_equality_delete_rows(reader.get(), read_specs, read_root_names, read_root_types,
887
28
                                       read_root_positions, &eq_file_block);
888
28
}
_ZN5doris18IcebergReaderMixinINS_9OrcReaderEE26_read_equality_delete_fileERKNS_22TIcebergDeleteFileDescE
Line
Count
Source
851
18
        const TIcebergDeleteFileDesc& delete_file) {
852
18
    if (!delete_file.__isset.field_ids) [[unlikely]] {
853
0
        return Status::InternalError("missing delete field ids when reading equality delete file");
854
0
    }
855
18
    TFileRangeDesc delete_desc;
856
18
    delete_desc.__set_fs_name(this->get_scan_range().fs_name);
857
18
    delete_desc.path = delete_file.path;
858
18
    delete_desc.start_offset = 0;
859
18
    delete_desc.size = -1;
860
18
    delete_desc.file_size = delete_file.__isset.file_size ? delete_file.file_size : -1;
861
862
18
    std::unique_ptr<GenericReader> reader = _create_equality_reader(delete_desc);
863
18
    RETURN_IF_ERROR(reader->init_schema_reader());
864
18
    std::vector<EqualityDeleteReadSpec> read_specs;
865
18
    RETURN_IF_ERROR(_build_equality_delete_read_specs(reader.get(), delete_file, &read_specs));
866
867
18
    std::vector<std::string> delete_col_names;
868
18
    std::vector<DataTypePtr> delete_col_types;
869
18
    std::vector<int> delete_col_ids;
870
18
    std::vector<std::string> read_root_names;
871
18
    std::vector<DataTypePtr> read_root_types;
872
18
    std::unordered_map<std::string, uint32_t> read_root_positions;
873
18
    _register_equality_delete_read_specs(read_specs, &delete_col_names, &delete_col_types,
874
18
                                         &delete_col_ids, &read_root_names, &read_root_types,
875
18
                                         &read_root_positions);
876
18
    RETURN_IF_ERROR(_initialize_equality_delete_reader(reader.get(), read_root_names,
877
18
                                                       &read_root_positions));
878
879
18
    if (!_equality_delete_block_map.contains(delete_col_ids)) {
880
18
        _equality_delete_block_map.emplace(delete_col_ids, _equality_delete_blocks.size());
881
18
        Block block;
882
18
        _generate_equality_delete_block(&block, delete_col_names, delete_col_types);
883
18
        _equality_delete_blocks.emplace_back(std::move(block));
884
18
    }
885
18
    Block& eq_file_block = _equality_delete_blocks[_equality_delete_block_map[delete_col_ids]];
886
18
    return _merge_equality_delete_rows(reader.get(), read_specs, read_root_names, read_root_types,
887
18
                                       read_root_positions, &eq_file_block);
888
18
}
889
890
template <typename BaseReader>
891
Status IcebergReaderMixin<BaseReader>::_equality_delete_base(
892
44
        const std::vector<TIcebergDeleteFileDesc>& delete_files) {
893
46
    for (const auto& delete_file : delete_files) {
894
46
        RETURN_IF_ERROR(_read_equality_delete_file(delete_file));
895
58
        for (const auto field_id : delete_file.field_ids) {
896
58
            _equality_delete_col_ids.insert(field_id);
897
58
        }
898
46
    }
899
46
    for (const auto& [delete_col_ids, block_idx] : _equality_delete_block_map) {
900
46
        auto& eq_file_block = _equality_delete_blocks[block_idx];
901
46
        auto equality_delete_impl =
902
46
                EqualityDeleteBase::get_delete_impl(&eq_file_block, delete_col_ids);
903
46
        RETURN_IF_ERROR(equality_delete_impl->init(this->get_profile()));
904
46
        _equality_delete_impls.emplace_back(std::move(equality_delete_impl));
905
46
    }
906
44
    return Status::OK();
907
44
}
_ZN5doris18IcebergReaderMixinINS_13ParquetReaderEE21_equality_delete_baseERKSt6vectorINS_22TIcebergDeleteFileDescESaIS4_EE
Line
Count
Source
892
27
        const std::vector<TIcebergDeleteFileDesc>& delete_files) {
893
28
    for (const auto& delete_file : delete_files) {
894
28
        RETURN_IF_ERROR(_read_equality_delete_file(delete_file));
895
36
        for (const auto field_id : delete_file.field_ids) {
896
36
            _equality_delete_col_ids.insert(field_id);
897
36
        }
898
28
    }
899
28
    for (const auto& [delete_col_ids, block_idx] : _equality_delete_block_map) {
900
28
        auto& eq_file_block = _equality_delete_blocks[block_idx];
901
28
        auto equality_delete_impl =
902
28
                EqualityDeleteBase::get_delete_impl(&eq_file_block, delete_col_ids);
903
28
        RETURN_IF_ERROR(equality_delete_impl->init(this->get_profile()));
904
28
        _equality_delete_impls.emplace_back(std::move(equality_delete_impl));
905
28
    }
906
27
    return Status::OK();
907
27
}
_ZN5doris18IcebergReaderMixinINS_9OrcReaderEE21_equality_delete_baseERKSt6vectorINS_22TIcebergDeleteFileDescESaIS4_EE
Line
Count
Source
892
17
        const std::vector<TIcebergDeleteFileDesc>& delete_files) {
893
18
    for (const auto& delete_file : delete_files) {
894
18
        RETURN_IF_ERROR(_read_equality_delete_file(delete_file));
895
22
        for (const auto field_id : delete_file.field_ids) {
896
22
            _equality_delete_col_ids.insert(field_id);
897
22
        }
898
18
    }
899
18
    for (const auto& [delete_col_ids, block_idx] : _equality_delete_block_map) {
900
18
        auto& eq_file_block = _equality_delete_blocks[block_idx];
901
18
        auto equality_delete_impl =
902
18
                EqualityDeleteBase::get_delete_impl(&eq_file_block, delete_col_ids);
903
18
        RETURN_IF_ERROR(equality_delete_impl->init(this->get_profile()));
904
18
        _equality_delete_impls.emplace_back(std::move(equality_delete_impl));
905
18
    }
906
17
    return Status::OK();
907
17
}
908
909
template <typename BaseReader>
910
void IcebergReaderMixin<BaseReader>::_generate_equality_delete_block(
911
        Block* block, const std::vector<std::string>& equality_delete_col_names,
912
46
        const std::vector<DataTypePtr>& equality_delete_col_types) {
913
104
    for (int i = 0; i < equality_delete_col_names.size(); ++i) {
914
58
        DataTypePtr data_type = make_nullable(equality_delete_col_types[i]);
915
58
        MutableColumnPtr data_column = data_type->create_column();
916
58
        block->insert(ColumnWithTypeAndName(std::move(data_column), data_type,
917
58
                                            equality_delete_col_names[i]));
918
58
    }
919
46
}
_ZN5doris18IcebergReaderMixinINS_13ParquetReaderEE31_generate_equality_delete_blockEPNS_5BlockERKSt6vectorINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEESaISB_EERKS5_ISt10shared_ptrIKNS_9IDataTypeEESaISJ_EE
Line
Count
Source
912
28
        const std::vector<DataTypePtr>& equality_delete_col_types) {
913
64
    for (int i = 0; i < equality_delete_col_names.size(); ++i) {
914
36
        DataTypePtr data_type = make_nullable(equality_delete_col_types[i]);
915
36
        MutableColumnPtr data_column = data_type->create_column();
916
36
        block->insert(ColumnWithTypeAndName(std::move(data_column), data_type,
917
36
                                            equality_delete_col_names[i]));
918
36
    }
919
28
}
_ZN5doris18IcebergReaderMixinINS_9OrcReaderEE31_generate_equality_delete_blockEPNS_5BlockERKSt6vectorINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEESaISB_EERKS5_ISt10shared_ptrIKNS_9IDataTypeEESaISJ_EE
Line
Count
Source
912
18
        const std::vector<DataTypePtr>& equality_delete_col_types) {
913
40
    for (int i = 0; i < equality_delete_col_names.size(); ++i) {
914
22
        DataTypePtr data_type = make_nullable(equality_delete_col_types[i]);
915
22
        MutableColumnPtr data_column = data_type->create_column();
916
22
        block->insert(ColumnWithTypeAndName(std::move(data_column), data_type,
917
22
                                            equality_delete_col_names[i]));
918
22
    }
919
18
}
920
921
template <typename BaseReader>
922
52
Status IcebergReaderMixin<BaseReader>::_expand_block_if_need(Block* block) {
923
52
    std::set<std::string> names;
924
52
    auto block_names = block->get_names();
925
52
    names.insert(block_names.begin(), block_names.end());
926
52
    for (auto& col : _expand_columns) {
927
50
        if (_missing_equality_delete_values.contains(col.name) ||
928
50
            _is_derived_equality_delete_column(col.name)) {
929
            // The reader has no column for a key that is missing from the file or extracted from
930
            // another column; on_after_read_block appends it at the batch's final row count.
931
24
            continue;
932
24
        }
933
26
        if (names.contains(col.name)) {
934
0
            return Status::InternalError("Wrong expand column '{}'", col.name);
935
0
        }
936
26
        names.insert(col.name);
937
26
        (*this->col_name_to_block_idx_ref())[col.name] = block->columns();
938
26
        block->insert({col.type->create_column(), col.type, col.name});
939
26
    }
940
52
    return Status::OK();
941
52
}
_ZN5doris18IcebergReaderMixinINS_13ParquetReaderEE21_expand_block_if_needEPNS_5BlockE
Line
Count
Source
922
32
Status IcebergReaderMixin<BaseReader>::_expand_block_if_need(Block* block) {
923
32
    std::set<std::string> names;
924
32
    auto block_names = block->get_names();
925
32
    names.insert(block_names.begin(), block_names.end());
926
32
    for (auto& col : _expand_columns) {
927
32
        if (_missing_equality_delete_values.contains(col.name) ||
928
32
            _is_derived_equality_delete_column(col.name)) {
929
            // The reader has no column for a key that is missing from the file or extracted from
930
            // another column; on_after_read_block appends it at the batch's final row count.
931
17
            continue;
932
17
        }
933
15
        if (names.contains(col.name)) {
934
0
            return Status::InternalError("Wrong expand column '{}'", col.name);
935
0
        }
936
15
        names.insert(col.name);
937
15
        (*this->col_name_to_block_idx_ref())[col.name] = block->columns();
938
15
        block->insert({col.type->create_column(), col.type, col.name});
939
15
    }
940
32
    return Status::OK();
941
32
}
_ZN5doris18IcebergReaderMixinINS_9OrcReaderEE21_expand_block_if_needEPNS_5BlockE
Line
Count
Source
922
20
Status IcebergReaderMixin<BaseReader>::_expand_block_if_need(Block* block) {
923
20
    std::set<std::string> names;
924
20
    auto block_names = block->get_names();
925
20
    names.insert(block_names.begin(), block_names.end());
926
20
    for (auto& col : _expand_columns) {
927
18
        if (_missing_equality_delete_values.contains(col.name) ||
928
18
            _is_derived_equality_delete_column(col.name)) {
929
            // The reader has no column for a key that is missing from the file or extracted from
930
            // another column; on_after_read_block appends it at the batch's final row count.
931
7
            continue;
932
7
        }
933
11
        if (names.contains(col.name)) {
934
0
            return Status::InternalError("Wrong expand column '{}'", col.name);
935
0
        }
936
11
        names.insert(col.name);
937
11
        (*this->col_name_to_block_idx_ref())[col.name] = block->columns();
938
11
        block->insert({col.type->create_column(), col.type, col.name});
939
11
    }
940
20
    return Status::OK();
941
20
}
942
943
template <typename BaseReader>
944
84
const schema::external::TStructField* IcebergReaderMixin<BaseReader>::_current_schema_root() const {
945
84
    const auto& scan_params = this->get_scan_params();
946
84
    if (!scan_params.__isset.history_schema_info || scan_params.history_schema_info.empty()) {
947
0
        return nullptr;
948
0
    }
949
84
    const schema::external::TSchema* current_schema = &scan_params.history_schema_info.front();
950
84
    if (scan_params.__isset.current_schema_id) {
951
84
        const auto schema_it = std::ranges::find_if(
952
84
                scan_params.history_schema_info, [&](const schema::external::TSchema& schema) {
953
84
                    return schema.__isset.schema_id &&
954
84
                           schema.schema_id == scan_params.current_schema_id;
955
84
                });
_ZZNK5doris18IcebergReaderMixinINS_13ParquetReaderEE20_current_schema_rootEvENKUlRKNS_6schema8external7TSchemaEE_clES7_
Line
Count
Source
952
63
                scan_params.history_schema_info, [&](const schema::external::TSchema& schema) {
953
63
                    return schema.__isset.schema_id &&
954
63
                           schema.schema_id == scan_params.current_schema_id;
955
63
                });
_ZZNK5doris18IcebergReaderMixinINS_9OrcReaderEE20_current_schema_rootEvENKUlRKNS_6schema8external7TSchemaEE_clES7_
Line
Count
Source
952
21
                scan_params.history_schema_info, [&](const schema::external::TSchema& schema) {
953
21
                    return schema.__isset.schema_id &&
954
21
                           schema.schema_id == scan_params.current_schema_id;
955
21
                });
956
84
        if (schema_it == scan_params.history_schema_info.end()) {
957
0
            return nullptr;
958
0
        }
959
84
        current_schema = &*schema_it;
960
84
    }
961
84
    return current_schema->__isset.root_field ? &current_schema->root_field : nullptr;
962
84
}
_ZNK5doris18IcebergReaderMixinINS_13ParquetReaderEE20_current_schema_rootEv
Line
Count
Source
944
63
const schema::external::TStructField* IcebergReaderMixin<BaseReader>::_current_schema_root() const {
945
63
    const auto& scan_params = this->get_scan_params();
946
63
    if (!scan_params.__isset.history_schema_info || scan_params.history_schema_info.empty()) {
947
0
        return nullptr;
948
0
    }
949
63
    const schema::external::TSchema* current_schema = &scan_params.history_schema_info.front();
950
63
    if (scan_params.__isset.current_schema_id) {
951
63
        const auto schema_it = std::ranges::find_if(
952
63
                scan_params.history_schema_info, [&](const schema::external::TSchema& schema) {
953
63
                    return schema.__isset.schema_id &&
954
63
                           schema.schema_id == scan_params.current_schema_id;
955
63
                });
956
63
        if (schema_it == scan_params.history_schema_info.end()) {
957
0
            return nullptr;
958
0
        }
959
63
        current_schema = &*schema_it;
960
63
    }
961
63
    return current_schema->__isset.root_field ? &current_schema->root_field : nullptr;
962
63
}
_ZNK5doris18IcebergReaderMixinINS_9OrcReaderEE20_current_schema_rootEv
Line
Count
Source
944
21
const schema::external::TStructField* IcebergReaderMixin<BaseReader>::_current_schema_root() const {
945
21
    const auto& scan_params = this->get_scan_params();
946
21
    if (!scan_params.__isset.history_schema_info || scan_params.history_schema_info.empty()) {
947
0
        return nullptr;
948
0
    }
949
21
    const schema::external::TSchema* current_schema = &scan_params.history_schema_info.front();
950
21
    if (scan_params.__isset.current_schema_id) {
951
21
        const auto schema_it = std::ranges::find_if(
952
21
                scan_params.history_schema_info, [&](const schema::external::TSchema& schema) {
953
21
                    return schema.__isset.schema_id &&
954
21
                           schema.schema_id == scan_params.current_schema_id;
955
21
                });
956
21
        if (schema_it == scan_params.history_schema_info.end()) {
957
0
            return nullptr;
958
0
        }
959
21
        current_schema = &*schema_it;
960
21
    }
961
21
    return current_schema->__isset.root_field ? &current_schema->root_field : nullptr;
962
21
}
963
964
template <typename BaseReader>
965
const schema::external::TField* IcebergReaderMixin<BaseReader>::_find_current_schema_field(
966
5
        const std::string& name) const {
967
5
    const auto* root = _current_schema_root();
968
5
    if (root == nullptr) {
969
0
        return nullptr;
970
0
    }
971
10
    const auto field = std::ranges::find_if(root->fields, [&](const auto& field_ptr) {
972
10
        return field_ptr.__isset.field_ptr && field_ptr.field_ptr != nullptr &&
973
10
               field_ptr.field_ptr->__isset.name && iequal(field_ptr.field_ptr->name, name);
974
10
    });
_ZZNK5doris18IcebergReaderMixinINS_13ParquetReaderEE26_find_current_schema_fieldERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEENKUlRKT_E_clINS_6schema8external9TFieldPtrEEEDaSD_
Line
Count
Source
971
8
    const auto field = std::ranges::find_if(root->fields, [&](const auto& field_ptr) {
972
8
        return field_ptr.__isset.field_ptr && field_ptr.field_ptr != nullptr &&
973
8
               field_ptr.field_ptr->__isset.name && iequal(field_ptr.field_ptr->name, name);
974
8
    });
_ZZNK5doris18IcebergReaderMixinINS_9OrcReaderEE26_find_current_schema_fieldERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEENKUlRKT_E_clINS_6schema8external9TFieldPtrEEEDaSD_
Line
Count
Source
971
2
    const auto field = std::ranges::find_if(root->fields, [&](const auto& field_ptr) {
972
2
        return field_ptr.__isset.field_ptr && field_ptr.field_ptr != nullptr &&
973
2
               field_ptr.field_ptr->__isset.name && iequal(field_ptr.field_ptr->name, name);
974
2
    });
975
5
    return field == root->fields.end() ? nullptr : field->field_ptr.get();
976
5
}
_ZNK5doris18IcebergReaderMixinINS_13ParquetReaderEE26_find_current_schema_fieldERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE
Line
Count
Source
966
4
        const std::string& name) const {
967
4
    const auto* root = _current_schema_root();
968
4
    if (root == nullptr) {
969
0
        return nullptr;
970
0
    }
971
4
    const auto field = std::ranges::find_if(root->fields, [&](const auto& field_ptr) {
972
4
        return field_ptr.__isset.field_ptr && field_ptr.field_ptr != nullptr &&
973
4
               field_ptr.field_ptr->__isset.name && iequal(field_ptr.field_ptr->name, name);
974
4
    });
975
4
    return field == root->fields.end() ? nullptr : field->field_ptr.get();
976
4
}
_ZNK5doris18IcebergReaderMixinINS_9OrcReaderEE26_find_current_schema_fieldERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE
Line
Count
Source
966
1
        const std::string& name) const {
967
1
    const auto* root = _current_schema_root();
968
1
    if (root == nullptr) {
969
0
        return nullptr;
970
0
    }
971
1
    const auto field = std::ranges::find_if(root->fields, [&](const auto& field_ptr) {
972
1
        return field_ptr.__isset.field_ptr && field_ptr.field_ptr != nullptr &&
973
1
               field_ptr.field_ptr->__isset.name && iequal(field_ptr.field_ptr->name, name);
974
1
    });
975
1
    return field == root->fields.end() ? nullptr : field->field_ptr.get();
976
1
}
977
978
template <typename BaseReader>
979
const schema::external::TField* IcebergReaderMixin<BaseReader>::_find_schema_field(
980
        int32_t field_id) const {
981
    auto path = _find_schema_field_path(field_id);
982
    return path.empty() ? nullptr : path.back();
983
}
984
985
template <typename BaseReader>
986
bool IcebergReaderMixin<BaseReader>::_find_schema_field_path_in_field(
987
        const schema::external::TField* field, int32_t field_id,
988
259
        std::vector<const schema::external::TField*>* path) {
989
259
    DORIS_CHECK(path != nullptr);
990
259
    if (field == nullptr) {
991
0
        return false;
992
0
    }
993
259
    path->push_back(field);
994
259
    if (field->__isset.id && field->id == field_id) {
995
78
        return true;
996
78
    }
997
181
    if (field->__isset.nestedField) {
998
46
        if (field->nestedField.__isset.struct_field &&
999
46
            field->nestedField.struct_field.__isset.fields) {
1000
46
            for (const auto& child_ptr : field->nestedField.struct_field.fields) {
1001
45
                if (child_ptr.__isset.field_ptr && child_ptr.field_ptr != nullptr &&
1002
45
                    _find_schema_field_path_in_field(child_ptr.field_ptr.get(), field_id, path)) {
1003
34
                    return true;
1004
34
                }
1005
45
            }
1006
46
        } else if (field->nestedField.__isset.array_field &&
1007
0
                   field->nestedField.array_field.__isset.item_field) {
1008
0
            const auto& child_ptr = field->nestedField.array_field.item_field;
1009
0
            if (child_ptr.__isset.field_ptr && child_ptr.field_ptr != nullptr &&
1010
0
                _find_schema_field_path_in_field(child_ptr.field_ptr.get(), field_id, path)) {
1011
0
                return true;
1012
0
            }
1013
0
        } else if (field->nestedField.__isset.map_field) {
1014
0
            const auto& map = field->nestedField.map_field;
1015
0
            if (map.__isset.key_field && map.key_field.__isset.field_ptr &&
1016
0
                map.key_field.field_ptr != nullptr &&
1017
0
                _find_schema_field_path_in_field(map.key_field.field_ptr.get(), field_id, path)) {
1018
0
                return true;
1019
0
            }
1020
0
            if (map.__isset.value_field && map.value_field.__isset.field_ptr &&
1021
0
                map.value_field.field_ptr != nullptr &&
1022
0
                _find_schema_field_path_in_field(map.value_field.field_ptr.get(), field_id, path)) {
1023
0
                return true;
1024
0
            }
1025
0
        }
1026
46
    }
1027
147
    path->pop_back();
1028
147
    return false;
1029
181
}
_ZN5doris18IcebergReaderMixinINS_13ParquetReaderEE32_find_schema_field_path_in_fieldEPKNS_6schema8external6TFieldEiPSt6vectorIS7_SaIS7_EE
Line
Count
Source
988
189
        std::vector<const schema::external::TField*>* path) {
989
189
    DORIS_CHECK(path != nullptr);
990
189
    if (field == nullptr) {
991
0
        return false;
992
0
    }
993
189
    path->push_back(field);
994
189
    if (field->__isset.id && field->id == field_id) {
995
58
        return true;
996
58
    }
997
131
    if (field->__isset.nestedField) {
998
36
        if (field->nestedField.__isset.struct_field &&
999
36
            field->nestedField.struct_field.__isset.fields) {
1000
37
            for (const auto& child_ptr : field->nestedField.struct_field.fields) {
1001
37
                if (child_ptr.__isset.field_ptr && child_ptr.field_ptr != nullptr &&
1002
37
                    _find_schema_field_path_in_field(child_ptr.field_ptr.get(), field_id, path)) {
1003
28
                    return true;
1004
28
                }
1005
37
            }
1006
36
        } else if (field->nestedField.__isset.array_field &&
1007
0
                   field->nestedField.array_field.__isset.item_field) {
1008
0
            const auto& child_ptr = field->nestedField.array_field.item_field;
1009
0
            if (child_ptr.__isset.field_ptr && child_ptr.field_ptr != nullptr &&
1010
0
                _find_schema_field_path_in_field(child_ptr.field_ptr.get(), field_id, path)) {
1011
0
                return true;
1012
0
            }
1013
0
        } else if (field->nestedField.__isset.map_field) {
1014
0
            const auto& map = field->nestedField.map_field;
1015
0
            if (map.__isset.key_field && map.key_field.__isset.field_ptr &&
1016
0
                map.key_field.field_ptr != nullptr &&
1017
0
                _find_schema_field_path_in_field(map.key_field.field_ptr.get(), field_id, path)) {
1018
0
                return true;
1019
0
            }
1020
0
            if (map.__isset.value_field && map.value_field.__isset.field_ptr &&
1021
0
                map.value_field.field_ptr != nullptr &&
1022
0
                _find_schema_field_path_in_field(map.value_field.field_ptr.get(), field_id, path)) {
1023
0
                return true;
1024
0
            }
1025
0
        }
1026
36
    }
1027
103
    path->pop_back();
1028
103
    return false;
1029
131
}
_ZN5doris18IcebergReaderMixinINS_9OrcReaderEE32_find_schema_field_path_in_fieldEPKNS_6schema8external6TFieldEiPSt6vectorIS7_SaIS7_EE
Line
Count
Source
988
70
        std::vector<const schema::external::TField*>* path) {
989
70
    DORIS_CHECK(path != nullptr);
990
70
    if (field == nullptr) {
991
0
        return false;
992
0
    }
993
70
    path->push_back(field);
994
70
    if (field->__isset.id && field->id == field_id) {
995
20
        return true;
996
20
    }
997
50
    if (field->__isset.nestedField) {
998
10
        if (field->nestedField.__isset.struct_field &&
999
10
            field->nestedField.struct_field.__isset.fields) {
1000
10
            for (const auto& child_ptr : field->nestedField.struct_field.fields) {
1001
8
                if (child_ptr.__isset.field_ptr && child_ptr.field_ptr != nullptr &&
1002
8
                    _find_schema_field_path_in_field(child_ptr.field_ptr.get(), field_id, path)) {
1003
6
                    return true;
1004
6
                }
1005
8
            }
1006
10
        } else if (field->nestedField.__isset.array_field &&
1007
0
                   field->nestedField.array_field.__isset.item_field) {
1008
0
            const auto& child_ptr = field->nestedField.array_field.item_field;
1009
0
            if (child_ptr.__isset.field_ptr && child_ptr.field_ptr != nullptr &&
1010
0
                _find_schema_field_path_in_field(child_ptr.field_ptr.get(), field_id, path)) {
1011
0
                return true;
1012
0
            }
1013
0
        } else if (field->nestedField.__isset.map_field) {
1014
0
            const auto& map = field->nestedField.map_field;
1015
0
            if (map.__isset.key_field && map.key_field.__isset.field_ptr &&
1016
0
                map.key_field.field_ptr != nullptr &&
1017
0
                _find_schema_field_path_in_field(map.key_field.field_ptr.get(), field_id, path)) {
1018
0
                return true;
1019
0
            }
1020
0
            if (map.__isset.value_field && map.value_field.__isset.field_ptr &&
1021
0
                map.value_field.field_ptr != nullptr &&
1022
0
                _find_schema_field_path_in_field(map.value_field.field_ptr.get(), field_id, path)) {
1023
0
                return true;
1024
0
            }
1025
0
        }
1026
10
    }
1027
44
    path->pop_back();
1028
44
    return false;
1029
50
}
1030
1031
template <typename BaseReader>
1032
bool IcebergReaderMixin<BaseReader>::_find_schema_field_path_in_root(
1033
        const schema::external::TStructField* root, int32_t field_id,
1034
96
        std::vector<const schema::external::TField*>* path) {
1035
96
    DORIS_CHECK(path != nullptr);
1036
96
    if (root == nullptr || !root->__isset.fields) {
1037
0
        return false;
1038
0
    }
1039
214
    return std::ranges::any_of(root->fields, [&](const auto& field_ptr) {
1040
214
        return field_ptr.__isset.field_ptr && field_ptr.field_ptr != nullptr &&
1041
214
               _find_schema_field_path_in_field(field_ptr.field_ptr.get(), field_id, path);
1042
214
    });
_ZZN5doris18IcebergReaderMixinINS_13ParquetReaderEE31_find_schema_field_path_in_rootEPKNS_6schema8external12TStructFieldEiPSt6vectorIPKNS4_6TFieldESaISB_EEENKUlRKT_E_clINS4_9TFieldPtrEEEDaSH_
Line
Count
Source
1039
152
    return std::ranges::any_of(root->fields, [&](const auto& field_ptr) {
1040
152
        return field_ptr.__isset.field_ptr && field_ptr.field_ptr != nullptr &&
1041
152
               _find_schema_field_path_in_field(field_ptr.field_ptr.get(), field_id, path);
1042
152
    });
_ZZN5doris18IcebergReaderMixinINS_9OrcReaderEE31_find_schema_field_path_in_rootEPKNS_6schema8external12TStructFieldEiPSt6vectorIPKNS4_6TFieldESaISB_EEENKUlRKT_E_clINS4_9TFieldPtrEEEDaSH_
Line
Count
Source
1039
62
    return std::ranges::any_of(root->fields, [&](const auto& field_ptr) {
1040
62
        return field_ptr.__isset.field_ptr && field_ptr.field_ptr != nullptr &&
1041
62
               _find_schema_field_path_in_field(field_ptr.field_ptr.get(), field_id, path);
1042
62
    });
1043
96
}
_ZN5doris18IcebergReaderMixinINS_13ParquetReaderEE31_find_schema_field_path_in_rootEPKNS_6schema8external12TStructFieldEiPSt6vectorIPKNS4_6TFieldESaISB_EE
Line
Count
Source
1034
72
        std::vector<const schema::external::TField*>* path) {
1035
72
    DORIS_CHECK(path != nullptr);
1036
72
    if (root == nullptr || !root->__isset.fields) {
1037
0
        return false;
1038
0
    }
1039
72
    return std::ranges::any_of(root->fields, [&](const auto& field_ptr) {
1040
72
        return field_ptr.__isset.field_ptr && field_ptr.field_ptr != nullptr &&
1041
72
               _find_schema_field_path_in_field(field_ptr.field_ptr.get(), field_id, path);
1042
72
    });
1043
72
}
_ZN5doris18IcebergReaderMixinINS_9OrcReaderEE31_find_schema_field_path_in_rootEPKNS_6schema8external12TStructFieldEiPSt6vectorIPKNS4_6TFieldESaISB_EE
Line
Count
Source
1034
24
        std::vector<const schema::external::TField*>* path) {
1035
24
    DORIS_CHECK(path != nullptr);
1036
24
    if (root == nullptr || !root->__isset.fields) {
1037
0
        return false;
1038
0
    }
1039
24
    return std::ranges::any_of(root->fields, [&](const auto& field_ptr) {
1040
24
        return field_ptr.__isset.field_ptr && field_ptr.field_ptr != nullptr &&
1041
24
               _find_schema_field_path_in_field(field_ptr.field_ptr.get(), field_id, path);
1042
24
    });
1043
24
}
1044
1045
template <typename BaseReader>
1046
std::vector<const schema::external::TField*>
1047
68
IcebergReaderMixin<BaseReader>::_find_schema_field_path(int32_t field_id) const {
1048
68
    std::vector<const schema::external::TField*> path;
1049
68
    if (_find_schema_field_path_in_root(_current_schema_root(), field_id, &path)) {
1050
59
        return path;
1051
59
    }
1052
1053
    // Equality deletes remain applicable after their key is dropped from the current schema.
1054
    // FE can retain that field's metadata in history_schema_info; field IDs are stable, so recover
1055
    // the original initial-default/required semantics from any historical schema that contains it.
1056
9
    const auto& scan_params = this->get_scan_params();
1057
9
    if (!scan_params.__isset.history_schema_info) {
1058
0
        return {};
1059
0
    }
1060
17
    for (const auto& schema : scan_params.history_schema_info) {
1061
17
        if (!schema.__isset.root_field) {
1062
0
            continue;
1063
0
        }
1064
17
        path.clear();
1065
17
        if (_find_schema_field_path_in_root(&schema.root_field, field_id, &path)) {
1066
8
            return path;
1067
8
        }
1068
17
    }
1069
1
    return {};
1070
9
}
_ZNK5doris18IcebergReaderMixinINS_13ParquetReaderEE23_find_schema_field_pathEi
Line
Count
Source
1047
48
IcebergReaderMixin<BaseReader>::_find_schema_field_path(int32_t field_id) const {
1048
48
    std::vector<const schema::external::TField*> path;
1049
48
    if (_find_schema_field_path_in_root(_current_schema_root(), field_id, &path)) {
1050
41
        return path;
1051
41
    }
1052
1053
    // Equality deletes remain applicable after their key is dropped from the current schema.
1054
    // FE can retain that field's metadata in history_schema_info; field IDs are stable, so recover
1055
    // the original initial-default/required semantics from any historical schema that contains it.
1056
7
    const auto& scan_params = this->get_scan_params();
1057
7
    if (!scan_params.__isset.history_schema_info) {
1058
0
        return {};
1059
0
    }
1060
13
    for (const auto& schema : scan_params.history_schema_info) {
1061
13
        if (!schema.__isset.root_field) {
1062
0
            continue;
1063
0
        }
1064
13
        path.clear();
1065
13
        if (_find_schema_field_path_in_root(&schema.root_field, field_id, &path)) {
1066
6
            return path;
1067
6
        }
1068
13
    }
1069
1
    return {};
1070
7
}
_ZNK5doris18IcebergReaderMixinINS_9OrcReaderEE23_find_schema_field_pathEi
Line
Count
Source
1047
20
IcebergReaderMixin<BaseReader>::_find_schema_field_path(int32_t field_id) const {
1048
20
    std::vector<const schema::external::TField*> path;
1049
20
    if (_find_schema_field_path_in_root(_current_schema_root(), field_id, &path)) {
1050
18
        return path;
1051
18
    }
1052
1053
    // Equality deletes remain applicable after their key is dropped from the current schema.
1054
    // FE can retain that field's metadata in history_schema_info; field IDs are stable, so recover
1055
    // the original initial-default/required semantics from any historical schema that contains it.
1056
2
    const auto& scan_params = this->get_scan_params();
1057
2
    if (!scan_params.__isset.history_schema_info) {
1058
0
        return {};
1059
0
    }
1060
4
    for (const auto& schema : scan_params.history_schema_info) {
1061
4
        if (!schema.__isset.root_field) {
1062
0
            continue;
1063
0
        }
1064
4
        path.clear();
1065
4
        if (_find_schema_field_path_in_root(&schema.root_field, field_id, &path)) {
1066
2
            return path;
1067
2
        }
1068
4
    }
1069
0
    return {};
1070
2
}
1071
1072
template <typename BaseReader>
1073
Status IcebergReaderMixin<BaseReader>::_extract_nested_equality_delete_column(
1074
        const ColumnPtr& root_column, const NestedEqualityDeleteColumn& nested_field,
1075
90
        ColumnPtr* leaf_column) const {
1076
90
    DORIS_CHECK(static_cast<bool>(root_column));
1077
90
    DORIS_CHECK(nested_field.leaf_type != nullptr);
1078
90
    DORIS_CHECK(leaf_column != nullptr);
1079
90
    const IColumn* current = root_column.get();
1080
90
    std::vector<const NullMap*> ancestor_null_maps;
1081
90
    for (size_t child_index : nested_field.child_indexes) {
1082
53
        if (const auto* nullable = check_and_get_column<ColumnNullable>(*current);
1083
53
            nullable != nullptr) {
1084
53
            ancestor_null_maps.push_back(&nullable->get_null_map_data());
1085
53
            current = &nullable->get_nested_column();
1086
53
        }
1087
53
        const auto* struct_column = check_and_get_column<ColumnStruct>(*current);
1088
53
        if (struct_column == nullptr || child_index >= struct_column->tuple_size()) {
1089
0
            return Status::InternalError(
1090
0
                    "Iceberg equality delete path for field id {} is absent from column {}",
1091
0
                    nested_field.field_id, root_column->get_name());
1092
0
        }
1093
53
        current = &struct_column->get_column(child_index);
1094
53
    }
1095
90
    if (const auto* nullable = check_and_get_column<ColumnNullable>(*current);
1096
90
        nullable != nullptr) {
1097
90
        ancestor_null_maps.push_back(&nullable->get_null_map_data());
1098
90
        current = &nullable->get_nested_column();
1099
90
    }
1100
90
    ColumnPtr repeated_missing_value;
1101
90
    if (static_cast<bool>(nested_field.missing_value)) {
1102
2
        repeated_missing_value = iceberg::repeat_initial_default_column(nested_field.missing_value,
1103
2
                                                                        root_column->size());
1104
2
        current = repeated_missing_value.get();
1105
2
        if (const auto* nullable = check_and_get_column<ColumnNullable>(*current);
1106
2
            nullable != nullptr) {
1107
2
            ancestor_null_maps.push_back(&nullable->get_null_map_data());
1108
2
            current = &nullable->get_nested_column();
1109
2
        }
1110
2
    }
1111
1112
90
    auto result = ColumnNullable::create(remove_nullable(nested_field.leaf_type)->create_column(),
1113
90
                                         ColumnUInt8::create());
1114
90
    auto& result_data = result->get_nested_column();
1115
90
    auto& result_null_map = result->get_null_map_data();
1116
90
    result_data.reserve(root_column->size());
1117
90
    result_null_map.reserve(root_column->size());
1118
238
    for (size_t row = 0; row < root_column->size(); ++row) {
1119
148
        bool is_null = false;
1120
251
        for (const auto* null_map : ancestor_null_maps) {
1121
251
            if ((*null_map)[row] != 0) {
1122
10
                is_null = true;
1123
10
                break;
1124
10
            }
1125
251
        }
1126
148
        if (is_null) {
1127
10
            result_data.insert_default();
1128
10
            result_null_map.push_back(1);
1129
138
        } else {
1130
138
            result_data.insert_from(*current, row);
1131
138
            result_null_map.push_back(0);
1132
138
        }
1133
148
    }
1134
90
    *leaf_column = std::move(result);
1135
90
    return Status::OK();
1136
90
}
_ZNK5doris18IcebergReaderMixinINS_13ParquetReaderEE38_extract_nested_equality_delete_columnERKNS_3COWINS_7IColumnEE13immutable_ptrIS4_EERKNS2_26NestedEqualityDeleteColumnEPS7_
Line
Count
Source
1075
59
        ColumnPtr* leaf_column) const {
1076
59
    DORIS_CHECK(static_cast<bool>(root_column));
1077
59
    DORIS_CHECK(nested_field.leaf_type != nullptr);
1078
59
    DORIS_CHECK(leaf_column != nullptr);
1079
59
    const IColumn* current = root_column.get();
1080
59
    std::vector<const NullMap*> ancestor_null_maps;
1081
59
    for (size_t child_index : nested_field.child_indexes) {
1082
40
        if (const auto* nullable = check_and_get_column<ColumnNullable>(*current);
1083
40
            nullable != nullptr) {
1084
40
            ancestor_null_maps.push_back(&nullable->get_null_map_data());
1085
40
            current = &nullable->get_nested_column();
1086
40
        }
1087
40
        const auto* struct_column = check_and_get_column<ColumnStruct>(*current);
1088
40
        if (struct_column == nullptr || child_index >= struct_column->tuple_size()) {
1089
0
            return Status::InternalError(
1090
0
                    "Iceberg equality delete path for field id {} is absent from column {}",
1091
0
                    nested_field.field_id, root_column->get_name());
1092
0
        }
1093
40
        current = &struct_column->get_column(child_index);
1094
40
    }
1095
59
    if (const auto* nullable = check_and_get_column<ColumnNullable>(*current);
1096
59
        nullable != nullptr) {
1097
59
        ancestor_null_maps.push_back(&nullable->get_null_map_data());
1098
59
        current = &nullable->get_nested_column();
1099
59
    }
1100
59
    ColumnPtr repeated_missing_value;
1101
59
    if (static_cast<bool>(nested_field.missing_value)) {
1102
1
        repeated_missing_value = iceberg::repeat_initial_default_column(nested_field.missing_value,
1103
1
                                                                        root_column->size());
1104
1
        current = repeated_missing_value.get();
1105
1
        if (const auto* nullable = check_and_get_column<ColumnNullable>(*current);
1106
1
            nullable != nullptr) {
1107
1
            ancestor_null_maps.push_back(&nullable->get_null_map_data());
1108
1
            current = &nullable->get_nested_column();
1109
1
        }
1110
1
    }
1111
1112
59
    auto result = ColumnNullable::create(remove_nullable(nested_field.leaf_type)->create_column(),
1113
59
                                         ColumnUInt8::create());
1114
59
    auto& result_data = result->get_nested_column();
1115
59
    auto& result_null_map = result->get_null_map_data();
1116
59
    result_data.reserve(root_column->size());
1117
59
    result_null_map.reserve(root_column->size());
1118
158
    for (size_t row = 0; row < root_column->size(); ++row) {
1119
99
        bool is_null = false;
1120
175
        for (const auto* null_map : ancestor_null_maps) {
1121
175
            if ((*null_map)[row] != 0) {
1122
5
                is_null = true;
1123
5
                break;
1124
5
            }
1125
175
        }
1126
99
        if (is_null) {
1127
5
            result_data.insert_default();
1128
5
            result_null_map.push_back(1);
1129
94
        } else {
1130
94
            result_data.insert_from(*current, row);
1131
94
            result_null_map.push_back(0);
1132
94
        }
1133
99
    }
1134
59
    *leaf_column = std::move(result);
1135
59
    return Status::OK();
1136
59
}
_ZNK5doris18IcebergReaderMixinINS_9OrcReaderEE38_extract_nested_equality_delete_columnERKNS_3COWINS_7IColumnEE13immutable_ptrIS4_EERKNS2_26NestedEqualityDeleteColumnEPS7_
Line
Count
Source
1075
31
        ColumnPtr* leaf_column) const {
1076
31
    DORIS_CHECK(static_cast<bool>(root_column));
1077
31
    DORIS_CHECK(nested_field.leaf_type != nullptr);
1078
31
    DORIS_CHECK(leaf_column != nullptr);
1079
31
    const IColumn* current = root_column.get();
1080
31
    std::vector<const NullMap*> ancestor_null_maps;
1081
31
    for (size_t child_index : nested_field.child_indexes) {
1082
13
        if (const auto* nullable = check_and_get_column<ColumnNullable>(*current);
1083
13
            nullable != nullptr) {
1084
13
            ancestor_null_maps.push_back(&nullable->get_null_map_data());
1085
13
            current = &nullable->get_nested_column();
1086
13
        }
1087
13
        const auto* struct_column = check_and_get_column<ColumnStruct>(*current);
1088
13
        if (struct_column == nullptr || child_index >= struct_column->tuple_size()) {
1089
0
            return Status::InternalError(
1090
0
                    "Iceberg equality delete path for field id {} is absent from column {}",
1091
0
                    nested_field.field_id, root_column->get_name());
1092
0
        }
1093
13
        current = &struct_column->get_column(child_index);
1094
13
    }
1095
31
    if (const auto* nullable = check_and_get_column<ColumnNullable>(*current);
1096
31
        nullable != nullptr) {
1097
31
        ancestor_null_maps.push_back(&nullable->get_null_map_data());
1098
31
        current = &nullable->get_nested_column();
1099
31
    }
1100
31
    ColumnPtr repeated_missing_value;
1101
31
    if (static_cast<bool>(nested_field.missing_value)) {
1102
1
        repeated_missing_value = iceberg::repeat_initial_default_column(nested_field.missing_value,
1103
1
                                                                        root_column->size());
1104
1
        current = repeated_missing_value.get();
1105
1
        if (const auto* nullable = check_and_get_column<ColumnNullable>(*current);
1106
1
            nullable != nullptr) {
1107
1
            ancestor_null_maps.push_back(&nullable->get_null_map_data());
1108
1
            current = &nullable->get_nested_column();
1109
1
        }
1110
1
    }
1111
1112
31
    auto result = ColumnNullable::create(remove_nullable(nested_field.leaf_type)->create_column(),
1113
31
                                         ColumnUInt8::create());
1114
31
    auto& result_data = result->get_nested_column();
1115
31
    auto& result_null_map = result->get_null_map_data();
1116
31
    result_data.reserve(root_column->size());
1117
31
    result_null_map.reserve(root_column->size());
1118
80
    for (size_t row = 0; row < root_column->size(); ++row) {
1119
49
        bool is_null = false;
1120
76
        for (const auto* null_map : ancestor_null_maps) {
1121
76
            if ((*null_map)[row] != 0) {
1122
5
                is_null = true;
1123
5
                break;
1124
5
            }
1125
76
        }
1126
49
        if (is_null) {
1127
5
            result_data.insert_default();
1128
5
            result_null_map.push_back(1);
1129
44
        } else {
1130
44
            result_data.insert_from(*current, row);
1131
44
            result_null_map.push_back(0);
1132
44
        }
1133
49
    }
1134
31
    *leaf_column = std::move(result);
1135
31
    return Status::OK();
1136
31
}
1137
1138
template <typename BaseReader>
1139
52
Status IcebergReaderMixin<BaseReader>::_materialize_nested_equality_delete_columns(Block* block) {
1140
52
    DORIS_CHECK(block != nullptr);
1141
    // A carrier may be the source of other keys under the same physical root, so extract every
1142
    // leaf before replacing any carrier column with its own leaf.
1143
52
    std::vector<ColumnPtr> leaves;
1144
52
    leaves.reserve(_nested_equality_delete_columns.size());
1145
52
    for (const auto& nested_field : _nested_equality_delete_columns) {
1146
32
        const auto& source_name = nested_field.source_block_name.empty()
1147
32
                                          ? nested_field.block_name
1148
32
                                          : nested_field.source_block_name;
1149
32
        const auto source = this->col_name_to_block_idx_ref()->find(source_name);
1150
32
        DORIS_CHECK(source != this->col_name_to_block_idx_ref()->end());
1151
32
        DORIS_CHECK(source->second < block->columns());
1152
32
        ColumnPtr leaf;
1153
32
        RETURN_IF_ERROR(_extract_nested_equality_delete_column(
1154
32
                block->get_by_position(source->second).column, nested_field, &leaf));
1155
32
        leaves.push_back(std::move(leaf));
1156
32
    }
1157
84
    for (size_t index = 0; index < leaves.size(); ++index) {
1158
32
        const auto& nested_field = _nested_equality_delete_columns[index];
1159
32
        const auto type = make_nullable(nested_field.leaf_type);
1160
32
        auto& positions = *this->col_name_to_block_idx_ref();
1161
32
        if (!nested_field.source_block_name.empty()) {
1162
            // A key extracted from a projected root or another key's carrier is not read, so the
1163
            // block gets its column only now.
1164
11
            DORIS_CHECK(!positions.contains(nested_field.block_name));
1165
11
            positions[nested_field.block_name] = block->columns();
1166
11
            block->insert({std::move(leaves[index]), type, nested_field.block_name});
1167
11
            continue;
1168
11
        }
1169
21
        const auto target = positions.find(nested_field.block_name);
1170
21
        DORIS_CHECK(target != positions.end());
1171
21
        DORIS_CHECK(target->second < block->columns());
1172
21
        auto& column = block->get_by_position(target->second);
1173
21
        column.column = std::move(leaves[index]);
1174
21
        column.type = type;
1175
21
    }
1176
52
    return Status::OK();
1177
52
}
_ZN5doris18IcebergReaderMixinINS_13ParquetReaderEE43_materialize_nested_equality_delete_columnsEPNS_5BlockE
Line
Count
Source
1139
32
Status IcebergReaderMixin<BaseReader>::_materialize_nested_equality_delete_columns(Block* block) {
1140
32
    DORIS_CHECK(block != nullptr);
1141
    // A carrier may be the source of other keys under the same physical root, so extract every
1142
    // leaf before replacing any carrier column with its own leaf.
1143
32
    std::vector<ColumnPtr> leaves;
1144
32
    leaves.reserve(_nested_equality_delete_columns.size());
1145
32
    for (const auto& nested_field : _nested_equality_delete_columns) {
1146
23
        const auto& source_name = nested_field.source_block_name.empty()
1147
23
                                          ? nested_field.block_name
1148
23
                                          : nested_field.source_block_name;
1149
23
        const auto source = this->col_name_to_block_idx_ref()->find(source_name);
1150
23
        DORIS_CHECK(source != this->col_name_to_block_idx_ref()->end());
1151
23
        DORIS_CHECK(source->second < block->columns());
1152
23
        ColumnPtr leaf;
1153
23
        RETURN_IF_ERROR(_extract_nested_equality_delete_column(
1154
23
                block->get_by_position(source->second).column, nested_field, &leaf));
1155
23
        leaves.push_back(std::move(leaf));
1156
23
    }
1157
55
    for (size_t index = 0; index < leaves.size(); ++index) {
1158
23
        const auto& nested_field = _nested_equality_delete_columns[index];
1159
23
        const auto type = make_nullable(nested_field.leaf_type);
1160
23
        auto& positions = *this->col_name_to_block_idx_ref();
1161
23
        if (!nested_field.source_block_name.empty()) {
1162
            // A key extracted from a projected root or another key's carrier is not read, so the
1163
            // block gets its column only now.
1164
11
            DORIS_CHECK(!positions.contains(nested_field.block_name));
1165
11
            positions[nested_field.block_name] = block->columns();
1166
11
            block->insert({std::move(leaves[index]), type, nested_field.block_name});
1167
11
            continue;
1168
11
        }
1169
12
        const auto target = positions.find(nested_field.block_name);
1170
12
        DORIS_CHECK(target != positions.end());
1171
12
        DORIS_CHECK(target->second < block->columns());
1172
12
        auto& column = block->get_by_position(target->second);
1173
12
        column.column = std::move(leaves[index]);
1174
12
        column.type = type;
1175
12
    }
1176
32
    return Status::OK();
1177
32
}
_ZN5doris18IcebergReaderMixinINS_9OrcReaderEE43_materialize_nested_equality_delete_columnsEPNS_5BlockE
Line
Count
Source
1139
20
Status IcebergReaderMixin<BaseReader>::_materialize_nested_equality_delete_columns(Block* block) {
1140
20
    DORIS_CHECK(block != nullptr);
1141
    // A carrier may be the source of other keys under the same physical root, so extract every
1142
    // leaf before replacing any carrier column with its own leaf.
1143
20
    std::vector<ColumnPtr> leaves;
1144
20
    leaves.reserve(_nested_equality_delete_columns.size());
1145
20
    for (const auto& nested_field : _nested_equality_delete_columns) {
1146
9
        const auto& source_name = nested_field.source_block_name.empty()
1147
9
                                          ? nested_field.block_name
1148
9
                                          : nested_field.source_block_name;
1149
9
        const auto source = this->col_name_to_block_idx_ref()->find(source_name);
1150
9
        DORIS_CHECK(source != this->col_name_to_block_idx_ref()->end());
1151
9
        DORIS_CHECK(source->second < block->columns());
1152
9
        ColumnPtr leaf;
1153
9
        RETURN_IF_ERROR(_extract_nested_equality_delete_column(
1154
9
                block->get_by_position(source->second).column, nested_field, &leaf));
1155
9
        leaves.push_back(std::move(leaf));
1156
9
    }
1157
29
    for (size_t index = 0; index < leaves.size(); ++index) {
1158
9
        const auto& nested_field = _nested_equality_delete_columns[index];
1159
9
        const auto type = make_nullable(nested_field.leaf_type);
1160
9
        auto& positions = *this->col_name_to_block_idx_ref();
1161
9
        if (!nested_field.source_block_name.empty()) {
1162
            // A key extracted from a projected root or another key's carrier is not read, so the
1163
            // block gets its column only now.
1164
0
            DORIS_CHECK(!positions.contains(nested_field.block_name));
1165
0
            positions[nested_field.block_name] = block->columns();
1166
0
            block->insert({std::move(leaves[index]), type, nested_field.block_name});
1167
0
            continue;
1168
0
        }
1169
9
        const auto target = positions.find(nested_field.block_name);
1170
9
        DORIS_CHECK(target != positions.end());
1171
9
        DORIS_CHECK(target->second < block->columns());
1172
9
        auto& column = block->get_by_position(target->second);
1173
9
        column.column = std::move(leaves[index]);
1174
9
        column.type = type;
1175
9
    }
1176
20
    return Status::OK();
1177
20
}
1178
1179
template <typename BaseReader>
1180
Status IcebergReaderMixin<BaseReader>::_create_missing_equality_delete_value(
1181
        int32_t field_id, const DataTypePtr& delete_key_type, size_t physical_path_size,
1182
21
        ColumnPtr* const value) const {
1183
21
    DORIS_CHECK(delete_key_type != nullptr);
1184
21
    DORIS_CHECK(value != nullptr);
1185
21
    const auto table_path = _find_schema_field_path(field_id);
1186
21
    if (table_path.empty()) {
1187
        // Without field-id-bound current or historical metadata BE cannot distinguish a true NULL
1188
        // initial default from a non-NULL default, so continuing would risk silently keeping or
1189
        // deleting wrong rows.
1190
1
        return Status::InternalError(
1191
1
                "Missing Iceberg schema metadata for equality-delete field id {}", field_id);
1192
1
    }
1193
20
    const size_t missing_index =
1194
20
            physical_path_size < table_path.size() ? physical_path_size : table_path.size() - 1;
1195
20
    const auto* missing_field = table_path[missing_index];
1196
20
    DORIS_CHECK(missing_field != nullptr);
1197
1198
20
    if (!supports_iceberg_scan_semantics_v2(&this->get_scan_params()) &&
1199
20
        !missing_field->__isset.initial_default_value) {
1200
0
        *value = delete_key_type->create_column_const(1, Field());
1201
0
        return Status::OK();
1202
0
    }
1203
1204
20
    DataTypePtr missing_type = delete_key_type;
1205
20
    for (size_t index = table_path.size(); index > missing_index + 1; --index) {
1206
0
        const auto* parent = table_path[index - 2];
1207
0
        const auto* child = table_path[index - 1];
1208
0
        DORIS_CHECK(parent != nullptr);
1209
0
        DORIS_CHECK(child != nullptr);
1210
0
        DORIS_CHECK(child->__isset.name);
1211
0
        if (!parent->__isset.nestedField || !parent->nestedField.__isset.struct_field) {
1212
0
            return Status::NotSupported(
1213
0
                    "Iceberg equality delete field id {} has a non-struct missing ancestor",
1214
0
                    field_id);
1215
0
        }
1216
0
        missing_type = std::make_shared<DataTypeStruct>(DataTypes {std::move(missing_type)},
1217
0
                                                        Strings {child->name});
1218
0
        if (parent->__isset.is_optional && parent->is_optional) {
1219
0
            missing_type = make_nullable(missing_type);
1220
0
        }
1221
0
    }
1222
1223
20
    ColumnPtr missing_root_value;
1224
20
    RETURN_IF_ERROR(iceberg::create_initial_default_column(*missing_field, missing_type,
1225
20
                                                           &missing_root_value));
1226
20
    if (missing_index + 1 == table_path.size()) {
1227
20
        *value = std::move(missing_root_value);
1228
20
        return Status::OK();
1229
20
    }
1230
1231
0
    NestedEqualityDeleteColumn missing_path {
1232
0
            .field_id = field_id,
1233
0
            .block_name = "",
1234
0
            .leaf_type = delete_key_type,
1235
0
            .child_indexes = std::vector<size_t>(table_path.size() - missing_index - 1, 0),
1236
0
            .missing_value = nullptr,
1237
0
    };
1238
0
    return _extract_nested_equality_delete_column(missing_root_value, missing_path, value);
1239
20
}
_ZNK5doris18IcebergReaderMixinINS_13ParquetReaderEE37_create_missing_equality_delete_valueEiRKSt10shared_ptrIKNS_9IDataTypeEEmPNS_3COWINS_7IColumnEE13immutable_ptrISA_EE
Line
Count
Source
1182
13
        ColumnPtr* const value) const {
1183
13
    DORIS_CHECK(delete_key_type != nullptr);
1184
13
    DORIS_CHECK(value != nullptr);
1185
13
    const auto table_path = _find_schema_field_path(field_id);
1186
13
    if (table_path.empty()) {
1187
        // Without field-id-bound current or historical metadata BE cannot distinguish a true NULL
1188
        // initial default from a non-NULL default, so continuing would risk silently keeping or
1189
        // deleting wrong rows.
1190
1
        return Status::InternalError(
1191
1
                "Missing Iceberg schema metadata for equality-delete field id {}", field_id);
1192
1
    }
1193
12
    const size_t missing_index =
1194
12
            physical_path_size < table_path.size() ? physical_path_size : table_path.size() - 1;
1195
12
    const auto* missing_field = table_path[missing_index];
1196
12
    DORIS_CHECK(missing_field != nullptr);
1197
1198
12
    if (!supports_iceberg_scan_semantics_v2(&this->get_scan_params()) &&
1199
12
        !missing_field->__isset.initial_default_value) {
1200
0
        *value = delete_key_type->create_column_const(1, Field());
1201
0
        return Status::OK();
1202
0
    }
1203
1204
12
    DataTypePtr missing_type = delete_key_type;
1205
12
    for (size_t index = table_path.size(); index > missing_index + 1; --index) {
1206
0
        const auto* parent = table_path[index - 2];
1207
0
        const auto* child = table_path[index - 1];
1208
0
        DORIS_CHECK(parent != nullptr);
1209
0
        DORIS_CHECK(child != nullptr);
1210
0
        DORIS_CHECK(child->__isset.name);
1211
0
        if (!parent->__isset.nestedField || !parent->nestedField.__isset.struct_field) {
1212
0
            return Status::NotSupported(
1213
0
                    "Iceberg equality delete field id {} has a non-struct missing ancestor",
1214
0
                    field_id);
1215
0
        }
1216
0
        missing_type = std::make_shared<DataTypeStruct>(DataTypes {std::move(missing_type)},
1217
0
                                                        Strings {child->name});
1218
0
        if (parent->__isset.is_optional && parent->is_optional) {
1219
0
            missing_type = make_nullable(missing_type);
1220
0
        }
1221
0
    }
1222
1223
12
    ColumnPtr missing_root_value;
1224
12
    RETURN_IF_ERROR(iceberg::create_initial_default_column(*missing_field, missing_type,
1225
12
                                                           &missing_root_value));
1226
12
    if (missing_index + 1 == table_path.size()) {
1227
12
        *value = std::move(missing_root_value);
1228
12
        return Status::OK();
1229
12
    }
1230
1231
0
    NestedEqualityDeleteColumn missing_path {
1232
0
            .field_id = field_id,
1233
0
            .block_name = "",
1234
0
            .leaf_type = delete_key_type,
1235
0
            .child_indexes = std::vector<size_t>(table_path.size() - missing_index - 1, 0),
1236
0
            .missing_value = nullptr,
1237
0
    };
1238
0
    return _extract_nested_equality_delete_column(missing_root_value, missing_path, value);
1239
12
}
_ZNK5doris18IcebergReaderMixinINS_9OrcReaderEE37_create_missing_equality_delete_valueEiRKSt10shared_ptrIKNS_9IDataTypeEEmPNS_3COWINS_7IColumnEE13immutable_ptrISA_EE
Line
Count
Source
1182
8
        ColumnPtr* const value) const {
1183
8
    DORIS_CHECK(delete_key_type != nullptr);
1184
8
    DORIS_CHECK(value != nullptr);
1185
8
    const auto table_path = _find_schema_field_path(field_id);
1186
8
    if (table_path.empty()) {
1187
        // Without field-id-bound current or historical metadata BE cannot distinguish a true NULL
1188
        // initial default from a non-NULL default, so continuing would risk silently keeping or
1189
        // deleting wrong rows.
1190
0
        return Status::InternalError(
1191
0
                "Missing Iceberg schema metadata for equality-delete field id {}", field_id);
1192
0
    }
1193
8
    const size_t missing_index =
1194
8
            physical_path_size < table_path.size() ? physical_path_size : table_path.size() - 1;
1195
8
    const auto* missing_field = table_path[missing_index];
1196
8
    DORIS_CHECK(missing_field != nullptr);
1197
1198
8
    if (!supports_iceberg_scan_semantics_v2(&this->get_scan_params()) &&
1199
8
        !missing_field->__isset.initial_default_value) {
1200
0
        *value = delete_key_type->create_column_const(1, Field());
1201
0
        return Status::OK();
1202
0
    }
1203
1204
8
    DataTypePtr missing_type = delete_key_type;
1205
8
    for (size_t index = table_path.size(); index > missing_index + 1; --index) {
1206
0
        const auto* parent = table_path[index - 2];
1207
0
        const auto* child = table_path[index - 1];
1208
0
        DORIS_CHECK(parent != nullptr);
1209
0
        DORIS_CHECK(child != nullptr);
1210
0
        DORIS_CHECK(child->__isset.name);
1211
0
        if (!parent->__isset.nestedField || !parent->nestedField.__isset.struct_field) {
1212
0
            return Status::NotSupported(
1213
0
                    "Iceberg equality delete field id {} has a non-struct missing ancestor",
1214
0
                    field_id);
1215
0
        }
1216
0
        missing_type = std::make_shared<DataTypeStruct>(DataTypes {std::move(missing_type)},
1217
0
                                                        Strings {child->name});
1218
0
        if (parent->__isset.is_optional && parent->is_optional) {
1219
0
            missing_type = make_nullable(missing_type);
1220
0
        }
1221
0
    }
1222
1223
8
    ColumnPtr missing_root_value;
1224
8
    RETURN_IF_ERROR(iceberg::create_initial_default_column(*missing_field, missing_type,
1225
8
                                                           &missing_root_value));
1226
8
    if (missing_index + 1 == table_path.size()) {
1227
8
        *value = std::move(missing_root_value);
1228
8
        return Status::OK();
1229
8
    }
1230
1231
0
    NestedEqualityDeleteColumn missing_path {
1232
0
            .field_id = field_id,
1233
0
            .block_name = "",
1234
0
            .leaf_type = delete_key_type,
1235
0
            .child_indexes = std::vector<size_t>(table_path.size() - missing_index - 1, 0),
1236
0
            .missing_value = nullptr,
1237
0
    };
1238
0
    return _extract_nested_equality_delete_column(missing_root_value, missing_path, value);
1239
8
}
1240
1241
template <typename BaseReader>
1242
Status IcebergReaderMixin<BaseReader>::_register_missing_equality_delete_column(
1243
19
        int32_t field_id, const std::string& name, const DataTypePtr& delete_key_type) {
1244
19
    DORIS_CHECK(delete_key_type != nullptr);
1245
19
    ColumnPtr default_column;
1246
19
    RETURN_IF_ERROR(
1247
19
            _create_missing_equality_delete_value(field_id, delete_key_type, 0, &default_column));
1248
    // The key is appended after the read (on_after_read_block), not by a synthesized-column
1249
    // handler: the reader filters only the columns its block had before the read, and Parquet's
1250
    // lazy read also looks up a tuple slot for every synthesized column, which this hidden key
1251
    // does not have.
1252
18
    const bool inserted =
1253
18
            _missing_equality_delete_values.emplace(name, std::move(default_column)).second;
1254
18
    DORIS_CHECK(inserted);
1255
18
    return Status::OK();
1256
19
}
_ZN5doris18IcebergReaderMixinINS_13ParquetReaderEE40_register_missing_equality_delete_columnEiRKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEERKSt10shared_ptrIKNS_9IDataTypeEE
Line
Count
Source
1243
12
        int32_t field_id, const std::string& name, const DataTypePtr& delete_key_type) {
1244
12
    DORIS_CHECK(delete_key_type != nullptr);
1245
12
    ColumnPtr default_column;
1246
12
    RETURN_IF_ERROR(
1247
12
            _create_missing_equality_delete_value(field_id, delete_key_type, 0, &default_column));
1248
    // The key is appended after the read (on_after_read_block), not by a synthesized-column
1249
    // handler: the reader filters only the columns its block had before the read, and Parquet's
1250
    // lazy read also looks up a tuple slot for every synthesized column, which this hidden key
1251
    // does not have.
1252
11
    const bool inserted =
1253
11
            _missing_equality_delete_values.emplace(name, std::move(default_column)).second;
1254
11
    DORIS_CHECK(inserted);
1255
11
    return Status::OK();
1256
12
}
_ZN5doris18IcebergReaderMixinINS_9OrcReaderEE40_register_missing_equality_delete_columnEiRKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEERKSt10shared_ptrIKNS_9IDataTypeEE
Line
Count
Source
1243
7
        int32_t field_id, const std::string& name, const DataTypePtr& delete_key_type) {
1244
7
    DORIS_CHECK(delete_key_type != nullptr);
1245
7
    ColumnPtr default_column;
1246
7
    RETURN_IF_ERROR(
1247
7
            _create_missing_equality_delete_value(field_id, delete_key_type, 0, &default_column));
1248
    // The key is appended after the read (on_after_read_block), not by a synthesized-column
1249
    // handler: the reader filters only the columns its block had before the read, and Parquet's
1250
    // lazy read also looks up a tuple slot for every synthesized column, which this hidden key
1251
    // does not have.
1252
7
    const bool inserted =
1253
7
            _missing_equality_delete_values.emplace(name, std::move(default_column)).second;
1254
7
    DORIS_CHECK(inserted);
1255
7
    return Status::OK();
1256
7
}
1257
1258
template <typename BaseReader>
1259
bool IcebergReaderMixin<BaseReader>::_is_derived_equality_delete_column(
1260
37
        const std::string& name) const {
1261
38
    return std::ranges::any_of(_nested_equality_delete_columns, [&](const auto& nested_field) {
1262
38
        return nested_field.block_name == name && !nested_field.source_block_name.empty();
1263
38
    });
_ZZNK5doris18IcebergReaderMixinINS_13ParquetReaderEE34_is_derived_equality_delete_columnERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEENKUlRKT_E_clINS2_26NestedEqualityDeleteColumnEEEDaSD_
Line
Count
Source
1261
29
    return std::ranges::any_of(_nested_equality_delete_columns, [&](const auto& nested_field) {
1262
29
        return nested_field.block_name == name && !nested_field.source_block_name.empty();
1263
29
    });
_ZZNK5doris18IcebergReaderMixinINS_9OrcReaderEE34_is_derived_equality_delete_columnERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEENKUlRKT_E_clINS2_26NestedEqualityDeleteColumnEEEDaSD_
Line
Count
Source
1261
9
    return std::ranges::any_of(_nested_equality_delete_columns, [&](const auto& nested_field) {
1262
9
        return nested_field.block_name == name && !nested_field.source_block_name.empty();
1263
9
    });
1264
37
}
_ZNK5doris18IcebergReaderMixinINS_13ParquetReaderEE34_is_derived_equality_delete_columnERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE
Line
Count
Source
1260
26
        const std::string& name) const {
1261
26
    return std::ranges::any_of(_nested_equality_delete_columns, [&](const auto& nested_field) {
1262
26
        return nested_field.block_name == name && !nested_field.source_block_name.empty();
1263
26
    });
1264
26
}
_ZNK5doris18IcebergReaderMixinINS_9OrcReaderEE34_is_derived_equality_delete_columnERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE
Line
Count
Source
1260
11
        const std::string& name) const {
1261
11
    return std::ranges::any_of(_nested_equality_delete_columns, [&](const auto& nested_field) {
1262
11
        return nested_field.block_name == name && !nested_field.source_block_name.empty();
1263
11
    });
1264
11
}
1265
1266
template <typename BaseReader>
1267
Status IcebergReaderMixin<BaseReader>::_materialize_missing_equality_delete_column(
1268
18
        Block* block, const std::string& name, const ColumnPtr& value, size_t rows) {
1269
18
    if (!this->col_name_to_block_idx_ref()->contains(name)) {
1270
        // A key that is absent from the file is not a physical child of the reader, so the block
1271
        // has no column for it: append one before equality-delete filtering. MultiEqualityDelete
1272
        // requires a full, batch-sized column.
1273
13
        const auto expand_col = std::ranges::find_if(
1274
13
                _expand_columns,
1275
15
                [&](const ColumnWithTypeAndName& col) { return col.name == name; });
_ZZN5doris18IcebergReaderMixinINS_13ParquetReaderEE43_materialize_missing_equality_delete_columnEPNS_5BlockERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEERKNS_3COWINS_7IColumnEE13immutable_ptrISE_EEmENKUlRKNS_21ColumnWithTypeAndNameEE_clESM_
Line
Count
Source
1275
7
                [&](const ColumnWithTypeAndName& col) { return col.name == name; });
_ZZN5doris18IcebergReaderMixinINS_9OrcReaderEE43_materialize_missing_equality_delete_columnEPNS_5BlockERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEERKNS_3COWINS_7IColumnEE13immutable_ptrISE_EEmENKUlRKNS_21ColumnWithTypeAndNameEE_clESM_
Line
Count
Source
1275
8
                [&](const ColumnWithTypeAndName& col) { return col.name == name; });
1276
13
        DORIS_CHECK(expand_col != _expand_columns.end());
1277
13
        (*this->col_name_to_block_idx_ref())[name] = block->columns();
1278
13
        block->insert(
1279
13
                {iceberg::repeat_initial_default_column(value, rows), expand_col->type, name});
1280
13
        return Status::OK();
1281
13
    }
1282
5
    const auto position = this->col_name_to_block_idx_ref()->at(name);
1283
5
    DORIS_CHECK(position < block->columns());
1284
5
    DORIS_CHECK(block->get_by_position(position).column->empty());
1285
    // MultiEqualityDelete hashes each key column directly. Materialize the repeated default so
1286
    // every key has the batch row count; a ColumnConst keeps only one nested value and therefore
1287
    // cannot participate in the row-wise multi-column hash contract.
1288
5
    block->get_by_position(position).column = iceberg::repeat_initial_default_column(value, rows);
1289
5
    return Status::OK();
1290
18
}
_ZN5doris18IcebergReaderMixinINS_13ParquetReaderEE43_materialize_missing_equality_delete_columnEPNS_5BlockERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEERKNS_3COWINS_7IColumnEE13immutable_ptrISE_EEm
Line
Count
Source
1268
11
        Block* block, const std::string& name, const ColumnPtr& value, size_t rows) {
1269
11
    if (!this->col_name_to_block_idx_ref()->contains(name)) {
1270
        // A key that is absent from the file is not a physical child of the reader, so the block
1271
        // has no column for it: append one before equality-delete filtering. MultiEqualityDelete
1272
        // requires a full, batch-sized column.
1273
6
        const auto expand_col = std::ranges::find_if(
1274
6
                _expand_columns,
1275
6
                [&](const ColumnWithTypeAndName& col) { return col.name == name; });
1276
6
        DORIS_CHECK(expand_col != _expand_columns.end());
1277
6
        (*this->col_name_to_block_idx_ref())[name] = block->columns();
1278
6
        block->insert(
1279
6
                {iceberg::repeat_initial_default_column(value, rows), expand_col->type, name});
1280
6
        return Status::OK();
1281
6
    }
1282
5
    const auto position = this->col_name_to_block_idx_ref()->at(name);
1283
5
    DORIS_CHECK(position < block->columns());
1284
5
    DORIS_CHECK(block->get_by_position(position).column->empty());
1285
    // MultiEqualityDelete hashes each key column directly. Materialize the repeated default so
1286
    // every key has the batch row count; a ColumnConst keeps only one nested value and therefore
1287
    // cannot participate in the row-wise multi-column hash contract.
1288
5
    block->get_by_position(position).column = iceberg::repeat_initial_default_column(value, rows);
1289
5
    return Status::OK();
1290
11
}
_ZN5doris18IcebergReaderMixinINS_9OrcReaderEE43_materialize_missing_equality_delete_columnEPNS_5BlockERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEERKNS_3COWINS_7IColumnEE13immutable_ptrISE_EEm
Line
Count
Source
1268
7
        Block* block, const std::string& name, const ColumnPtr& value, size_t rows) {
1269
7
    if (!this->col_name_to_block_idx_ref()->contains(name)) {
1270
        // A key that is absent from the file is not a physical child of the reader, so the block
1271
        // has no column for it: append one before equality-delete filtering. MultiEqualityDelete
1272
        // requires a full, batch-sized column.
1273
7
        const auto expand_col = std::ranges::find_if(
1274
7
                _expand_columns,
1275
7
                [&](const ColumnWithTypeAndName& col) { return col.name == name; });
1276
7
        DORIS_CHECK(expand_col != _expand_columns.end());
1277
7
        (*this->col_name_to_block_idx_ref())[name] = block->columns();
1278
7
        block->insert(
1279
7
                {iceberg::repeat_initial_default_column(value, rows), expand_col->type, name});
1280
7
        return Status::OK();
1281
7
    }
1282
0
    const auto position = this->col_name_to_block_idx_ref()->at(name);
1283
0
    DORIS_CHECK(position < block->columns());
1284
0
    DORIS_CHECK(block->get_by_position(position).column->empty());
1285
    // MultiEqualityDelete hashes each key column directly. Materialize the repeated default so
1286
    // every key has the batch row count; a ColumnConst keeps only one nested value and therefore
1287
    // cannot participate in the row-wise multi-column hash contract.
1288
0
    block->get_by_position(position).column = iceberg::repeat_initial_default_column(value, rows);
1289
0
    return Status::OK();
1290
7
}
1291
1292
template <typename BaseReader>
1293
Status IcebergReaderMixin<BaseReader>::_materialize_missing_equality_delete_columns(Block* block,
1294
55
                                                                                    size_t rows) {
1295
55
    for (const auto& [name, value] : _missing_equality_delete_values) {
1296
18
        RETURN_IF_ERROR(_materialize_missing_equality_delete_column(block, name, value, rows));
1297
18
    }
1298
55
    return Status::OK();
1299
55
}
_ZN5doris18IcebergReaderMixinINS_13ParquetReaderEE44_materialize_missing_equality_delete_columnsEPNS_5BlockEm
Line
Count
Source
1294
35
                                                                                    size_t rows) {
1295
35
    for (const auto& [name, value] : _missing_equality_delete_values) {
1296
11
        RETURN_IF_ERROR(_materialize_missing_equality_delete_column(block, name, value, rows));
1297
11
    }
1298
35
    return Status::OK();
1299
35
}
_ZN5doris18IcebergReaderMixinINS_9OrcReaderEE44_materialize_missing_equality_delete_columnsEPNS_5BlockEm
Line
Count
Source
1294
20
                                                                                    size_t rows) {
1295
20
    for (const auto& [name, value] : _missing_equality_delete_values) {
1296
7
        RETURN_IF_ERROR(_materialize_missing_equality_delete_column(block, name, value, rows));
1297
7
    }
1298
20
    return Status::OK();
1299
20
}
1300
1301
template <typename BaseReader>
1302
52
Status IcebergReaderMixin<BaseReader>::_shrink_block_if_need(Block* block) {
1303
52
    std::set<size_t> positions_to_erase;
1304
52
    for (const std::string& expand_col : _expand_col_names) {
1305
50
        if (!this->col_name_to_block_idx_ref()->contains(expand_col)) {
1306
0
            return Status::InternalError("Wrong erase column '{}', block: {}", expand_col,
1307
0
                                         block->dump_names());
1308
0
        }
1309
50
        positions_to_erase.emplace((*this->col_name_to_block_idx_ref())[expand_col]);
1310
50
    }
1311
52
    block->erase(positions_to_erase);
1312
52
    for (const std::string& expand_col : _expand_col_names) {
1313
50
        this->col_name_to_block_idx_ref()->erase(expand_col);
1314
50
    }
1315
52
    return Status::OK();
1316
52
}
_ZN5doris18IcebergReaderMixinINS_13ParquetReaderEE21_shrink_block_if_needEPNS_5BlockE
Line
Count
Source
1302
32
Status IcebergReaderMixin<BaseReader>::_shrink_block_if_need(Block* block) {
1303
32
    std::set<size_t> positions_to_erase;
1304
32
    for (const std::string& expand_col : _expand_col_names) {
1305
32
        if (!this->col_name_to_block_idx_ref()->contains(expand_col)) {
1306
0
            return Status::InternalError("Wrong erase column '{}', block: {}", expand_col,
1307
0
                                         block->dump_names());
1308
0
        }
1309
32
        positions_to_erase.emplace((*this->col_name_to_block_idx_ref())[expand_col]);
1310
32
    }
1311
32
    block->erase(positions_to_erase);
1312
32
    for (const std::string& expand_col : _expand_col_names) {
1313
32
        this->col_name_to_block_idx_ref()->erase(expand_col);
1314
32
    }
1315
32
    return Status::OK();
1316
32
}
_ZN5doris18IcebergReaderMixinINS_9OrcReaderEE21_shrink_block_if_needEPNS_5BlockE
Line
Count
Source
1302
20
Status IcebergReaderMixin<BaseReader>::_shrink_block_if_need(Block* block) {
1303
20
    std::set<size_t> positions_to_erase;
1304
20
    for (const std::string& expand_col : _expand_col_names) {
1305
18
        if (!this->col_name_to_block_idx_ref()->contains(expand_col)) {
1306
0
            return Status::InternalError("Wrong erase column '{}', block: {}", expand_col,
1307
0
                                         block->dump_names());
1308
0
        }
1309
18
        positions_to_erase.emplace((*this->col_name_to_block_idx_ref())[expand_col]);
1310
18
    }
1311
20
    block->erase(positions_to_erase);
1312
20
    for (const std::string& expand_col : _expand_col_names) {
1313
18
        this->col_name_to_block_idx_ref()->erase(expand_col);
1314
18
    }
1315
20
    return Status::OK();
1316
20
}
1317
1318
template <typename BaseReader>
1319
Status IcebergReaderMixin<BaseReader>::_position_delete_base(
1320
2
        const std::string data_file_path, const std::vector<TIcebergDeleteFileDesc>& delete_files) {
1321
2
    std::vector<DeleteRows*> delete_rows_array;
1322
2
    int64_t num_delete_rows = 0;
1323
2
    for (const auto& delete_file : delete_files) {
1324
2
        SCOPED_TIMER(_iceberg_profile.delete_files_read_time);
1325
2
        Status create_status = Status::OK();
1326
2
        auto* delete_file_cache = _kv_cache->template get<DeleteFile>(
1327
2
                _delet_file_cache_key(delete_file.path), [&]() -> DeleteFile* {
1328
2
                    auto position_delete = std::make_unique<DeleteFile>();
1329
2
                    TFileRangeDesc delete_file_range;
1330
2
                    delete_file_range.__set_fs_name(this->get_scan_range().fs_name);
1331
2
                    delete_file_range.path = delete_file.path;
1332
2
                    delete_file_range.start_offset = 0;
1333
2
                    delete_file_range.size = -1;
1334
2
                    delete_file_range.file_size =
1335
2
                            delete_file.__isset.file_size ? delete_file.file_size : -1;
1336
2
                    create_status =
1337
2
                            _read_position_delete_file(&delete_file_range, position_delete.get());
1338
2
                    if (!create_status) {
1339
2
                        return nullptr;
1340
2
                    }
1341
0
                    return position_delete.release();
1342
2
                });
_ZZN5doris18IcebergReaderMixinINS_13ParquetReaderEE21_position_delete_baseENSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEERKSt6vectorINS_22TIcebergDeleteFileDescESaISA_EEENKUlvE_clB5cxx11Ev
Line
Count
Source
1327
2
                _delet_file_cache_key(delete_file.path), [&]() -> DeleteFile* {
1328
2
                    auto position_delete = std::make_unique<DeleteFile>();
1329
2
                    TFileRangeDesc delete_file_range;
1330
2
                    delete_file_range.__set_fs_name(this->get_scan_range().fs_name);
1331
2
                    delete_file_range.path = delete_file.path;
1332
2
                    delete_file_range.start_offset = 0;
1333
2
                    delete_file_range.size = -1;
1334
2
                    delete_file_range.file_size =
1335
2
                            delete_file.__isset.file_size ? delete_file.file_size : -1;
1336
2
                    create_status =
1337
2
                            _read_position_delete_file(&delete_file_range, position_delete.get());
1338
2
                    if (!create_status) {
1339
2
                        return nullptr;
1340
2
                    }
1341
0
                    return position_delete.release();
1342
2
                });
Unexecuted instantiation: _ZZN5doris18IcebergReaderMixinINS_9OrcReaderEE21_position_delete_baseENSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEERKSt6vectorINS_22TIcebergDeleteFileDescESaISA_EEENKUlvE_clB5cxx11Ev
1343
2
        if (create_status.is<ErrorCode::END_OF_FILE>()) {
1344
0
            continue;
1345
2
        } else if (!create_status.ok()) {
1346
2
            return create_status;
1347
2
        }
1348
1349
0
        DeleteFile& delete_file_map = *((DeleteFile*)delete_file_cache);
1350
0
        auto get_value = [&](const auto& v) {
1351
0
            DeleteRows* row_ids = v.second.get();
1352
0
            if (!row_ids->empty()) {
1353
0
                delete_rows_array.emplace_back(row_ids);
1354
0
                num_delete_rows += row_ids->size();
1355
0
            }
1356
0
        };
Unexecuted instantiation: _ZZN5doris18IcebergReaderMixinINS_13ParquetReaderEE21_position_delete_baseENSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEERKSt6vectorINS_22TIcebergDeleteFileDescESaISA_EEENKUlRKT_E_clISt4pairIKS8_St10unique_ptrIS9_IlSaIlEESt14default_deleteISO_EEEEEDaSH_
Unexecuted instantiation: _ZZN5doris18IcebergReaderMixinINS_9OrcReaderEE21_position_delete_baseENSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEERKSt6vectorINS_22TIcebergDeleteFileDescESaISA_EEENKUlRKT_E_clISt4pairIKS8_St10unique_ptrIS9_IlSaIlEESt14default_deleteISO_EEEEEDaSH_
1357
0
        delete_file_map.if_contains(data_file_path, get_value);
1358
0
    }
1359
0
    if (num_delete_rows > 0) {
1360
0
        SCOPED_TIMER(_iceberg_profile.delete_rows_sort_time);
1361
0
        _iceberg_delete_rows =
1362
0
                _kv_cache->template get<DeleteRows>(data_file_path, [&]() -> DeleteRows* {
1363
0
                    auto data_file_position_delete = std::make_unique<DeleteRows>();
1364
0
                    _sort_delete_rows(delete_rows_array, num_delete_rows,
1365
0
                                      *data_file_position_delete);
1366
0
                    return data_file_position_delete.release();
1367
0
                });
Unexecuted instantiation: _ZZN5doris18IcebergReaderMixinINS_13ParquetReaderEE21_position_delete_baseENSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEERKSt6vectorINS_22TIcebergDeleteFileDescESaISA_EEENKUlvE0_clEv
Unexecuted instantiation: _ZZN5doris18IcebergReaderMixinINS_9OrcReaderEE21_position_delete_baseENSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEERKSt6vectorINS_22TIcebergDeleteFileDescESaISA_EEENKUlvE0_clEv
1368
0
        set_delete_rows();
1369
0
        COUNTER_UPDATE(_iceberg_profile.num_delete_rows, num_delete_rows);
1370
0
    }
1371
0
    return Status::OK();
1372
2
}
_ZN5doris18IcebergReaderMixinINS_13ParquetReaderEE21_position_delete_baseENSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEERKSt6vectorINS_22TIcebergDeleteFileDescESaISA_EE
Line
Count
Source
1320
2
        const std::string data_file_path, const std::vector<TIcebergDeleteFileDesc>& delete_files) {
1321
2
    std::vector<DeleteRows*> delete_rows_array;
1322
2
    int64_t num_delete_rows = 0;
1323
2
    for (const auto& delete_file : delete_files) {
1324
2
        SCOPED_TIMER(_iceberg_profile.delete_files_read_time);
1325
2
        Status create_status = Status::OK();
1326
2
        auto* delete_file_cache = _kv_cache->template get<DeleteFile>(
1327
2
                _delet_file_cache_key(delete_file.path), [&]() -> DeleteFile* {
1328
2
                    auto position_delete = std::make_unique<DeleteFile>();
1329
2
                    TFileRangeDesc delete_file_range;
1330
2
                    delete_file_range.__set_fs_name(this->get_scan_range().fs_name);
1331
2
                    delete_file_range.path = delete_file.path;
1332
2
                    delete_file_range.start_offset = 0;
1333
2
                    delete_file_range.size = -1;
1334
2
                    delete_file_range.file_size =
1335
2
                            delete_file.__isset.file_size ? delete_file.file_size : -1;
1336
2
                    create_status =
1337
2
                            _read_position_delete_file(&delete_file_range, position_delete.get());
1338
2
                    if (!create_status) {
1339
2
                        return nullptr;
1340
2
                    }
1341
2
                    return position_delete.release();
1342
2
                });
1343
2
        if (create_status.is<ErrorCode::END_OF_FILE>()) {
1344
0
            continue;
1345
2
        } else if (!create_status.ok()) {
1346
2
            return create_status;
1347
2
        }
1348
1349
0
        DeleteFile& delete_file_map = *((DeleteFile*)delete_file_cache);
1350
0
        auto get_value = [&](const auto& v) {
1351
0
            DeleteRows* row_ids = v.second.get();
1352
0
            if (!row_ids->empty()) {
1353
0
                delete_rows_array.emplace_back(row_ids);
1354
0
                num_delete_rows += row_ids->size();
1355
0
            }
1356
0
        };
1357
0
        delete_file_map.if_contains(data_file_path, get_value);
1358
0
    }
1359
0
    if (num_delete_rows > 0) {
1360
0
        SCOPED_TIMER(_iceberg_profile.delete_rows_sort_time);
1361
0
        _iceberg_delete_rows =
1362
0
                _kv_cache->template get<DeleteRows>(data_file_path, [&]() -> DeleteRows* {
1363
0
                    auto data_file_position_delete = std::make_unique<DeleteRows>();
1364
0
                    _sort_delete_rows(delete_rows_array, num_delete_rows,
1365
0
                                      *data_file_position_delete);
1366
0
                    return data_file_position_delete.release();
1367
0
                });
1368
0
        set_delete_rows();
1369
0
        COUNTER_UPDATE(_iceberg_profile.num_delete_rows, num_delete_rows);
1370
0
    }
1371
0
    return Status::OK();
1372
2
}
Unexecuted instantiation: _ZN5doris18IcebergReaderMixinINS_9OrcReaderEE21_position_delete_baseENSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEERKSt6vectorINS_22TIcebergDeleteFileDescESaISA_EE
1373
1374
template <typename BaseReader>
1375
typename IcebergReaderMixin<BaseReader>::PositionDeleteRange
1376
0
IcebergReaderMixin<BaseReader>::_get_range(const ColumnDictI32& file_path_column) {
1377
0
    PositionDeleteRange range;
1378
0
    size_t read_rows = file_path_column.get_data().size();
1379
0
    const int* code_path = file_path_column.get_data().data();
1380
0
    const int* code_path_start = code_path;
1381
0
    const int* code_path_end = code_path + read_rows;
1382
0
    while (code_path < code_path_end) {
1383
0
        int code = code_path[0];
1384
0
        const int* code_end = std::upper_bound(code_path, code_path_end, code);
1385
0
        range.data_file_path.emplace_back(file_path_column.get_value(code).to_string());
1386
0
        range.range.emplace_back(code_path - code_path_start, code_end - code_path_start);
1387
0
        code_path = code_end;
1388
0
    }
1389
0
    return range;
1390
0
}
Unexecuted instantiation: _ZN5doris18IcebergReaderMixinINS_13ParquetReaderEE10_get_rangeERKNS_13ColumnDictI32E
Unexecuted instantiation: _ZN5doris18IcebergReaderMixinINS_9OrcReaderEE10_get_rangeERKNS_13ColumnDictI32E
1391
1392
template <typename BaseReader>
1393
typename IcebergReaderMixin<BaseReader>::PositionDeleteRange
1394
0
IcebergReaderMixin<BaseReader>::_get_range(const ColumnString& file_path_column) {
1395
0
    PositionDeleteRange range;
1396
0
    size_t read_rows = file_path_column.size();
1397
0
    size_t index = 0;
1398
0
    while (index < read_rows) {
1399
0
        StringRef data_path = file_path_column.get_data_at(index);
1400
0
        size_t left = index - 1;
1401
0
        size_t right = read_rows;
1402
0
        while (left + 1 != right) {
1403
0
            size_t mid = left + (right - left) / 2;
1404
0
            if (file_path_column.get_data_at(mid) > data_path) {
1405
0
                right = mid;
1406
0
            } else {
1407
0
                left = mid;
1408
0
            }
1409
0
        }
1410
0
        range.data_file_path.emplace_back(data_path.to_string());
1411
0
        range.range.emplace_back(index, left + 1);
1412
0
        index = left + 1;
1413
0
    }
1414
0
    return range;
1415
0
}
Unexecuted instantiation: _ZN5doris18IcebergReaderMixinINS_13ParquetReaderEE10_get_rangeERKNS_9ColumnStrIjEE
Unexecuted instantiation: _ZN5doris18IcebergReaderMixinINS_9OrcReaderEE10_get_rangeERKNS_9ColumnStrIjEE
1416
1417
template <typename BaseReader>
1418
void IcebergReaderMixin<BaseReader>::_sort_delete_rows(
1419
        const std::vector<std::vector<int64_t>*>& delete_rows_array, int64_t num_delete_rows,
1420
0
        std::vector<int64_t>& result) {
1421
0
    if (delete_rows_array.empty()) {
1422
0
        return;
1423
0
    }
1424
0
    if (delete_rows_array.size() == 1) {
1425
0
        result.resize(num_delete_rows);
1426
0
        memcpy(result.data(), delete_rows_array.front()->data(), sizeof(int64_t) * num_delete_rows);
1427
0
        return;
1428
0
    }
1429
0
    if (delete_rows_array.size() == 2) {
1430
0
        result.resize(num_delete_rows);
1431
0
        std::merge(delete_rows_array.front()->begin(), delete_rows_array.front()->end(),
1432
0
                   delete_rows_array.back()->begin(), delete_rows_array.back()->end(),
1433
0
                   result.begin());
1434
0
        return;
1435
0
    }
1436
1437
0
    using vec_pair = std::pair<std::vector<int64_t>::iterator, std::vector<int64_t>::iterator>;
1438
0
    result.resize(num_delete_rows);
1439
0
    auto row_id_iter = result.begin();
1440
0
    auto iter_end = result.end();
1441
0
    std::vector<vec_pair> rows_array;
1442
0
    for (auto* rows : delete_rows_array) {
1443
0
        if (!rows->empty()) {
1444
0
            rows_array.emplace_back(rows->begin(), rows->end());
1445
0
        }
1446
0
    }
1447
0
    size_t array_size = rows_array.size();
1448
0
    while (row_id_iter != iter_end) {
1449
0
        int64_t min_index = 0;
1450
0
        int64_t min = *rows_array[0].first;
1451
0
        for (size_t i = 0; i < array_size; ++i) {
1452
0
            if (*rows_array[i].first < min) {
1453
0
                min_index = i;
1454
0
                min = *rows_array[i].first;
1455
0
            }
1456
0
        }
1457
0
        *row_id_iter++ = min;
1458
0
        rows_array[min_index].first++;
1459
0
        if (UNLIKELY(rows_array[min_index].first == rows_array[min_index].second)) {
1460
0
            rows_array.erase(rows_array.begin() + min_index);
1461
0
            array_size--;
1462
0
        }
1463
0
    }
1464
0
}
Unexecuted instantiation: _ZN5doris18IcebergReaderMixinINS_13ParquetReaderEE17_sort_delete_rowsERKSt6vectorIPS3_IlSaIlEESaIS6_EElRS5_
Unexecuted instantiation: _ZN5doris18IcebergReaderMixinINS_9OrcReaderEE17_sort_delete_rowsERKSt6vectorIPS3_IlSaIlEESaIS6_EElRS5_
1465
1466
template <typename BaseReader>
1467
Status IcebergReaderMixin<BaseReader>::_gen_position_delete_file_range(
1468
        Block& block, DeleteFile* position_delete, size_t read_rows,
1469
0
        bool file_path_column_dictionary_coded) {
1470
0
    SCOPED_TIMER(_iceberg_profile.parse_delete_file_time);
1471
0
    auto name_to_pos_map = block.get_name_to_pos_map();
1472
0
    ColumnPtr path_column = block.get_by_position(name_to_pos_map[ICEBERG_FILE_PATH]).column;
1473
0
    DCHECK_EQ(path_column->size(), read_rows);
1474
0
    ColumnPtr pos_column = block.get_by_position(name_to_pos_map[ICEBERG_ROW_POS]).column;
1475
0
    if (const auto* nullable_col = check_and_get_column<ColumnNullable>(*path_column);
1476
0
        nullable_col != nullptr) {
1477
0
        if (nullable_col->has_null(0, read_rows)) {
1478
0
            return Status::Corruption(
1479
0
                    "Iceberg position delete column file_path contains null values");
1480
0
        }
1481
0
        path_column = remove_nullable(path_column);
1482
0
    }
1483
0
    if (const auto* nullable_col = check_and_get_column<ColumnNullable>(*pos_column);
1484
0
        nullable_col != nullptr) {
1485
0
        if (nullable_col->has_null(0, read_rows)) {
1486
0
            return Status::Corruption("Iceberg position delete column pos contains null values");
1487
0
        }
1488
0
        pos_column = remove_nullable(pos_column);
1489
0
    }
1490
0
    using ColumnType = typename PrimitiveTypeTraits<TYPE_BIGINT>::ColumnType;
1491
0
    const int64_t* src_data = assert_cast<const ColumnType&>(*pos_column).get_data().data();
1492
0
    PositionDeleteRange range;
1493
0
    if (file_path_column_dictionary_coded) {
1494
0
        range = _get_range(assert_cast<const ColumnDictI32&>(*path_column));
1495
0
    } else {
1496
0
        range = _get_range(assert_cast<const ColumnString&>(*path_column));
1497
0
    }
1498
0
    for (int i = 0; i < range.range.size(); ++i) {
1499
0
        std::string key = range.data_file_path[i];
1500
0
        auto iter = position_delete->find(key);
1501
0
        DeleteRows* delete_rows;
1502
0
        if (iter == position_delete->end()) {
1503
0
            delete_rows = new DeleteRows;
1504
0
            std::unique_ptr<DeleteRows> delete_rows_ptr(delete_rows);
1505
0
            (*position_delete)[key] = std::move(delete_rows_ptr);
1506
0
        } else {
1507
0
            delete_rows = iter->second.get();
1508
0
        }
1509
0
        const int64_t* cpy_start = src_data + range.range[i].first;
1510
0
        const int64_t cpy_count = range.range[i].second - range.range[i].first;
1511
0
        int64_t origin_size = delete_rows->size();
1512
0
        delete_rows->resize(origin_size + cpy_count);
1513
0
        int64_t* dest_position = &(*delete_rows)[origin_size];
1514
0
        memcpy(dest_position, cpy_start, cpy_count * sizeof(int64_t));
1515
0
    }
1516
0
    return Status::OK();
1517
0
}
Unexecuted instantiation: _ZN5doris18IcebergReaderMixinINS_13ParquetReaderEE31_gen_position_delete_file_rangeERNS_5BlockEPN5phmap22parallel_flat_hash_mapINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEESt10unique_ptrISt6vectorIlSaIlEESt14default_deleteISG_EESt4hashISC_ESt8equal_toIvESaISt4pairIKSC_SJ_EELm8ESt5mutexEEmb
Unexecuted instantiation: _ZN5doris18IcebergReaderMixinINS_9OrcReaderEE31_gen_position_delete_file_rangeERNS_5BlockEPN5phmap22parallel_flat_hash_mapINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEESt10unique_ptrISt6vectorIlSaIlEESt14default_deleteISG_EESt4hashISC_ESt8equal_toIvESaISt4pairIKSC_SJ_EELm8ESt5mutexEEmb
1518
1519
template <typename BaseReader>
1520
Status IcebergReaderMixin<BaseReader>::read_deletion_vector(
1521
1
        const std::string& data_file_path, const TIcebergDeleteFileDesc& delete_file_desc) {
1522
1
    size_t bytes_read = 0;
1523
1
    RETURN_IF_ERROR(validate_iceberg_deletion_vector_descriptor(delete_file_desc, bytes_read));
1524
1525
1
    Status create_status = Status::OK();
1526
1
    SCOPED_TIMER(_iceberg_profile.delete_files_read_time);
1527
1
    bool decoded_cache_hit = false;
1528
1
    _iceberg_deletion_vector = _kv_cache->template get<DeletionVector>(
1529
1
            build_iceberg_deletion_vector_cache_key(data_file_path, delete_file_desc),
1530
1
            [&]() -> DeletionVector* {
1531
1
                auto deletion_vector = std::make_unique<DeletionVector>();
1532
1533
1
                io::FileCacheStatistics file_cache_stats;
1534
1
                IcebergDeleteFileReaderOptions options;
1535
1
                options.state = this->get_state();
1536
1
                options.profile = this->get_profile();
1537
1
                options.scan_params = &this->get_scan_params();
1538
1
                options.io_ctx = this->get_io_ctx();
1539
1
                options.fs_name = &this->get_scan_range().fs_name;
1540
1
                options.deletion_vector_file_cache_stats = &file_cache_stats;
1541
1
                create_status = read_iceberg_deletion_vector(delete_file_desc, options,
1542
1
                                                             deletion_vector.get());
1543
1
                COUNTER_UPDATE(_iceberg_profile.file_cache_hit_count,
1544
1
                               file_cache_stats.num_local_io_total);
1545
1
                COUNTER_UPDATE(_iceberg_profile.file_cache_miss_count,
1546
1
                               file_cache_stats.num_remote_io_total);
1547
1
                COUNTER_UPDATE(_iceberg_profile.file_cache_peer_read_count,
1548
1
                               file_cache_stats.num_peer_io_total);
1549
1
                if (!create_status.ok()) [[unlikely]] {
1550
1
                    return nullptr;
1551
1
                }
1552
1553
0
                SCOPED_TIMER(_iceberg_profile.parse_delete_file_time);
1554
0
                COUNTER_UPDATE(_iceberg_profile.num_delete_rows, deletion_vector->cardinality());
1555
0
                return deletion_vector.release();
1556
1
            },
_ZZN5doris18IcebergReaderMixinINS_13ParquetReaderEE20read_deletion_vectorERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEERKNS_22TIcebergDeleteFileDescEENKUlvE_clEv
Line
Count
Source
1530
1
            [&]() -> DeletionVector* {
1531
1
                auto deletion_vector = std::make_unique<DeletionVector>();
1532
1533
1
                io::FileCacheStatistics file_cache_stats;
1534
1
                IcebergDeleteFileReaderOptions options;
1535
1
                options.state = this->get_state();
1536
1
                options.profile = this->get_profile();
1537
1
                options.scan_params = &this->get_scan_params();
1538
1
                options.io_ctx = this->get_io_ctx();
1539
1
                options.fs_name = &this->get_scan_range().fs_name;
1540
1
                options.deletion_vector_file_cache_stats = &file_cache_stats;
1541
1
                create_status = read_iceberg_deletion_vector(delete_file_desc, options,
1542
1
                                                             deletion_vector.get());
1543
1
                COUNTER_UPDATE(_iceberg_profile.file_cache_hit_count,
1544
1
                               file_cache_stats.num_local_io_total);
1545
1
                COUNTER_UPDATE(_iceberg_profile.file_cache_miss_count,
1546
1
                               file_cache_stats.num_remote_io_total);
1547
1
                COUNTER_UPDATE(_iceberg_profile.file_cache_peer_read_count,
1548
1
                               file_cache_stats.num_peer_io_total);
1549
1
                if (!create_status.ok()) [[unlikely]] {
1550
1
                    return nullptr;
1551
1
                }
1552
1553
0
                SCOPED_TIMER(_iceberg_profile.parse_delete_file_time);
1554
0
                COUNTER_UPDATE(_iceberg_profile.num_delete_rows, deletion_vector->cardinality());
1555
0
                return deletion_vector.release();
1556
1
            },
Unexecuted instantiation: _ZZN5doris18IcebergReaderMixinINS_9OrcReaderEE20read_deletion_vectorERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEERKNS_22TIcebergDeleteFileDescEENKUlvE_clEv
1557
1
            &decoded_cache_hit);
1558
1559
1
    RETURN_IF_ERROR(create_status);
1560
0
    COUNTER_UPDATE(decoded_cache_hit ? _iceberg_profile.decoded_cache_hit_count
1561
0
                                     : _iceberg_profile.decoded_cache_miss_count,
1562
0
                   1);
1563
0
    if (!_iceberg_deletion_vector->isEmpty()) [[likely]] {
1564
0
        set_deletion_vector();
1565
0
    }
1566
0
    return Status::OK();
1567
1
}
_ZN5doris18IcebergReaderMixinINS_13ParquetReaderEE20read_deletion_vectorERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEERKNS_22TIcebergDeleteFileDescE
Line
Count
Source
1521
1
        const std::string& data_file_path, const TIcebergDeleteFileDesc& delete_file_desc) {
1522
1
    size_t bytes_read = 0;
1523
1
    RETURN_IF_ERROR(validate_iceberg_deletion_vector_descriptor(delete_file_desc, bytes_read));
1524
1525
1
    Status create_status = Status::OK();
1526
1
    SCOPED_TIMER(_iceberg_profile.delete_files_read_time);
1527
1
    bool decoded_cache_hit = false;
1528
1
    _iceberg_deletion_vector = _kv_cache->template get<DeletionVector>(
1529
1
            build_iceberg_deletion_vector_cache_key(data_file_path, delete_file_desc),
1530
1
            [&]() -> DeletionVector* {
1531
1
                auto deletion_vector = std::make_unique<DeletionVector>();
1532
1533
1
                io::FileCacheStatistics file_cache_stats;
1534
1
                IcebergDeleteFileReaderOptions options;
1535
1
                options.state = this->get_state();
1536
1
                options.profile = this->get_profile();
1537
1
                options.scan_params = &this->get_scan_params();
1538
1
                options.io_ctx = this->get_io_ctx();
1539
1
                options.fs_name = &this->get_scan_range().fs_name;
1540
1
                options.deletion_vector_file_cache_stats = &file_cache_stats;
1541
1
                create_status = read_iceberg_deletion_vector(delete_file_desc, options,
1542
1
                                                             deletion_vector.get());
1543
1
                COUNTER_UPDATE(_iceberg_profile.file_cache_hit_count,
1544
1
                               file_cache_stats.num_local_io_total);
1545
1
                COUNTER_UPDATE(_iceberg_profile.file_cache_miss_count,
1546
1
                               file_cache_stats.num_remote_io_total);
1547
1
                COUNTER_UPDATE(_iceberg_profile.file_cache_peer_read_count,
1548
1
                               file_cache_stats.num_peer_io_total);
1549
1
                if (!create_status.ok()) [[unlikely]] {
1550
1
                    return nullptr;
1551
1
                }
1552
1553
1
                SCOPED_TIMER(_iceberg_profile.parse_delete_file_time);
1554
1
                COUNTER_UPDATE(_iceberg_profile.num_delete_rows, deletion_vector->cardinality());
1555
1
                return deletion_vector.release();
1556
1
            },
1557
1
            &decoded_cache_hit);
1558
1559
1
    RETURN_IF_ERROR(create_status);
1560
0
    COUNTER_UPDATE(decoded_cache_hit ? _iceberg_profile.decoded_cache_hit_count
1561
0
                                     : _iceberg_profile.decoded_cache_miss_count,
1562
0
                   1);
1563
0
    if (!_iceberg_deletion_vector->isEmpty()) [[likely]] {
1564
0
        set_deletion_vector();
1565
0
    }
1566
0
    return Status::OK();
1567
1
}
Unexecuted instantiation: _ZN5doris18IcebergReaderMixinINS_9OrcReaderEE20read_deletion_vectorERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEERKNS_22TIcebergDeleteFileDescE
1568
1569
} // namespace doris