Commits


sgilmore10 authored and GitHub committed 5c239382223
GH-37175: [MATLAB] Support creating `arrow.tabular.RecordBatch` instances from a list of `arrow.array.Array` values (#37176) ### Rationale for this change Right now, the only way to construct an `arrow.tabular.RecordBatch` is from a MATLAB `table`: ```matlab >> t = table([1; 2; 3], ["A"; "B"; "C"], VariableNames=["Numbers", "Letters"]); t = 3×2 table Numbers Letters _______ _______ 1 "A" 2 "B" 3 "C" >> rb = arrow.recordbatch(t) rb = Numbers: [ 1, 2, 3 ] Letters: [ "A", "B", "C" ] ``` The interface should also support creating `arrow.tabular.RecordBatch` instances from lists of `arrow.array.Array` values. ### What changes are included in this PR? Added a new static method to `arrow.tabular.RecordBatch` called `fromArrays`. This method accepts a comma-separated list of `arrow.array.Array` values which it uses to construct an `arrow.tabular.RecordBatch`. It also accepts an optional name-value pair called `ColumnNames`, which can be used to specify the column names in the record batch. If this name-value pair is not supplied, the column names default to `"Column1"`, `"Column2"`, etc. **Example Usage:** ```matlab >> a1 = arrow.array([1, 2, 3]); >> a2 = arrow.array(["A", "B", "C"]); >> rb1 = arrow.tabular.RecordBatch.fromArrays(a1, a2) rb1 = Column1: [ 1, 2, 3 ] Column2: [ "A", "B", "C" ] >> rb2 = arrow.tabular.RecordBatch.fromArrays(a1, a2, ColumnNames=["Numbers", "Letters"]) rb2 = Numbers: [ 1, 2, 3 ] Letters: [ "A", "B", "C" ] ``` ### Are these changes tested? Yes. 1. Added new test class `arrow/test/tabular/tValidateArrayLengths.m` 2. Added new test class `arrow/test/tabular/tValidateColumnNames.m` 3. Added new test cases to `arrow/test/tabular/tRecordBatch.m` ### Are there any user-facing changes? Yes, users can now create `arrow.tabular.RecordBatch` instances using the static method `arrow.tabular.RecordBatch.fromArrays`. * Closes: #37175 Authored-by: Sarah Gilmore <sgilmore@mathworks.com> Signed-off-by: Kevin Gurney <kgurney@mathworks.com>