1
+ % TRECORDBATCHFILEWRITER Unit tests for arrow.io.ipc.RecordBatchFileWriter.
2
+
3
+ % Licensed to the Apache Software Foundation (ASF) under one or more
4
+ % contributor license agreements. See the NOTICE file distributed with
5
+ % this work for additional information regarding copyright ownership.
6
+ % The ASF licenses this file to you under the Apache License, Version
7
+ % 2.0 (the "License"); you may not use this file except in compliance
8
+ % with the License. You may obtain a copy of the License at
9
+ %
10
+ % http://www.apache.org/licenses/LICENSE-2.0
11
+ %
12
+ % Unless required by applicable law or agreed to in writing, software
13
+ % distributed under the License is distributed on an "AS IS" BASIS,
14
+ % WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
15
+ % implied. See the License for the specific language governing
16
+ % permissions and limitations under the License.
17
+
18
+ classdef tRecordBatchFileWriter < matlab .unittest .TestCase
19
+
20
+ methods
21
+ function folder = setupTemporaryFolder(testCase )
22
+ import matlab .unittest .fixtures .TemporaryFolderFixture
23
+ fixture = testCase .applyFixture(TemporaryFolderFixture );
24
+ folder = string(fixture .Folder );
25
+ end
26
+ end
27
+
28
+ methods (Test )
29
+ function ZeroLengthFilenameError(testCase )
30
+ schema = arrow .schema(arrow .field(" A" , arrow .float64()));
31
+ fcn = @() arrow .io .ipc .RecordBatchFileWriter(" " , schema );
32
+ testCase .verifyError(fcn , " MATLAB:validators:mustBeNonzeroLengthText" );
33
+ end
34
+
35
+ function MissingStringFilenameError(testCase )
36
+ schema = arrow .schema(arrow .field(" A" , arrow .float64()));
37
+ fcn = @() arrow .io .ipc .RecordBatchFileWriter(string(missing ), schema );
38
+ testCase .verifyError(fcn , " MATLAB:validators:mustBeNonzeroLengthText" );
39
+ end
40
+
41
+ function FilenameInvalidTypeError(testCase )
42
+ schema = arrow .schema(arrow .field(" A" , arrow .float64()));
43
+ fcn = @() arrow .io .ipc .RecordBatchFileWriter(table , schema );
44
+ testCase .verifyError(fcn , " MATLAB:validation:UnableToConvert" );
45
+ end
46
+
47
+ function InvalidSchemaType(testCase )
48
+ folder = testCase .setupTemporaryFolder();
49
+ fname = fullfile(folder , " data.arrow" );
50
+ schema = arrow .field(" A" , arrow .float64());
51
+ fcn = @() arrow .io .ipc .RecordBatchFileWriter(fname , schema );
52
+ testCase .verifyError(fcn , " MATLAB:validation:UnableToConvert" );
53
+ end
54
+
55
+ function writeRecordBatchInvalidType(testCase )
56
+ folder = testCase .setupTemporaryFolder();
57
+ fname = fullfile(folder , " data.arrow" );
58
+ schema = arrow .schema(arrow .field(" A" , arrow .float64()));
59
+ writer = arrow .io .ipc .RecordBatchFileWriter(fname , schema );
60
+ arrowTable = arrow .table(table([1 2 3 4 ]' , VariableNames= " A" ));
61
+ fcn = @() writer .writeRecordBatch(arrowTable );
62
+ testCase .verifyError(fcn , " MATLAB:validation:UnableToConvert" );
63
+ end
64
+
65
+ function writeTableInvalidType(testCase )
66
+ folder = testCase .setupTemporaryFolder();
67
+ fname = fullfile(folder , " data.arrow" );
68
+ schema = arrow .schema(arrow .field(" A" , arrow .float64()));
69
+ writer = arrow .io .ipc .RecordBatchFileWriter(fname , schema );
70
+ arrowRecordBatch = arrow .recordBatch(table([1 2 3 4 ]' , VariableNames= " A" ));
71
+ fcn = @() writer .writeTable(arrowRecordBatch );
72
+ testCase .verifyError(fcn , " MATLAB:validation:UnableToConvert" );
73
+ end
74
+
75
+ function writeInvalidType(testCase )
76
+ folder = testCase .setupTemporaryFolder();
77
+ fname = fullfile(folder , " data.arrow" );
78
+ schema = arrow .schema(arrow .field(" A" , arrow .float64()));
79
+ writer = arrow .io .ipc .RecordBatchFileWriter(fname , schema );
80
+ fcn = @() writer .write(schema );
81
+ testCase .verifyError(fcn , " arrow:matlab:ipc:write:InvalidType" );
82
+ end
83
+ end
84
+ end
0 commit comments