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 "format/table/paimon_jni_reader.h" |
19 | | |
20 | | #include <map> |
21 | | |
22 | | #include "core/types.h" |
23 | | #include "runtime/descriptors.h" |
24 | | #include "runtime/runtime_state.h" |
25 | | namespace doris { |
26 | | class RuntimeProfile; |
27 | | class RuntimeState; |
28 | | class Block; |
29 | | } // namespace doris |
30 | | |
31 | | namespace doris { |
32 | | #include "common/compile_check_begin.h" |
33 | | |
34 | | const std::string PaimonJniReader::PAIMON_OPTION_PREFIX = "paimon."; |
35 | | const std::string PaimonJniReader::HADOOP_OPTION_PREFIX = "hadoop."; |
36 | | |
37 | | PaimonJniReader::PaimonJniReader(const std::vector<SlotDescriptor*>& file_slot_descs, |
38 | | RuntimeState* state, RuntimeProfile* profile, |
39 | | const TFileRangeDesc& range, |
40 | | const TFileScanRangeParams* range_params) |
41 | 0 | : JniReader(file_slot_descs, state, profile) { |
42 | 0 | std::vector<std::string> column_names; |
43 | 0 | std::vector<std::string> column_types; |
44 | 0 | for (const auto& desc : _file_slot_descs) { |
45 | 0 | column_names.emplace_back(desc->col_name()); |
46 | 0 | column_types.emplace_back(JniConnector::get_jni_type_with_different_string(desc->type())); |
47 | 0 | } |
48 | 0 | const auto& paimon_params = range.table_format_params.paimon_params; |
49 | 0 | std::map<String, String> params; |
50 | 0 | params["paimon_split"] = paimon_params.paimon_split; |
51 | 0 | if (range_params->__isset.paimon_predicate && !range_params->paimon_predicate.empty()) { |
52 | 0 | params["paimon_predicate"] = range_params->paimon_predicate; |
53 | 0 | } else if (paimon_params.__isset.paimon_predicate) { |
54 | | // Fallback to split level paimon_predicate for backward compatibility |
55 | 0 | params["paimon_predicate"] = paimon_params.paimon_predicate; |
56 | 0 | } |
57 | 0 | params["required_fields"] = join(column_names, ","); |
58 | 0 | params["columns_types"] = join(column_types, "#"); |
59 | 0 | params["time_zone"] = _state->timezone(); |
60 | 0 | if (range_params->__isset.serialized_table) { |
61 | 0 | params["serialized_table"] = range_params->serialized_table; |
62 | 0 | } |
63 | 0 | if (range.table_format_params.__isset.table_level_row_count) { |
64 | 0 | _remaining_table_level_row_count = range.table_format_params.table_level_row_count; |
65 | 0 | } else { |
66 | 0 | _remaining_table_level_row_count = -1; |
67 | 0 | } |
68 | | |
69 | | // Used to create paimon option |
70 | 0 | for (const auto& kv : paimon_params.paimon_options) { |
71 | 0 | params[PAIMON_OPTION_PREFIX + kv.first] = kv.second; |
72 | 0 | } |
73 | | // Prefer hadoop conf from scan node level (range_params->properties) over split level |
74 | | // to avoid redundant configuration in each split |
75 | 0 | if (range_params->__isset.properties && !range_params->properties.empty()) { |
76 | 0 | for (const auto& kv : range_params->properties) { |
77 | 0 | params[HADOOP_OPTION_PREFIX + kv.first] = kv.second; |
78 | 0 | } |
79 | 0 | } else if (paimon_params.__isset.hadoop_conf) { |
80 | | // Fallback to split level hadoop conf for backward compatibility |
81 | 0 | for (const auto& kv : paimon_params.hadoop_conf) { |
82 | 0 | params[HADOOP_OPTION_PREFIX + kv.first] = kv.second; |
83 | 0 | } |
84 | 0 | } |
85 | 0 | int64_t self_split_weight = range.__isset.self_split_weight ? range.self_split_weight : -1; |
86 | 0 | _jni_connector = std::make_unique<JniConnector>("org/apache/doris/paimon/PaimonJniScanner", |
87 | 0 | params, column_names, self_split_weight); |
88 | 0 | } |
89 | | |
90 | 0 | Status PaimonJniReader::get_next_block(Block* block, size_t* read_rows, bool* eof) { |
91 | 0 | if (_push_down_agg_type == TPushAggOp::type::COUNT && _remaining_table_level_row_count >= 0) { |
92 | 0 | auto rows = std::min(_remaining_table_level_row_count, |
93 | 0 | (int64_t)_state->query_options().batch_size); |
94 | 0 | _remaining_table_level_row_count -= rows; |
95 | 0 | auto mutate_columns = block->mutate_columns(); |
96 | 0 | for (auto& col : mutate_columns) { |
97 | 0 | col->resize(rows); |
98 | 0 | } |
99 | 0 | block->set_columns(std::move(mutate_columns)); |
100 | 0 | *read_rows = rows; |
101 | 0 | if (_remaining_table_level_row_count == 0) { |
102 | 0 | *eof = true; |
103 | 0 | } |
104 | |
|
105 | 0 | return Status::OK(); |
106 | 0 | } |
107 | 0 | return _jni_connector->get_next_block(block, read_rows, eof); |
108 | 0 | } |
109 | | |
110 | 0 | Status PaimonJniReader::init_reader() { |
111 | 0 | RETURN_IF_ERROR(_jni_connector->init()); |
112 | 0 | return _jni_connector->open(_state, _profile); |
113 | 0 | } |
114 | | #include "common/compile_check_end.h" |
115 | | } // namespace doris |