Skip to content

Commit

Permalink
Add source file for RecordBatchImporter
Browse files Browse the repository at this point in the history
  • Loading branch information
sgilmore10 committed May 23, 2024
1 parent 7e7d5c3 commit e7eedbe
Showing 1 changed file with 64 additions and 0 deletions.
64 changes: 64 additions & 0 deletions matlab/src/cpp/arrow/matlab/c/proxy/record_batch_importer.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.

#include "arrow/record_batch.h"
#include "arrow/c/bridge.h"

#include "arrow/matlab/c/proxy/record_batch.h"
#include "arrow/matlab/error/error.h"

#include "libmexclass/proxy/ProxyManager.h"
#include "record_batch_importer.h"

namespace arrow::matlab::c::proxy {

RecordBatchImporter::RecordBatchImporter() { REGISTER_METHOD(RecordBatchImporter, import); }

libmexclass::proxy::MakeResult RecordBatchImporter::make(
const libmexclass::proxy::FunctionArguments& constructor_arguments) {
return std::make_shared<RecordBatchImporter>();
}

void RecordBatchImporter::import(libmexclass::proxy::method::Context& context) {
namespace mda = ::matlab::data;
using namespace libmexclass::proxy;

mda::StructArray args = context.inputs[0];
const mda::TypedArray<uint64_t> arrow_array_address_mda = args[0]["ArrowArrayAddress"];
const mda::TypedArray<uint64_t> arrow_schema_address_mda =
args[0]["ArrowSchemaAddress"];

const auto arrow_array_address = uint64_t(arrow_array_address_mda[0]);
const auto arrow_schema_address = uint64_t(arrow_schema_address_mda[0]);

auto arrow_array = reinterpret_cast<struct ArrowArray*>(arrow_array_address);
auto arrow_schema = reinterpret_cast<struct ArrowSchema*>(arrow_schema_address);

MATLAB_ASSIGN_OR_ERROR_WITH_CONTEXT(auto record_batch,
arrow::ImportREcordBatch(arrow_array, arrow_schema),
context, error::C_IMPORT_FAILED);

auto record_batch_proxy = arrow::matlab::tabular::proxy::RecordBatch(std::move(record_batch_proxy));

mda::ArrayFactory factory;
const auto record_batch_proxy_id = ProxyManager::manageProxy(record_batch_proxy);
const auto record_batch_proxy_id_mda = factory.createScalar(record_batch_proxy_id);

context.outputs[0] = record_batch_proxy_id_mda;
}

} // namespace arrow::matlab::c::proxy

0 comments on commit e7eedbe

Please sign in to comment.