be/src/format/table/paimon_jni_reader.cpp
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 | | #include "paimon_jni_reader.h" |
19 | | |
20 | | #include <map> |
21 | | #include <string_view> |
22 | | #include <vector> |
23 | | |
24 | | #include "core/types.h" |
25 | | #include "format/jni/jni_data_bridge.h" |
26 | | #include "runtime/descriptors.h" |
27 | | #include "runtime/exec_env.h" |
28 | | #include "runtime/runtime_state.h" |
29 | | #include "storage/options.h" |
30 | | #include "util/string_util.h" |
31 | | #include "util/uid_util.h" |
32 | | |
33 | | namespace doris { |
34 | | class RuntimeProfile; |
35 | | class RuntimeState; |
36 | | class Block; |
37 | | } // namespace doris |
38 | | |
39 | | namespace doris { |
40 | | |
41 | | namespace { |
42 | | constexpr std::string_view PAIMON_JNI_SCANNER_IO_TMP_DIR = "paimon_jni_scanner_io_tmp"; |
43 | | } // namespace |
44 | | |
45 | | const std::string PaimonJniReader::PAIMON_OPTION_PREFIX = "paimon."; |
46 | | const std::string PaimonJniReader::HADOOP_OPTION_PREFIX = "hadoop."; |
47 | | const std::string PaimonJniReader::DORIS_ENABLE_JNI_IO_MANAGER = "jni.enable_jni_io_manager"; |
48 | | const std::string PaimonJniReader::DORIS_JNI_IO_MANAGER_TMP_DIR = "jni.io_manager.tmp_dir"; |
49 | | |
50 | | PaimonJniReader::PaimonJniReader(const std::vector<SlotDescriptor*>& file_slot_descs, |
51 | | RuntimeState* state, RuntimeProfile* profile, |
52 | | const TFileRangeDesc& range, |
53 | | const TFileScanRangeParams* range_params) |
54 | 2 | : JniReader( |
55 | 2 | file_slot_descs, state, profile, "org/apache/doris/paimon/PaimonJniScanner", |
56 | 2 | [&]() { |
57 | 2 | std::vector<std::string> column_names; |
58 | 2 | std::vector<std::string> column_types; |
59 | 2 | std::vector<std::string> encoded_column_types; |
60 | 2 | for (const auto& desc : file_slot_descs) { |
61 | 0 | column_names.emplace_back(desc->col_name()); |
62 | 0 | column_types.emplace_back( |
63 | 0 | JniDataBridge::get_jni_type_with_different_string(desc->type())); |
64 | 0 | encoded_column_types.emplace_back( |
65 | 0 | JniDataBridge::get_jni_type_with_encoded_struct_fields( |
66 | 0 | desc->type())); |
67 | 0 | } |
68 | 2 | const auto& paimon_params = range.table_format_params.paimon_params; |
69 | 2 | std::map<String, String> params; |
70 | 2 | params["paimon_split"] = paimon_params.paimon_split; |
71 | 2 | if (range_params->__isset.paimon_predicate && |
72 | 2 | !range_params->paimon_predicate.empty()) { |
73 | 2 | params["paimon_predicate"] = range_params->paimon_predicate; |
74 | 2 | } else if (paimon_params.__isset.paimon_predicate) { |
75 | 0 | params["paimon_predicate"] = paimon_params.paimon_predicate; |
76 | 0 | } |
77 | 2 | params["required_fields"] = join(column_names, ","); |
78 | 2 | params["columns_types"] = join(column_types, "#"); |
79 | | // V1 and V2 must publish the same safe schema protocol because session |
80 | | // routing can select either producer for the same Paimon scanner. |
81 | 2 | params["required_fields_base64"] = |
82 | 2 | JniDataBridge::encode_schema_values(column_names); |
83 | 2 | params["columns_types_base64"] = |
84 | 2 | JniDataBridge::encode_schema_values(encoded_column_types); |
85 | 2 | params["time_zone"] = state->timezone(); |
86 | 2 | if (range_params->__isset.serialized_table) { |
87 | 2 | params["serialized_table"] = range_params->serialized_table; |
88 | 2 | } |
89 | 2 | params["serialized_table_cache_key"] = |
90 | 2 | range_params->__isset.serialized_table_cache_key && |
91 | 2 | !range_params->serialized_table_cache_key.empty() |
92 | 2 | ? range_params->serialized_table_cache_key |
93 | 2 | : generate_uuid_string(); |
94 | 2 | if (range_params->__isset.paimon_options && |
95 | 2 | !range_params->paimon_options.empty()) { |
96 | 0 | for (const auto& kv : range_params->paimon_options) { |
97 | 0 | params[PAIMON_OPTION_PREFIX + kv.first] = kv.second; |
98 | 0 | } |
99 | 2 | } else if (paimon_params.__isset.paimon_options) { |
100 | 0 | for (const auto& kv : paimon_params.paimon_options) { |
101 | 0 | params[PAIMON_OPTION_PREFIX + kv.first] = kv.second; |
102 | 0 | } |
103 | 0 | } |
104 | 2 | const std::string enable_io_manager_key = |
105 | 2 | PAIMON_OPTION_PREFIX + DORIS_ENABLE_JNI_IO_MANAGER; |
106 | 2 | const std::string io_manager_tmp_dir_key = |
107 | 2 | PAIMON_OPTION_PREFIX + DORIS_JNI_IO_MANAGER_TMP_DIR; |
108 | 2 | auto enable_io_manager_it = params.find(enable_io_manager_key); |
109 | 2 | if (enable_io_manager_it != params.end() && |
110 | 2 | iequal(enable_io_manager_it->second, "true") && |
111 | 2 | params.find(io_manager_tmp_dir_key) == params.end()) { |
112 | 0 | std::vector<std::string> tmp_dirs; |
113 | 0 | for (const auto& store_path : state->exec_env()->store_paths()) { |
114 | 0 | tmp_dirs.push_back(store_path.path + "/" + |
115 | 0 | std::string(PAIMON_JNI_SCANNER_IO_TMP_DIR)); |
116 | 0 | } |
117 | 0 | DORIS_CHECK(!tmp_dirs.empty()); |
118 | | // Paimon's IOManager creates and later removes its own paimon-* child |
119 | | // directory under these Doris storage-root scoped parent directories. |
120 | 0 | params[io_manager_tmp_dir_key] = join(tmp_dirs, ":"); |
121 | 0 | } |
122 | 2 | if (range_params->__isset.properties && !range_params->properties.empty()) { |
123 | 0 | for (const auto& kv : range_params->properties) { |
124 | 0 | params[HADOOP_OPTION_PREFIX + kv.first] = kv.second; |
125 | 0 | } |
126 | 2 | } else if (paimon_params.__isset.hadoop_conf) { |
127 | 0 | for (const auto& kv : paimon_params.hadoop_conf) { |
128 | 0 | params[HADOOP_OPTION_PREFIX + kv.first] = kv.second; |
129 | 0 | } |
130 | 0 | } |
131 | 2 | return params; |
132 | 2 | }(), |
133 | 2 | [&]() { |
134 | 2 | std::vector<std::string> names; |
135 | 2 | for (const auto& desc : file_slot_descs) { |
136 | 0 | names.emplace_back(desc->col_name()); |
137 | 0 | } |
138 | 2 | return names; |
139 | 2 | }(), |
140 | 2 | range.__isset.self_split_weight ? range.self_split_weight : -1) { |
141 | 2 | if (range.table_format_params.__isset.table_level_row_count) { |
142 | 2 | _remaining_table_level_row_count = range.table_format_params.table_level_row_count; |
143 | 2 | } else { |
144 | 0 | _remaining_table_level_row_count = -1; |
145 | 0 | } |
146 | 2 | } |
147 | | |
148 | 0 | Status PaimonJniReader::_do_get_next_block(Block* block, size_t* read_rows, bool* eof) { |
149 | 0 | if (_push_down_agg_type == TPushAggOp::type::COUNT && _remaining_table_level_row_count >= 0) { |
150 | 0 | auto rows = std::min(_remaining_table_level_row_count, |
151 | 0 | (int64_t)_state->query_options().batch_size); |
152 | 0 | _remaining_table_level_row_count -= rows; |
153 | 0 | auto mutable_columns_guard = block->mutate_columns_scoped(); |
154 | 0 | auto& mutate_columns = mutable_columns_guard.mutable_columns(); |
155 | 0 | for (auto& col : mutate_columns) { |
156 | 0 | col->resize(rows); |
157 | 0 | } |
158 | 0 | *read_rows = rows; |
159 | 0 | if (_remaining_table_level_row_count == 0) { |
160 | 0 | *eof = true; |
161 | 0 | } |
162 | |
|
163 | 0 | return Status::OK(); |
164 | 0 | } |
165 | 0 | return JniReader::_do_get_next_block(block, read_rows, eof); |
166 | 0 | } |
167 | | |
168 | 0 | Status PaimonJniReader::init_reader() { |
169 | 0 | return open(_state, _profile); |
170 | 0 | } |
171 | | } // namespace doris |