Coverage Report

Created: 2026-04-16 14:28

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 <memory>
21
#include <vector>
22
23
#include "format/orc/vorc_reader.h"
24
#include "format/parquet/vparquet_reader.h"
25
#include "format/table/table_format_reader.h"
26
27
namespace doris {
28
class PaimonReader : public TableFormatReader, public TableSchemaChangeHelper {
29
public:
30
    PaimonReader(std::unique_ptr<GenericReader> file_format_reader, RuntimeProfile* profile,
31
                 RuntimeState* state, const TFileScanRangeParams& params,
32
                 const TFileRangeDesc& range, ShardedKVCache* kv_cache, io::IOContext* io_ctx,
33
                 FileMetaCache* meta_cache);
34
35
0
    ~PaimonReader() override = default;
36
37
    Status init_row_filters() final;
38
39
    Status get_next_block_inner(Block* block, size_t* read_rows, bool* eof) final;
40
41
protected:
42
    struct PaimonProfile {
43
        RuntimeProfile::Counter* num_delete_rows;
44
        RuntimeProfile::Counter* delete_files_read_time;
45
        RuntimeProfile::Counter* parse_deletion_vector_time;
46
    };
47
    // _delete_rows from kv_cache.
48
    const std::vector<int64_t>* _delete_rows = nullptr;
49
    // owned by scan node
50
    ShardedKVCache* _kv_cache;
51
    PaimonProfile _paimon_profile;
52
53
    virtual void set_delete_rows() = 0;
54
};
55
56
class PaimonOrcReader final : public PaimonReader {
57
public:
58
    ENABLE_FACTORY_CREATOR(PaimonOrcReader);
59
    PaimonOrcReader(std::unique_ptr<GenericReader> file_format_reader, RuntimeProfile* profile,
60
                    RuntimeState* state, const TFileScanRangeParams& params,
61
                    const TFileRangeDesc& range, ShardedKVCache* kv_cache, io::IOContext* io_ctx,
62
                    FileMetaCache* meta_cache)
63
0
            : PaimonReader(std::move(file_format_reader), profile, state, params, range, kv_cache,
64
0
                           io_ctx, meta_cache) {};
65
0
    ~PaimonOrcReader() final = default;
66
67
0
    void set_delete_rows() final {
68
0
        (reinterpret_cast<OrcReader*>(_file_format_reader.get()))
69
0
                ->set_position_delete_rowids(_delete_rows);
70
0
    }
71
72
    Status init_reader(
73
            const std::vector<std::string>& read_table_col_names,
74
            std::unordered_map<std::string, uint32_t>* col_name_to_block_idx,
75
            const VExprContextSPtrs& conjuncts, const TupleDescriptor* tuple_descriptor,
76
            const RowDescriptor* row_descriptor,
77
            const VExprContextSPtrs* not_single_slot_filter_conjuncts,
78
0
            const std::unordered_map<int, VExprContextSPtrs>* slot_id_to_filter_conjuncts) {
79
0
        auto* orc_reader = static_cast<OrcReader*>(_file_format_reader.get());
80
0
        const orc::Type* orc_type_ptr = nullptr;
81
0
        RETURN_IF_ERROR(orc_reader->get_file_type(&orc_type_ptr));
82
0
        RETURN_IF_ERROR(gen_table_info_node_by_field_id(
83
0
                _params, _range.table_format_params.paimon_params.schema_id, tuple_descriptor,
84
0
                orc_type_ptr));
85
86
0
        return orc_reader->init_reader(&read_table_col_names, col_name_to_block_idx, conjuncts,
87
0
                                       false, tuple_descriptor, row_descriptor,
88
0
                                       not_single_slot_filter_conjuncts,
89
0
                                       slot_id_to_filter_conjuncts, table_info_node_ptr);
90
0
    }
91
};
92
93
class PaimonParquetReader final : public PaimonReader {
94
public:
95
    ENABLE_FACTORY_CREATOR(PaimonParquetReader);
96
    PaimonParquetReader(std::unique_ptr<GenericReader> file_format_reader, RuntimeProfile* profile,
97
                        RuntimeState* state, const TFileScanRangeParams& params,
98
                        const TFileRangeDesc& range, ShardedKVCache* kv_cache,
99
                        io::IOContext* io_ctx, FileMetaCache* meta_cache)
100
0
            : PaimonReader(std::move(file_format_reader), profile, state, params, range, kv_cache,
101
0
                           io_ctx, meta_cache) {};
102
0
    ~PaimonParquetReader() final = default;
103
104
0
    void set_delete_rows() final {
105
0
        (reinterpret_cast<ParquetReader*>(_file_format_reader.get()))
106
0
                ->set_delete_rows(_delete_rows);
107
0
    }
108
109
    Status init_reader(
110
            const std::vector<std::string>& read_table_col_names,
111
            std::unordered_map<std::string, uint32_t>* col_name_to_block_idx,
112
            const VExprContextSPtrs& conjuncts,
113
            phmap::flat_hash_map<int, std::vector<std::shared_ptr<ColumnPredicate>>>&
114
                    slot_id_to_predicates,
115
            const TupleDescriptor* tuple_descriptor, const RowDescriptor* row_descriptor,
116
            const std::unordered_map<std::string, int>* colname_to_slot_id,
117
            const VExprContextSPtrs* not_single_slot_filter_conjuncts,
118
0
            const std::unordered_map<int, VExprContextSPtrs>* slot_id_to_filter_conjuncts) {
119
0
        auto* parquet_reader = static_cast<ParquetReader*>(_file_format_reader.get());
120
121
0
        const FieldDescriptor* field_desc = nullptr;
122
0
        RETURN_IF_ERROR(parquet_reader->get_file_metadata_schema(&field_desc));
123
0
        DCHECK(field_desc != nullptr);
124
125
0
        RETURN_IF_ERROR(gen_table_info_node_by_field_id(
126
0
                _params, _range.table_format_params.paimon_params.schema_id, tuple_descriptor,
127
0
                *field_desc));
128
129
0
        return parquet_reader->init_reader(read_table_col_names, col_name_to_block_idx, conjuncts,
130
0
                                           slot_id_to_predicates, tuple_descriptor, row_descriptor,
131
0
                                           colname_to_slot_id, not_single_slot_filter_conjuncts,
132
0
                                           slot_id_to_filter_conjuncts, table_info_node_ptr);
133
0
    }
134
};
135
} // namespace doris