Coverage Report

Created: 2026-07-20 15:57

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
be/src/format/table/paimon_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 <gen_cpp/PlanNodes_types.h>
21
22
#include <cstddef>
23
#include <memory>
24
#include <string>
25
#include <utility>
26
#include <vector>
27
28
#include "common/status.h"
29
#include "format/orc/vorc_reader.h"
30
#include "format/parquet/vparquet_reader.h"
31
#include "format/table/deletion_vector.h"
32
#include "format/table/table_schema_change_helper.h"
33
34
namespace doris {
35
class ShardedKVCache;
36
37
std::string build_paimon_deletion_vector_cache_key(const TPaimonDeletionFileDesc& deletion_file);
38
39
Status validate_paimon_deletion_vector_descriptor(const TPaimonDeletionFileDesc& deletion_file,
40
                                                  size_t& bytes_read);
41
42
Status decode_paimon_deletion_vector_buffer(const char* buf, size_t buffer_size,
43
                                            DeletionVector* deletion_vector);
44
45
// PaimonOrcReader: directly inherits OrcReader (no composition wrapping).
46
// Schema mapping in on_before_init_reader, deletion vector reading in on_after_init_reader.
47
class PaimonOrcReader final : public OrcReader, public TableSchemaChangeHelper {
48
public:
49
    ENABLE_FACTORY_CREATOR(PaimonOrcReader);
50
    PaimonOrcReader(RuntimeProfile* profile, RuntimeState* state,
51
                    const TFileScanRangeParams& params, const TFileRangeDesc& range,
52
                    size_t batch_size, const std::string& ctz, ShardedKVCache* kv_cache,
53
                    io::IOContext* io_ctx, FileMetaCache* meta_cache = nullptr,
54
                    bool enable_lazy_mat = true)
55
            : OrcReader(profile, state, params, range, batch_size, ctz, io_ctx, meta_cache,
56
                        enable_lazy_mat),
57
              _kv_cache(kv_cache) {
58
        _init_paimon_profile();
59
    }
60
    PaimonOrcReader(RuntimeProfile* profile, RuntimeState* state,
61
                    const TFileScanRangeParams& params, const TFileRangeDesc& range,
62
                    size_t batch_size, const std::string& ctz, ShardedKVCache* kv_cache,
63
                    std::shared_ptr<io::IOContext> io_ctx_holder,
64
                    FileMetaCache* meta_cache = nullptr, bool enable_lazy_mat = true)
65
7.68k
            : OrcReader(profile, state, params, range, batch_size, ctz, std::move(io_ctx_holder),
66
7.68k
                        meta_cache, enable_lazy_mat),
67
7.68k
              _kv_cache(kv_cache) {
68
7.68k
        _init_paimon_profile();
69
7.68k
    }
70
7.69k
    ~PaimonOrcReader() final = default;
71
72
    Status TEST_init_deletion_vector() { return _init_deletion_vector(); }
73
74
protected:
75
    Status on_before_init_reader(ReaderInitContext* ctx) override;
76
77
    Status on_after_init_reader(ReaderInitContext* /*ctx*/) override;
78
79
private:
80
    void _init_paimon_profile();
81
    Status _init_deletion_vector();
82
83
    struct PaimonProfile {
84
        RuntimeProfile::Counter* num_delete_rows = nullptr;
85
        RuntimeProfile::Counter* delete_files_read_time = nullptr;
86
        RuntimeProfile::Counter* parse_deletion_vector_time = nullptr;
87
        RuntimeProfile::Counter* decoded_cache_hit_count = nullptr;
88
        RuntimeProfile::Counter* decoded_cache_miss_count = nullptr;
89
        RuntimeProfile::Counter* file_cache_hit_count = nullptr;
90
        RuntimeProfile::Counter* file_cache_miss_count = nullptr;
91
        RuntimeProfile::Counter* file_cache_peer_read_count = nullptr;
92
    };
93
94
    const DeletionVector* _deletion_vector = nullptr;
95
    ShardedKVCache* _kv_cache;
96
    PaimonProfile _paimon_profile;
97
};
98
99
// PaimonParquetReader: directly inherits ParquetReader (no composition wrapping).
100
class PaimonParquetReader final : public ParquetReader, public TableSchemaChangeHelper {
101
public:
102
    ENABLE_FACTORY_CREATOR(PaimonParquetReader);
103
    PaimonParquetReader(RuntimeProfile* profile, const TFileScanRangeParams& params,
104
                        const TFileRangeDesc& range, size_t batch_size, const cctz::time_zone* ctz,
105
                        ShardedKVCache* kv_cache, io::IOContext* io_ctx, RuntimeState* state,
106
                        FileMetaCache* meta_cache = nullptr, bool enable_lazy_mat = true)
107
            : ParquetReader(profile, params, range, batch_size, ctz, io_ctx, state, meta_cache,
108
                            enable_lazy_mat),
109
              _kv_cache(kv_cache) {
110
        _init_paimon_profile();
111
    }
112
    PaimonParquetReader(RuntimeProfile* profile, const TFileScanRangeParams& params,
113
                        const TFileRangeDesc& range, size_t batch_size, const cctz::time_zone* ctz,
114
                        ShardedKVCache* kv_cache, std::shared_ptr<io::IOContext> io_ctx_holder,
115
                        RuntimeState* state, FileMetaCache* meta_cache = nullptr,
116
                        bool enable_lazy_mat = true)
117
49.6k
            : ParquetReader(profile, params, range, batch_size, ctz, std::move(io_ctx_holder),
118
49.6k
                            state, meta_cache, enable_lazy_mat),
119
49.6k
              _kv_cache(kv_cache) {
120
49.6k
        _init_paimon_profile();
121
49.6k
    }
122
48.2k
    ~PaimonParquetReader() final = default;
123
124
    Status TEST_init_deletion_vector() { return _init_deletion_vector(); }
125
126
protected:
127
    Status on_before_init_reader(ReaderInitContext* ctx) override;
128
129
    Status on_after_init_reader(ReaderInitContext* /*ctx*/) override;
130
131
private:
132
    void _init_paimon_profile();
133
    Status _init_deletion_vector();
134
135
    struct PaimonProfile {
136
        RuntimeProfile::Counter* num_delete_rows = nullptr;
137
        RuntimeProfile::Counter* delete_files_read_time = nullptr;
138
        RuntimeProfile::Counter* parse_deletion_vector_time = nullptr;
139
        RuntimeProfile::Counter* decoded_cache_hit_count = nullptr;
140
        RuntimeProfile::Counter* decoded_cache_miss_count = nullptr;
141
        RuntimeProfile::Counter* file_cache_hit_count = nullptr;
142
        RuntimeProfile::Counter* file_cache_miss_count = nullptr;
143
        RuntimeProfile::Counter* file_cache_peer_read_count = nullptr;
144
    };
145
146
    const DeletionVector* _deletion_vector = nullptr;
147
    ShardedKVCache* _kv_cache;
148
    PaimonProfile _paimon_profile;
149
};
150
151
} // namespace doris