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