Coverage Report

Created: 2026-09-09 01:13

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
be/src/format_v2/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 <functional>
21
#include <utility>
22
23
#include "format_v2/table_reader.h"
24
25
namespace doris {
26
struct DeleteFileDesc;
27
}
28
namespace doris::format::paimon {
29
30
class PaimonReader final : public format::TableReader {
31
public:
32
    ENABLE_FACTORY_CREATOR(PaimonReader);
33
15
    ~PaimonReader() final = default;
34
    Status prepare_split(const format::SplitReadOptions& options) override;
35
36
#ifdef BE_TEST
37
4
    void TEST_set_scan_params(TFileScanRangeParams* params) { _scan_params = params; }
38
4
    void TEST_set_projected_columns(std::vector<format::ColumnDefinition> columns) {
39
4
        _projected_columns = std::move(columns);
40
4
    }
41
4
    void TEST_set_format(format::FileFormat format) { _format = format; }
42
4
    format::TableColumnMappingMode TEST_mapping_mode() const { return mapping_mode(); }
43
7
    Status TEST_annotate_file_schema(std::vector<format::ColumnDefinition>* file_schema) {
44
7
        return annotate_file_schema(file_schema);
45
7
    }
46
4
    Status TEST_customize_file_scan_request(format::FileScanRequest* request) {
47
4
        return customize_file_scan_request(request);
48
4
    }
49
    Status TEST_parse_deletion_vector_file(const TTableFormatFileDesc& t_desc, DeleteFileDesc* desc,
50
4
                                           bool* has_delete_file) {
51
4
        return _parse_deletion_vector_file(t_desc, desc, has_delete_file);
52
4
    }
53
#endif
54
55
protected:
56
3
    void configure_mapper_options(format::TableColumnMapperOptions* options) const override {
57
3
        options->enable_paimon_metadata_virtual_columns = true;
58
3
    }
59
    format::TableColumnMappingMode mapping_mode() const override;
60
    Status annotate_file_schema(std::vector<format::ColumnDefinition>* file_schema) override;
61
    Status customize_file_scan_request(format::FileScanRequest* file_request) override;
62
    Status materialize_virtual_columns(Block* table_block) override;
63
64
    Status _parse_deletion_vector_file(const TTableFormatFileDesc& t_desc, DeleteFileDesc* desc,
65
                                       bool* has_delete_file) override;
66
67
private:
68
    const std::string& _data_file_path() const;
69
    Status _append_row_position_output_column(format::FileScanRequest* request);
70
    Status _materialize_file_path(Block* table_block, size_t column_idx);
71
    Status _materialize_row_position(Block* table_block, size_t column_idx);
72
    bool _need_metadata_columns() const;
73
74
    int64_t _split_schema_id = -1;
75
    size_t _row_position_block_position = 0;
76
    std::string _original_file_path;
77
    std::vector<format::LocalColumnIndex> _variant_schema_overrides;
78
};
79
80
// Paimon scans can contain both native data-file splits and serialized JNI splits in the same
81
// SplitSource. FileScannerV2 owns one table reader for the scanner lifetime, so this reader keeps
82
// native and JNI child readers internally and dispatches each split to the matching child reader.
83
class PaimonHybridReader final : public format::TableReader {
84
public:
85
7
    ~PaimonHybridReader() override = default;
86
87
    Status init(format::TableReadOptions&& options) override;
88
    Status prepare_split(const format::SplitReadOptions& options) override;
89
    Status refresh_conjuncts(VExprContextSPtrs conjuncts) override;
90
    Status get_block(Block* block, bool* eos) override;
91
    bool current_split_pruned() const override;
92
    bool current_split_uses_metadata_count() const override;
93
    Status abort_split() override;
94
    Status close() override;
95
    void set_batch_size(size_t batch_size) override;
96
    int64_t condition_cache_hit_count() const override;
97
98
#ifdef BE_TEST
99
3
    static bool TEST_is_jni_split(const TFileRangeDesc& range) { return _is_jni_split(range); }
100
    static Status TEST_to_file_format(const TFileRangeDesc& range,
101
5
                                      format::FileFormat* file_format) {
102
5
        return _to_file_format(range, file_format);
103
5
    }
104
2
    void TEST_install_batch_size_children() {
105
2
        _native_reader = std::make_unique<format::TableReader>();
106
2
        _jni_reader = std::make_unique<format::TableReader>();
107
2
    }
108
1
    std::pair<size_t, size_t> TEST_child_batch_sizes() const {
109
1
        return {_native_reader->TEST_batch_size(), _jni_reader->TEST_batch_size()};
110
1
    }
111
1
    void TEST_set_child_condition_cache_hits(int64_t native_hits, int64_t jni_hits) {
112
1
        _native_reader->TEST_set_condition_cache_hit_count(native_hits);
113
1
        _jni_reader->TEST_set_condition_cache_hit_count(jni_hits);
114
1
    }
115
    void TEST_set_child_reader_factories(
116
            std::function<std::unique_ptr<format::TableReader>()> native_factory,
117
3
            std::function<std::unique_ptr<format::TableReader>()> jni_factory) {
118
3
        _test_native_reader_factory = std::move(native_factory);
119
3
        _test_jni_reader_factory = std::move(jni_factory);
120
3
    }
121
#endif
122
123
private:
124
    Status _ensure_current_split_reader(const format::SplitReadOptions& options);
125
    Status _init_child_reader(format::TableReader* reader, format::FileFormat file_format);
126
    Status _clone_conjuncts(VExprContextSPtrs* conjuncts) const;
127
    static bool _is_jni_split(const TFileRangeDesc& range);
128
    static Status _to_file_format(const TFileRangeDesc& range, format::FileFormat* file_format);
129
130
    std::unique_ptr<format::TableReader> _native_reader; // handle parquet/orc native splits
131
    std::unique_ptr<format::TableReader> _jni_reader;    // handle serialized JNI splits
132
    format::TableReader* _current_split_reader = nullptr;
133
#ifdef BE_TEST
134
    std::function<std::unique_ptr<format::TableReader>()> _test_native_reader_factory;
135
    std::function<std::unique_ptr<format::TableReader>()> _test_jni_reader_factory;
136
#endif
137
};
138
139
} // namespace doris::format::paimon