Skip to content

Commit a23c2c7

Browse files
authored
apacheGH-38211: [MATLAB] Add support for creating an empty arrow.tabular.RecordBatch by calling arrow.recordBatch with no input arguments (apache#47060)
### Rationale for this change Currently, the `arrow.table` construction function will return an empty `arrow.tabular.Table` if no input arguments are passed to the function. However, `arrow.recordBatch` throws an error in this case. We should consider making `arrow.recordBatch` behave consistently with `arrow.table` in this case. This should be relatively straightforward to implement. We can just set the input argument `T` to default to `table.empty(0,0)` in the `arguments` block of the `recordBatch` function, in the same way that `arrow.table` does: https://github.com/apache/arrow/blob/73454b7040fbea3a187c1bfabd7ea02d46ca3c41/matlab/src/matlab/%2Barrow/table.m#L21 ### What changes are included in this PR? Updated the `arrow.recordBatch` function to return an `arrow.tabular.RecordBatch` instance with zero columns and zero rows if called with zero input arguments. Before this change, the `arrow.recordBatch` function would throw an error if called with zero input arguments. **Example Usage:** ```matlab >> rb = arrow.recordBatch() rb = Arrow RecordBatch with 0 rows and 0 columns ``` ### Are these changes tested? Yes. Added a new test case to `tRecordBatch` called `ConvenienceConstructorZeroArguments`. ### Are there any user-facing changes? Yes. Users can now call `arrow.recordBatch` with zero input arguments. * GitHub Issue: apache#38211 Authored-by: Sarah Gilmore <[email protected]> Signed-off-by: Sarah Gilmore <[email protected]>
1 parent 8b23360 commit a23c2c7

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

matlab/src/matlab/+arrow/recordBatch.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
% permissions and limitations under the License.
1717
function rb = recordBatch(T)
1818
arguments
19-
T table
19+
T table = table.empty(0, 0)
2020
end
2121

2222
arrowArrays = arrow.tabular.internal.decompose(T);

matlab/test/arrow/tabular/tRecordBatch.m

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,17 @@ function Basic(tc)
2525
tc.verifyEqual(className, "arrow.tabular.RecordBatch");
2626
end
2727

28+
function ConvenienceConstructorZeroArguments(tc)
29+
% Verify the arrow.recordBatch function returns an
30+
% arrow.tabular.RecordBatch instance with zero rows and zero
31+
% columns if called with zero input arguments.
32+
recordBatch = arrow.recordBatch();
33+
className = string(class(recordBatch));
34+
tc.verifyEqual(className, "arrow.tabular.RecordBatch");
35+
tc.verifyEqual(recordBatch.NumRows, int64(0));
36+
tc.verifyEqual(recordBatch.NumColumns, int32(0));
37+
end
38+
2839
function SupportedTypes(tc)
2940
% Create a table all supported MATLAB types.
3041
import arrow.internal.test.tabular.createTableWithSupportedTypes

0 commit comments

Comments
 (0)