forked from apache/arrow
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add RecordBatchStreamWriter Proxy class
- Loading branch information
1 parent
1160fa7
commit 81f64f7
Showing
2 changed files
with
99 additions
and
0 deletions.
There are no files selected for viewing
63 changes: 63 additions & 0 deletions
63
matlab/src/cpp/arrow/matlab/io/ipc/proxy/record_batch_stream_writer.cc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
// 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/io/file.h" | ||
#include "arrow/ipc/writer.h" | ||
#include "arrow/matlab/error/error.h" | ||
#include "arrow/matlab/io/ipc/proxy/record_batch_file_writer.h" | ||
#include "arrow/matlab/tabular/proxy/schema.h" | ||
#include "arrow/util/utf8.h" | ||
|
||
#include "libmexclass/proxy/ProxyManager.h" | ||
|
||
namespace arrow::matlab::io::ipc::proxy { | ||
|
||
RecordBatchStreamWriter::RecordBatchStreamWriter( | ||
const std::shared_ptr<arrow::ipc::RecordBatchWriter> writer) | ||
: RecordBatchWriter(std::move(writer)) {} | ||
|
||
libmexclass::proxy::MakeResult RecordBatchStreamWriter::make( | ||
const libmexclass::proxy::FunctionArguments& constructor_arguments) { | ||
namespace mda = ::matlab::data; | ||
using RecordBatchStreamWriterProxy = arrow::matlab::io::ipc::proxy::RecordBatchStreamWriter; | ||
using SchemaProxy = arrow::matlab::tabular::proxy::Schema; | ||
|
||
const mda::StructArray opts = constructor_arguments[0]; | ||
|
||
const mda::StringArray filename_mda = opts[0]["Filename"]; | ||
const auto filename_utf16 = std::u16string(filename_mda[0]); | ||
MATLAB_ASSIGN_OR_ERROR(const auto filename_utf8, | ||
arrow::util::UTF16StringToUTF8(filename_utf16), | ||
error::UNICODE_CONVERSION_ERROR_ID); | ||
|
||
const mda::TypedArray<uint64_t> arrow_schema_proxy_id_mda = opts[0]["SchemaProxyID"]; | ||
auto proxy = libmexclass::proxy::ProxyManager::getProxy(arrow_schema_proxy_id_mda[0]); | ||
auto arrow_schema_proxy = std::static_pointer_cast<SchemaProxy>(proxy); | ||
auto arrow_schema = arrow_schema_proxy->unwrap(); | ||
|
||
MATLAB_ASSIGN_OR_ERROR(auto output_stream, | ||
arrow::io::FileOutputStream::Open(filename_utf8), | ||
error::FAILED_TO_OPEN_FILE_FOR_WRITE); | ||
|
||
MATLAB_ASSIGN_OR_ERROR(auto writer, | ||
arrow::ipc::MakeStreamWriter(output_stream, arrow_schema), | ||
"arrow:matlab:MakeFailed"); | ||
|
||
return std::make_shared<RecordBatchStreamWriterProxy>(std::move(writer)); | ||
} | ||
|
||
} // namespace arrow::matlab::io::ipc::proxy |
36 changes: 36 additions & 0 deletions
36
matlab/src/cpp/arrow/matlab/io/ipc/proxy/record_batch_stream_writer.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
// 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/ipc/writer.h" | ||
#include "arrow/matlab/io/ipc/proxy/record_batch_writer.h" | ||
|
||
#include "libmexclass/proxy/Proxy.h" | ||
|
||
namespace arrow::matlab::io::ipc::proxy { | ||
|
||
class RecordBatchStreamWriter : public RecordBatchWriter { | ||
public: | ||
RecordBatchStreamWriter(std::shared_ptr<arrow::ipc::RecordBatchWriter> writer); | ||
|
||
virtual ~RecordBatchStreamWriter() = default; | ||
|
||
static libmexclass::proxy::MakeResult make( | ||
const libmexclass::proxy::FunctionArguments& constructor_arguments); | ||
|
||
}; | ||
|
||
} // namespace arrow::matlab::io::ipc::proxy |