Skip to content

Commit c2a9d2e

Browse files
committed
Add test which verifies that an error is thrown if provided with a file that is not an Arrow IPC Stream file.
1 parent 432eae8 commit c2a9d2e

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

matlab/test/arrow/io/ipc/tRecordBatchStreamReader.m

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
ZeroBatchStreamFile
2222
OneBatchStreamFile
2323
MultipleBatchStreamFile
24+
RandomAccessFile
2425
end
2526

2627
properties (TestParameter)
@@ -35,6 +36,16 @@ function setupDataFolder(testCase)
3536
testCase.DataFolder = string(fixture.Folder);
3637
end
3738

39+
function setupRandomAccessFile(testCase)
40+
fieldA = arrow.field("A", arrow.string());
41+
fieldB = arrow.field("B", arrow.float32());
42+
schema = arrow.schema([fieldA, fieldB]);
43+
fname = fullfile(testCase.DataFolder, "RandomAccessFile.arrow");
44+
writer = arrow.io.ipc.RecordBatchFileWriter(fname, schema);
45+
writer.close();
46+
testCase.RandomAccessFile = fname;
47+
end
48+
3849
function setupZeroBatchStreamFile(testCase)
3950
fieldA = arrow.field("A", arrow.string());
4051
fieldB = arrow.field("B", arrow.float32());
@@ -249,7 +260,7 @@ function ReadTableOneBatchStreamFile(testCase)
249260

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

326+
function ErrorIfNotIpcStreamFile(testCase)
327+
% Verify RecordBatchStreamReader throws an exception with the
328+
% identifier arrow:io:ipc:FailedToOpenRecordBatchReader if
329+
% the provided file is not an Arrow IPC Stream file.
330+
fcn = @() arrow.io.ipc.RecordBatchStreamReader(testCase.RandomAccessFile);
331+
testCase.verifyError(fcn, "arrow:io:ipc:FailedToOpenRecordBatchReader");
332+
end
333+
315334
end
316335

317336
end

0 commit comments

Comments
 (0)