Coverage Report

Created: 2026-06-04 13:02

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
            : IcebergReaderMixin<ParquetReader>(kv_cache, profile, params, range, batch_size, ctz,
77
                                                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
protected:
93
    // Parquet-specific schema matching via on_before_init_reader hook
94
    Status on_before_init_reader(ReaderInitContext* ctx) override;
95
96
    std::unique_ptr<GenericReader> _create_equality_reader(
97
0
            const TFileRangeDesc& delete_desc) final {
98
0
        return ParquetReader::create_unique(this->get_profile(), this->get_scan_params(),
99
0
                                            delete_desc, READ_DELETE_FILE_BATCH_SIZE,
100
0
                                            &this->get_state()->timezone_obj(), this->get_io_ctx(),
101
0
                                            this->get_state(), this->_meta_cache);
102
0
    }
103
104
    static ColumnIdResult _create_column_ids(const FieldDescriptor* field_desc,
105
                                             const TupleDescriptor* tuple_descriptor);
106
107
private:
108
    Status _read_position_delete_file(const TFileRangeDesc* delete_range,
109
                                      DeleteFile* position_delete) final;
110
};
111
112
// IcebergOrcReader: inherits OrcReader via IcebergReaderMixin CRTP
113
class IcebergOrcReader final : public IcebergReaderMixin<OrcReader> {
114
public:
115
    ENABLE_FACTORY_CREATOR(IcebergOrcReader);
116
117
    IcebergOrcReader(ShardedKVCache* kv_cache, RuntimeProfile* profile, RuntimeState* state,
118
                     const TFileScanRangeParams& params, const TFileRangeDesc& range,
119
                     size_t batch_size, const std::string& ctz, io::IOContext* io_ctx,
120
                     FileMetaCache* meta_cache)
121
            : IcebergReaderMixin<OrcReader>(kv_cache, profile, state, params, range, batch_size,
122
                                            ctz, io_ctx, meta_cache) {}
123
124
    IcebergOrcReader(ShardedKVCache* kv_cache, RuntimeProfile* profile, RuntimeState* state,
125
                     const TFileScanRangeParams& params, const TFileRangeDesc& range,
126
                     size_t batch_size, const std::string& ctz,
127
                     std::shared_ptr<io::IOContext> io_ctx_holder, FileMetaCache* meta_cache)
128
0
            : IcebergReaderMixin<OrcReader>(kv_cache, profile, state, params, range, batch_size,
129
0
                                            ctz, std::move(io_ctx_holder), meta_cache) {}
130
131
0
    void set_delete_rows() final {
132
        // Call OrcReader's set_position_delete_rowids
133
0
        this->set_position_delete_rowids(_iceberg_delete_rows);
134
0
    }
135
136
protected:
137
    // ORC-specific schema matching via on_before_init_reader hook
138
    Status on_before_init_reader(ReaderInitContext* ctx) override;
139
140
    std::unique_ptr<GenericReader> _create_equality_reader(
141
0
            const TFileRangeDesc& delete_desc) override {
142
0
        return OrcReader::create_unique(this->get_profile(), this->get_state(),
143
0
                                        this->get_scan_params(), delete_desc,
144
0
                                        READ_DELETE_FILE_BATCH_SIZE, this->get_state()->timezone(),
145
0
                                        this->get_io_ctx(), this->_meta_cache);
146
0
    }
147
148
    static ColumnIdResult _create_column_ids(const orc::Type* orc_type,
149
                                             const TupleDescriptor* tuple_descriptor);
150
151
    static const std::string ICEBERG_ORC_ATTRIBUTE;
152
153
private:
154
    Status _read_position_delete_file(const TFileRangeDesc* delete_range,
155
                                      DeleteFile* position_delete) final;
156
};
157
158
} // namespace doris