Skip to content

Commit

Permalink
Add test which verifies that an error is thrown if provided with a fi…
Browse files Browse the repository at this point in the history
…le that is not an Arrow IPC Stream file.
  • Loading branch information
kevingurney committed Dec 6, 2024
1 parent 432eae8 commit c2a9d2e
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion matlab/test/arrow/io/ipc/tRecordBatchStreamReader.m
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
ZeroBatchStreamFile
OneBatchStreamFile
MultipleBatchStreamFile
RandomAccessFile
end

properties (TestParameter)
Expand All @@ -35,6 +36,16 @@ function setupDataFolder(testCase)
testCase.DataFolder = string(fixture.Folder);
end

function setupRandomAccessFile(testCase)
fieldA = arrow.field("A", arrow.string());
fieldB = arrow.field("B", arrow.float32());
schema = arrow.schema([fieldA, fieldB]);
fname = fullfile(testCase.DataFolder, "RandomAccessFile.arrow");
writer = arrow.io.ipc.RecordBatchFileWriter(fname, schema);
writer.close();
testCase.RandomAccessFile = fname;
end

function setupZeroBatchStreamFile(testCase)
fieldA = arrow.field("A", arrow.string());
fieldB = arrow.field("B", arrow.float32());
Expand Down Expand Up @@ -249,7 +260,7 @@ function ReadTableOneBatchStreamFile(testCase)

function ReadTableMultipleBatchStreamFile(testCase)
% Verify read can successfully read an Arrow IPC Stream file
% containing one batch as an arrow.tabular.Table.
% containing multiple batches as an arrow.tabular.Table.
reader = arrow.io.ipc.RecordBatchStreamReader(testCase.MultipleBatchStreamFile);
matlabTable = table(["Row1"; "Row2"; "Row3"; "Row4"], single([1; 2; 3; 4]), VariableNames=["A", "B"]);
expected = arrow.table(matlabTable);
Expand Down Expand Up @@ -312,6 +323,14 @@ function ReadTableMultipleCalls(testCase)
testCase.verifyTrue(reader.done());
end

function ErrorIfNotIpcStreamFile(testCase)
% Verify RecordBatchStreamReader throws an exception with the
% identifier arrow:io:ipc:FailedToOpenRecordBatchReader if
% the provided file is not an Arrow IPC Stream file.
fcn = @() arrow.io.ipc.RecordBatchStreamReader(testCase.RandomAccessFile);
testCase.verifyError(fcn, "arrow:io:ipc:FailedToOpenRecordBatchReader");
end

end

end

0 comments on commit c2a9d2e

Please sign in to comment.