Coverage Report

Created: 2026-07-11 19:13

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
class RowDescriptor;
45
class RuntimeState;
46
class SlotDescriptor;
47
class TFileRangeDesc;
48
class TFileScanRangeParams;
49
class TIcebergDeleteFileDesc;
50
class TupleDescriptor;
51
52
namespace io {
53
struct IOContext;
54
} // namespace io
55
template <typename T>
56
class ColumnStr;
57
using ColumnString = ColumnStr<UInt32>;
58
class Block;
59
class GenericReader;
60
class ShardedKVCache;
61
class VExprContext;
62
63
struct IcebergTableReader {
64
    static bool _is_fully_dictionary_encoded(const tparquet::ColumnMetaData& column_metadata);
65
};
66
67
// IcebergParquetReader: inherits ParquetReader via IcebergReaderMixin CRTP
68
class IcebergParquetReader final : public IcebergReaderMixin<ParquetReader> {
69
public:
70
    ENABLE_FACTORY_CREATOR(IcebergParquetReader);
71
72
    IcebergParquetReader(ShardedKVCache* kv_cache, RuntimeProfile* profile,
73
                         const TFileScanRangeParams& params, const TFileRangeDesc& range,
74
                         size_t batch_size, const cctz::time_zone* ctz, io::IOContext* io_ctx,
75
                         RuntimeState* state, FileMetaCache* meta_cache)
76
9
            : IcebergReaderMixin<ParquetReader>(kv_cache, profile, params, range, batch_size, ctz,
77
9
                                                io_ctx, state, meta_cache) {}
78
79
    IcebergParquetReader(ShardedKVCache* kv_cache, RuntimeProfile* profile,
80
                         const TFileScanRangeParams& params, const TFileRangeDesc& range,
81
                         size_t batch_size, const cctz::time_zone* ctz,
82
                         std::shared_ptr<io::IOContext> io_ctx_holder, RuntimeState* state,
83
                         FileMetaCache* meta_cache)
84
0
            : IcebergReaderMixin<ParquetReader>(kv_cache, profile, params, range, batch_size, ctz,
85
0
                                                std::move(io_ctx_holder), state, meta_cache) {}
86
87
0
    void set_delete_rows() final {
88
        // Call ParquetReader's set_delete_rows(const vector<int64_t>*)
89
0
        ParquetReader::set_delete_rows(_iceberg_delete_rows);
90
0
    }
91
92
0
    void set_deletion_vector() final {
93
0
        ParquetReader::set_deletion_vector(_iceberg_deletion_vector);
94
0
    }
95
96
protected:
97
    // Parquet-specific schema matching via on_before_init_reader hook
98
    Status on_before_init_reader(ReaderInitContext* ctx) override;
99
100
    std::unique_ptr<GenericReader> _create_equality_reader(
101
0
            const TFileRangeDesc& delete_desc) final {
102
0
        return ParquetReader::create_unique(this->get_profile(), this->get_scan_params(),
103
0
                                            delete_desc, READ_DELETE_FILE_BATCH_SIZE,
104
0
                                            &this->get_state()->timezone_obj(), this->get_io_ctx(),
105
0
                                            this->get_state(), this->_meta_cache);
106
0
    }
107
108
    static ColumnIdResult _create_column_ids(const FieldDescriptor* field_desc,
109
                                             const TupleDescriptor* tuple_descriptor);
110
111
private:
112
    Status _read_position_delete_file(const TFileRangeDesc* delete_range,
113
                                      DeleteFile* position_delete) final;
114
};
115
116
// IcebergOrcReader: inherits OrcReader via IcebergReaderMixin CRTP
117
class IcebergOrcReader final : public IcebergReaderMixin<OrcReader> {
118
public:
119
    ENABLE_FACTORY_CREATOR(IcebergOrcReader);
120
121
    IcebergOrcReader(ShardedKVCache* kv_cache, RuntimeProfile* profile, RuntimeState* state,
122
                     const TFileScanRangeParams& params, const TFileRangeDesc& range,
123
                     size_t batch_size, const std::string& ctz, io::IOContext* io_ctx,
124
                     FileMetaCache* meta_cache)
125
7
            : IcebergReaderMixin<OrcReader>(kv_cache, profile, state, params, range, batch_size,
126
7
                                            ctz, io_ctx, meta_cache) {}
127
128
    IcebergOrcReader(ShardedKVCache* kv_cache, RuntimeProfile* profile, RuntimeState* state,
129
                     const TFileScanRangeParams& params, const TFileRangeDesc& range,
130
                     size_t batch_size, const std::string& ctz,
131
                     std::shared_ptr<io::IOContext> io_ctx_holder, FileMetaCache* meta_cache)
132
0
            : IcebergReaderMixin<OrcReader>(kv_cache, profile, state, params, range, batch_size,
133
0
                                            ctz, std::move(io_ctx_holder), meta_cache) {}
134
135
0
    void set_delete_rows() final {
136
        // Call OrcReader's set_position_delete_rowids
137
0
        this->set_position_delete_rowids(_iceberg_delete_rows);
138
0
    }
139
140
0
    void set_deletion_vector() final { OrcReader::set_deletion_vector(_iceberg_deletion_vector); }
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
} // namespace doris