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 | 9 | ~PaimonReader() final = default; |
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 | | Status TEST_parse_deletion_vector_file(const TTableFormatFileDesc& t_desc, DeleteFileDesc* desc, |
43 | 4 | bool* has_delete_file) { |
44 | 4 | return _parse_deletion_vector_file(t_desc, desc, has_delete_file); |
45 | 4 | } |
46 | | #endif |
47 | | |
48 | | protected: |
49 | | format::TableColumnMappingMode mapping_mode() const override; |
50 | | Status annotate_file_schema(std::vector<format::ColumnDefinition>* file_schema) override; |
51 | | |
52 | | Status _parse_deletion_vector_file(const TTableFormatFileDesc& t_desc, DeleteFileDesc* desc, |
53 | | bool* has_delete_file) override; |
54 | | |
55 | | private: |
56 | | int64_t _split_schema_id = -1; |
57 | | }; |
58 | | |
59 | | // Paimon scans can contain both native data-file splits and serialized JNI splits in the same |
60 | | // SplitSource. FileScannerV2 owns one table reader for the scanner lifetime, so this reader keeps |
61 | | // native and JNI child readers internally and dispatches each split to the matching child reader. |
62 | | class PaimonHybridReader final : public format::TableReader { |
63 | | public: |
64 | 4 | ~PaimonHybridReader() override = default; |
65 | | |
66 | | Status init(format::TableReadOptions&& options) override; |
67 | | Status prepare_split(const format::SplitReadOptions& options) override; |
68 | | Status get_block(Block* block, bool* eos) override; |
69 | | bool current_split_pruned() const override; |
70 | | bool current_split_uses_metadata_count() const override; |
71 | | Status abort_split() override; |
72 | | Status close() override; |
73 | | void set_batch_size(size_t batch_size) override; |
74 | | |
75 | | #ifdef BE_TEST |
76 | 3 | static bool TEST_is_jni_split(const TFileRangeDesc& range) { return _is_jni_split(range); } |
77 | | static Status TEST_to_file_format(const TFileRangeDesc& range, |
78 | 3 | format::FileFormat* file_format) { |
79 | 3 | return _to_file_format(range, file_format); |
80 | 3 | } |
81 | 1 | void TEST_install_batch_size_children() { |
82 | 1 | _native_reader = std::make_unique<format::TableReader>(); |
83 | 1 | _jni_reader = std::make_unique<format::TableReader>(); |
84 | 1 | } |
85 | 1 | std::pair<size_t, size_t> TEST_child_batch_sizes() const { |
86 | 1 | return {_native_reader->TEST_batch_size(), _jni_reader->TEST_batch_size()}; |
87 | 1 | } |
88 | | void TEST_set_child_reader_factories( |
89 | | std::function<std::unique_ptr<format::TableReader>()> native_factory, |
90 | 1 | std::function<std::unique_ptr<format::TableReader>()> jni_factory) { |
91 | 1 | _test_native_reader_factory = std::move(native_factory); |
92 | 1 | _test_jni_reader_factory = std::move(jni_factory); |
93 | 1 | } |
94 | | #endif |
95 | | |
96 | | private: |
97 | | Status _ensure_current_split_reader(const format::SplitReadOptions& options); |
98 | | Status _init_child_reader(format::TableReader* reader, format::FileFormat file_format); |
99 | | Status _clone_conjuncts(VExprContextSPtrs* conjuncts) const; |
100 | | static bool _is_jni_split(const TFileRangeDesc& range); |
101 | | static Status _to_file_format(const TFileRangeDesc& range, format::FileFormat* file_format); |
102 | | |
103 | | std::unique_ptr<format::TableReader> _native_reader; // handle parquet/orc native splits |
104 | | std::unique_ptr<format::TableReader> _jni_reader; // handle serialized JNI splits |
105 | | format::TableReader* _current_split_reader = nullptr; |
106 | | #ifdef BE_TEST |
107 | | std::function<std::unique_ptr<format::TableReader>()> _test_native_reader_factory; |
108 | | std::function<std::unique_ptr<format::TableReader>()> _test_jni_reader_factory; |
109 | | #endif |
110 | | }; |
111 | | |
112 | | } // namespace doris::format::paimon |