Coverage Report

Created: 2026-03-16 11:17

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