be/src/format/jni_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 <cstddef> |
21 | | #include <memory> |
22 | | #include <string> |
23 | | #include <unordered_map> |
24 | | #include <unordered_set> |
25 | | #include <vector> |
26 | | |
27 | | #include "common/status.h" |
28 | | #include "exec/connector/jni_connector.h" |
29 | | #include "format/generic_reader.h" |
30 | | #include "storage/olap_scan_common.h" |
31 | | |
32 | | namespace doris { |
33 | | #include "common/compile_check_begin.h" |
34 | | class RuntimeProfile; |
35 | | class RuntimeState; |
36 | | class SlotDescriptor; |
37 | | class Block; |
38 | | } // namespace doris |
39 | | |
40 | | namespace doris { |
41 | | |
42 | | class JniReader : public GenericReader { |
43 | | public: |
44 | | JniReader(const std::vector<SlotDescriptor*>& file_slot_descs, RuntimeState* state, |
45 | | RuntimeProfile* profile) |
46 | 0 | : _file_slot_descs(file_slot_descs), _state(state), _profile(profile) {}; |
47 | | |
48 | 0 | ~JniReader() override = default; |
49 | | |
50 | | Status get_columns(std::unordered_map<std::string, DataTypePtr>* name_to_type, |
51 | 0 | std::unordered_set<std::string>* missing_cols) override { |
52 | 0 | for (const auto& desc : _file_slot_descs) { |
53 | 0 | name_to_type->emplace(desc->col_name(), desc->type()); |
54 | 0 | } |
55 | 0 | return Status::OK(); |
56 | 0 | } |
57 | | |
58 | 0 | Status get_next_block(Block* block, size_t* read_rows, bool* eof) override { |
59 | 0 | return _jni_connector->get_next_block(block, read_rows, eof); |
60 | 0 | } |
61 | | |
62 | 0 | Status close() override { |
63 | 0 | if (_jni_connector) { |
64 | 0 | return _jni_connector->close(); |
65 | 0 | } |
66 | 0 | return Status::OK(); |
67 | 0 | } |
68 | | |
69 | | void set_col_name_to_block_idx( |
70 | 0 | const std::unordered_map<std::string, uint32_t>* col_name_to_block_idx) { |
71 | 0 | if (_jni_connector) { |
72 | 0 | _jni_connector->set_col_name_to_block_idx(col_name_to_block_idx); |
73 | 0 | } |
74 | 0 | } |
75 | | |
76 | | protected: |
77 | 0 | void _collect_profile_before_close() override { |
78 | 0 | if (_jni_connector) { |
79 | 0 | _jni_connector->collect_profile_before_close(); |
80 | 0 | } |
81 | 0 | } |
82 | | |
83 | | const std::vector<SlotDescriptor*>& _file_slot_descs; |
84 | | RuntimeState* _state = nullptr; |
85 | | RuntimeProfile* _profile = nullptr; |
86 | | std::unique_ptr<JniConnector> _jni_connector; |
87 | | }; |
88 | | |
89 | | /** |
90 | | * The demo usage of JniReader, showing how to read data from java scanner. |
91 | | * The java side is also a mock reader that provide values for each type. |
92 | | * This class will only be retained during the functional testing phase to verify that |
93 | | * the communication and data exchange with the jvm are correct. |
94 | | */ |
95 | | class MockJniReader : public JniReader { |
96 | | public: |
97 | | MockJniReader(const std::vector<SlotDescriptor*>& file_slot_descs, RuntimeState* state, |
98 | | RuntimeProfile* profile); |
99 | | |
100 | | ~MockJniReader() override = default; |
101 | | |
102 | | Status init_reader(); |
103 | | |
104 | 0 | Status close() override { |
105 | 0 | if (_jni_connector) { |
106 | 0 | return _jni_connector->close(); |
107 | 0 | } |
108 | 0 | return Status::OK(); |
109 | 0 | } |
110 | | |
111 | | protected: |
112 | 0 | void _collect_profile_before_close() override { |
113 | 0 | if (_jni_connector != nullptr) { |
114 | 0 | _jni_connector->collect_profile_before_close(); |
115 | 0 | } |
116 | 0 | } |
117 | | }; |
118 | | |
119 | | #include "common/compile_check_end.h" |
120 | | } // namespace doris |