Coverage Report

Created: 2026-04-09 21:24

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
be/src/format/table/iceberg_reader.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 <cstddef>
21
#include <cstdint>
22
#include <string>
23
#include <unordered_map>
24
#include <unordered_set>
25
#include <utility>
26
#include <vector>
27
28
#include "common/status.h"
29
#include "core/column/column_dictionary.h"
30
#include "core/data_type/define_primitive_type.h"
31
#include "core/data_type/primitive_type.h"
32
#include "core/types.h"
33
#include "format/orc/vorc_reader.h"
34
#include "format/parquet/vparquet_reader.h"
35
#include "format/table/iceberg_reader_mixin.h"
36
#include "storage/olap_common.h"
37
38
namespace tparquet {
39
class KeyValue;
40
class ColumnMetaData;
41
} // namespace tparquet
42
43
namespace doris {
44
#include "common/compile_check_begin.h"
45
class RowDescriptor;
46
class RuntimeState;
47
class SlotDescriptor;
48
class TFileRangeDesc;
49
class TFileScanRangeParams;
50
class TIcebergDeleteFileDesc;
51
class TupleDescriptor;
52
53
namespace io {
54
struct IOContext;
55
} // namespace io
56
template <typename T>
57
class ColumnStr;
58
using ColumnString = ColumnStr<UInt32>;
59
class Block;
60
class GenericReader;
61
class ShardedKVCache;
62
class VExprContext;
63
64
struct RowLineageColumns {
65
    int row_id_column_idx = -1;
66
    int last_updated_sequence_number_column_idx = -1;
67
    int64_t first_row_id = -1;
68
    int64_t last_updated_sequence_number = -1;
69
70
0
    bool need_row_ids() const { return row_id_column_idx >= 0; }
71
0
    bool has_last_updated_sequence_number_column() const {
72
0
        return last_updated_sequence_number_column_idx >= 0;
73
0
    }
74
};
75
76
struct IcebergTableReader {
77
    static constexpr const char* ROW_LINEAGE_ROW_ID = "_row_id";
78
    static constexpr const char* ROW_LINEAGE_LAST_UPDATED_SEQ_NUMBER =
79
            "_last_updated_sequence_number";
80
81
    static bool _is_fully_dictionary_encoded(const tparquet::ColumnMetaData& column_metadata);
82
};
83
84
// IcebergParquetReader: inherits ParquetReader via IcebergReaderMixin CRTP
85
class IcebergParquetReader final : public IcebergReaderMixin<ParquetReader> {
86
public:
87
    ENABLE_FACTORY_CREATOR(IcebergParquetReader);
88
89
    IcebergParquetReader(ShardedKVCache* kv_cache, RuntimeProfile* profile,
90
                         const TFileScanRangeParams& params, const TFileRangeDesc& range,
91
                         size_t batch_size, const cctz::time_zone* ctz, io::IOContext* io_ctx,
92
                         RuntimeState* state, FileMetaCache* meta_cache)
93
7
            : IcebergReaderMixin<ParquetReader>(kv_cache, profile, params, range, batch_size, ctz,
94
7
                                                io_ctx, state, meta_cache) {}
95
96
0
    void set_delete_rows() final {
97
0
        LOG(INFO) << "[PosDeleteDebug] IcebergParquetReader::set_delete_rows: _iceberg_delete_rows="
98
0
                  << (_iceberg_delete_rows
99
0
                              ? "set(" + std::to_string(_iceberg_delete_rows->size()) + ")"
100
0
                              : "null");
101
        // Call ParquetReader's set_delete_rows(const vector<int64_t>*)
102
0
        ParquetReader::set_delete_rows(_iceberg_delete_rows);
103
0
    }
104
105
protected:
106
    // Parquet-specific schema matching via on_before_init_reader hook
107
    Status on_before_init_reader(ReaderInitContext* ctx) override;
108
109
    std::unique_ptr<GenericReader> _create_equality_reader(
110
0
            const TFileRangeDesc& delete_desc) final {
111
0
        return ParquetReader::create_unique(this->get_profile(), this->get_scan_params(),
112
0
                                            delete_desc, READ_DELETE_FILE_BATCH_SIZE,
113
0
                                            &this->get_state()->timezone_obj(), this->get_io_ctx(),
114
0
                                            this->get_state(), this->_meta_cache);
115
0
    }
116
117
    static ColumnIdResult _create_column_ids(const FieldDescriptor* field_desc,
118
                                             const TupleDescriptor* tuple_descriptor);
119
120
private:
121
    Status _read_position_delete_file(const TFileRangeDesc* delete_range,
122
                                      DeleteFile* position_delete) final;
123
};
124
125
// IcebergOrcReader: inherits OrcReader via IcebergReaderMixin CRTP
126
class IcebergOrcReader final : public IcebergReaderMixin<OrcReader> {
127
public:
128
    ENABLE_FACTORY_CREATOR(IcebergOrcReader);
129
130
    IcebergOrcReader(ShardedKVCache* kv_cache, RuntimeProfile* profile, RuntimeState* state,
131
                     const TFileScanRangeParams& params, const TFileRangeDesc& range,
132
                     size_t batch_size, const std::string& ctz, io::IOContext* io_ctx,
133
                     FileMetaCache* meta_cache)
134
7
            : IcebergReaderMixin<OrcReader>(kv_cache, profile, state, params, range, batch_size,
135
7
                                            ctz, io_ctx, meta_cache) {}
136
137
0
    void set_delete_rows() final {
138
        // Call OrcReader's set_position_delete_rowids
139
0
        this->set_position_delete_rowids(_iceberg_delete_rows);
140
0
    }
141
142
protected:
143
    // ORC-specific schema matching via on_before_init_reader hook
144
    Status on_before_init_reader(ReaderInitContext* ctx) override;
145
146
    std::unique_ptr<GenericReader> _create_equality_reader(
147
0
            const TFileRangeDesc& delete_desc) override {
148
0
        return OrcReader::create_unique(this->get_profile(), this->get_state(),
149
0
                                        this->get_scan_params(), delete_desc,
150
0
                                        READ_DELETE_FILE_BATCH_SIZE, this->get_state()->timezone(),
151
0
                                        this->get_io_ctx(), this->_meta_cache);
152
0
    }
153
154
    static ColumnIdResult _create_column_ids(const orc::Type* orc_type,
155
                                             const TupleDescriptor* tuple_descriptor);
156
157
    static const std::string ICEBERG_ORC_ATTRIBUTE;
158
159
private:
160
    Status _read_position_delete_file(const TFileRangeDesc* delete_range,
161
                                      DeleteFile* position_delete) final;
162
};
163
164
#include "common/compile_check_end.h"
165
} // namespace doris