Coverage Report

Created: 2026-07-15 03:26

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
be/src/format_v2/table/hudi_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 <utility>
22
#include <vector>
23
24
#include "format_v2/table_reader.h"
25
26
namespace doris::format::hudi {
27
28
class HudiReader final : public format::TableReader {
29
public:
30
    ENABLE_FACTORY_CREATOR(HudiReader);
31
4
    ~HudiReader() final = default;
32
33
    Status prepare_split(const format::SplitReadOptions& options) override;
34
35
#ifdef BE_TEST
36
3
    void TEST_set_scan_params(TFileScanRangeParams* params) { _scan_params = params; }
37
4
    format::TableColumnMappingMode TEST_mapping_mode() const { return mapping_mode(); }
38
2
    Status TEST_annotate_file_schema(std::vector<format::ColumnDefinition>* file_schema) {
39
2
        return annotate_file_schema(file_schema);
40
2
    }
41
#endif
42
43
protected:
44
    format::TableColumnMappingMode mapping_mode() const override;
45
    Status annotate_file_schema(std::vector<format::ColumnDefinition>* file_schema) override;
46
47
private:
48
    int64_t _split_schema_id = -1;
49
};
50
51
// Hudi MOR scans can contain both JNI splits that need log-file merge semantics and native
52
// data-file splits without delta logs in the same SplitSource. FileScannerV2 owns one table reader
53
// for the scanner lifetime, so this reader keeps native and JNI child readers internally and
54
// dispatches each split to the matching child reader.
55
class HudiHybridReader final : public format::TableReader {
56
public:
57
1
    ~HudiHybridReader() override = default;
58
59
    Status init(format::TableReadOptions&& options) override;
60
    Status prepare_split(const format::SplitReadOptions& options) override;
61
    Status get_block(Block* block, bool* eos) override;
62
    bool current_split_pruned() const override;
63
    Status abort_split() override;
64
    Status close() override;
65
    void set_batch_size(size_t batch_size) override;
66
67
#ifdef BE_TEST
68
1
    void TEST_install_batch_size_children() {
69
1
        _native_reader = std::make_unique<format::TableReader>();
70
1
        _jni_reader = std::make_unique<format::TableReader>();
71
1
    }
72
1
    std::pair<size_t, size_t> TEST_child_batch_sizes() const {
73
1
        return {_native_reader->TEST_batch_size(), _jni_reader->TEST_batch_size()};
74
1
    }
75
#endif
76
77
private:
78
    Status _ensure_current_split_reader(const format::SplitReadOptions& options);
79
    Status _init_child_reader(format::TableReader* reader, format::FileFormat file_format);
80
    Status _clone_conjuncts(VExprContextSPtrs* conjuncts) const;
81
    static TFileFormatType::type _range_format_type(const TFileScanRangeParams& params,
82
                                                    const TFileRangeDesc& range);
83
    static bool _is_jni_split(const TFileScanRangeParams& params, const TFileRangeDesc& range);
84
    static Status _to_file_format(const TFileScanRangeParams& params, const TFileRangeDesc& range,
85
                                  format::FileFormat* file_format);
86
87
    std::unique_ptr<format::TableReader> _native_reader; // handle native parquet/orc splits
88
    std::unique_ptr<format::TableReader> _jni_reader;    // handle MOR JNI splits
89
    format::TableReader* _current_split_reader = nullptr;
90
};
91
92
} // namespace doris::format::hudi