Skip to content

Commit

Permalink
Fix linting errors from CI.
Browse files Browse the repository at this point in the history
  • Loading branch information
kevingurney committed Jan 15, 2025
1 parent a0b58c3 commit 2c9de9b
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 34 deletions.
3 changes: 2 additions & 1 deletion matlab/src/cpp/arrow/matlab/error/error.h
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,8 @@ static const char* IPC_RECORD_BATCH_WRITE_FAILED =
static const char* IPC_RECORD_BATCH_WRITE_CLOSE_FAILED = "arrow:io:ipc:CloseFailed";
static const char* IPC_RECORD_BATCH_READER_OPEN_FAILED =
"arrow:io:ipc:FailedToOpenRecordBatchReader";
static const char* IPC_RECORD_BATCH_READER_INVALID_CONSTRUCTION_TYPE = "arrow:io:ipc:InvalidConstructionType";
static const char* IPC_RECORD_BATCH_READER_INVALID_CONSTRUCTION_TYPE =
"arrow:io:ipc:InvalidConstructionType";
static const char* IPC_RECORD_BATCH_READ_INVALID_INDEX = "arrow:io:ipc:InvalidIndex";
static const char* IPC_RECORD_BATCH_READ_FAILED = "arrow:io:ipc:ReadFailed";
static const char* IPC_TABLE_READ_FAILED = "arrow:io:ipc:TableReadFailed";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@
// specific language governing permissions and limitations
// under the License.

#include "arrow/matlab/buffer/matlab_buffer.h"
#include "arrow/matlab/io/ipc/proxy/record_batch_stream_reader.h"
#include "arrow/io/file.h"
#include "arrow/io/memory.h"
#include "arrow/matlab/buffer/matlab_buffer.h"
#include "arrow/matlab/error/error.h"
#include "arrow/matlab/tabular/proxy/record_batch.h"
#include "arrow/matlab/tabular/proxy/schema.h"
Expand All @@ -38,58 +38,63 @@ RecordBatchStreamReader::RecordBatchStreamReader(
REGISTER_METHOD(RecordBatchStreamReader, readTable);
}

libmexclass::proxy::MakeResult RecordBatchStreamReader::fromFile(const libmexclass::proxy::FunctionArguments& constructor_arguments) {
namespace mda = ::matlab::data;
using RecordBatchStreamReaderProxy =
libmexclass::proxy::MakeResult RecordBatchStreamReader::fromFile(
const libmexclass::proxy::FunctionArguments& constructor_arguments) {
namespace mda = ::matlab::data;
using RecordBatchStreamReaderProxy =
arrow::matlab::io::ipc::proxy::RecordBatchStreamReader;

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::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);

MATLAB_ASSIGN_OR_ERROR(auto input_stream, arrow::io::ReadableFile::Open(filename_utf8),
error::FAILED_TO_OPEN_FILE_FOR_READ);
MATLAB_ASSIGN_OR_ERROR(auto input_stream, arrow::io::ReadableFile::Open(filename_utf8),
error::FAILED_TO_OPEN_FILE_FOR_READ);

MATLAB_ASSIGN_OR_ERROR(auto reader,
arrow::ipc::RecordBatchStreamReader::Open(input_stream),
error::IPC_RECORD_BATCH_READER_OPEN_FAILED);
MATLAB_ASSIGN_OR_ERROR(auto reader,
arrow::ipc::RecordBatchStreamReader::Open(input_stream),
error::IPC_RECORD_BATCH_READER_OPEN_FAILED);

return std::make_shared<RecordBatchStreamReaderProxy>(std::move(reader));
return std::make_shared<RecordBatchStreamReaderProxy>(std::move(reader));
}

libmexclass::proxy::MakeResult RecordBatchStreamReader::fromBytes(const libmexclass::proxy::FunctionArguments& constructor_arguments) {
namespace mda = ::matlab::data;
using RecordBatchStreamReaderProxy =
arrow::matlab::io::ipc::proxy::RecordBatchStreamReader;

const mda::StructArray opts = constructor_arguments[0];
const ::matlab::data::TypedArray<uint8_t> bytes_mda = opts[0]["Bytes"];
const auto matlab_buffer = std::make_shared<arrow::matlab::buffer::MatlabBuffer>(bytes_mda);
auto buffer_reader = std::make_shared<arrow::io::BufferReader>(matlab_buffer);
MATLAB_ASSIGN_OR_ERROR(auto reader,
arrow::ipc::RecordBatchStreamReader::Open(buffer_reader),
error::IPC_RECORD_BATCH_READER_OPEN_FAILED);
return std::make_shared<RecordBatchStreamReaderProxy>(std::move(reader));
libmexclass::proxy::MakeResult RecordBatchStreamReader::fromBytes(
const libmexclass::proxy::FunctionArguments& constructor_arguments) {
namespace mda = ::matlab::data;
using RecordBatchStreamReaderProxy =
arrow::matlab::io::ipc::proxy::RecordBatchStreamReader;

const mda::StructArray opts = constructor_arguments[0];
const ::matlab::data::TypedArray<uint8_t> bytes_mda = opts[0]["Bytes"];
const auto matlab_buffer =
std::make_shared<arrow::matlab::buffer::MatlabBuffer>(bytes_mda);
auto buffer_reader = std::make_shared<arrow::io::BufferReader>(matlab_buffer);
MATLAB_ASSIGN_OR_ERROR(auto reader,
arrow::ipc::RecordBatchStreamReader::Open(buffer_reader),
error::IPC_RECORD_BATCH_READER_OPEN_FAILED);
return std::make_shared<RecordBatchStreamReaderProxy>(std::move(reader));
}

libmexclass::proxy::MakeResult RecordBatchStreamReader::make(
const libmexclass::proxy::FunctionArguments& constructor_arguments) {
namespace mda = ::matlab::data;
namespace mda = ::matlab::data;
const mda::StructArray opts = constructor_arguments[0];

// Dispatch to the appropriate static "make" method depending
// on the input type.
const mda::StringArray type_mda = opts[0]["Type"];
const auto type_utf16 = std::u16string(type_mda[0]);
if (type_utf16 == u"Bytes") {
return RecordBatchStreamReader::fromBytes(constructor_arguments);
return RecordBatchStreamReader::fromBytes(constructor_arguments);
} else if (type_utf16 == u"File") {
return RecordBatchStreamReader::fromFile(constructor_arguments);
return RecordBatchStreamReader::fromFile(constructor_arguments);
} else {
return libmexclass::error::Error{"arrow:io:ipc:InvalidConstructionType", "Invalid construction type for RecordBatchStreamReader."};
return libmexclass::error::Error{
"arrow:io:ipc:InvalidConstructionType",
"Invalid construction type for RecordBatchStreamReader."};
}
}

Expand Down

0 comments on commit 2c9de9b

Please sign in to comment.