|
| 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 "lakesoul_jni_reader.h" |
| 19 | + |
| 20 | +#include <map> |
| 21 | +#include <ostream> |
| 22 | + |
| 23 | +#include "common/logging.h" |
| 24 | +#include "runtime/descriptors.h" |
| 25 | +#include "runtime/runtime_state.h" |
| 26 | +#include "runtime/types.h" |
| 27 | +#include "vec/core/types.h" |
| 28 | + |
| 29 | +namespace doris { |
| 30 | +class RuntimeProfile; |
| 31 | +class RuntimeState; |
| 32 | + |
| 33 | +namespace vectorized { |
| 34 | +class Block; |
| 35 | +} // namespace vectorized |
| 36 | +} // namespace doris |
| 37 | + |
| 38 | +namespace doris::vectorized { |
| 39 | +LakeSoulJniReader::LakeSoulJniReader(const TLakeSoulFileDesc& lakesoul_params, |
| 40 | + const std::vector<SlotDescriptor*>& file_slot_descs, |
| 41 | + RuntimeState* state, RuntimeProfile* profile) |
| 42 | + : _lakesoul_params(lakesoul_params), |
| 43 | + _file_slot_descs(file_slot_descs), |
| 44 | + _state(state), |
| 45 | + _profile(profile) { |
| 46 | + std::vector<std::string> required_fields; |
| 47 | + for (auto& desc : _file_slot_descs) { |
| 48 | + required_fields.emplace_back(desc->col_name()); |
| 49 | + } |
| 50 | + |
| 51 | + std::map<String, String> params = { |
| 52 | + {"query_id", print_id(_state->query_id())}, |
| 53 | + {"file_paths", join(_lakesoul_params.file_paths, ";")}, |
| 54 | + {"primary_keys", join(_lakesoul_params.primary_keys, ";")}, |
| 55 | + {"partition_descs", join(_lakesoul_params.partition_descs, ";")}, |
| 56 | + {"required_fields", join(required_fields, ";")}, |
| 57 | + {"options", _lakesoul_params.options}, |
| 58 | + {"table_schema", _lakesoul_params.table_schema}, |
| 59 | + }; |
| 60 | + _jni_connector = std::make_unique<JniConnector>("org/apache/doris/lakesoul/LakeSoulJniScanner", |
| 61 | + params, required_fields); |
| 62 | +} |
| 63 | + |
| 64 | +Status LakeSoulJniReader::get_next_block(Block* block, size_t* read_rows, bool* eof) { |
| 65 | + RETURN_IF_ERROR(_jni_connector->get_next_block(block, read_rows, eof)); |
| 66 | + if (*eof) { |
| 67 | + RETURN_IF_ERROR(_jni_connector->close()); |
| 68 | + } |
| 69 | + return Status::OK(); |
| 70 | +} |
| 71 | + |
| 72 | +Status LakeSoulJniReader::get_columns(std::unordered_map<std::string, TypeDescriptor>* name_to_type, |
| 73 | + std::unordered_set<std::string>* missing_cols) { |
| 74 | + for (auto& desc : _file_slot_descs) { |
| 75 | + name_to_type->emplace(desc->col_name(), desc->type()); |
| 76 | + } |
| 77 | + return Status::OK(); |
| 78 | +} |
| 79 | + |
| 80 | +Status LakeSoulJniReader::init_reader( |
| 81 | + std::unordered_map<std::string, ColumnValueRangeType>* colname_to_value_range) { |
| 82 | + _colname_to_value_range = colname_to_value_range; |
| 83 | + RETURN_IF_ERROR(_jni_connector->init(colname_to_value_range)); |
| 84 | + return _jni_connector->open(_state, _profile); |
| 85 | +} |
| 86 | +} // namespace doris::vectorized |
0 commit comments