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