Coverage Report

Created: 2026-08-18 17:57

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