forked from apache/arrow
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
apacheGH-37996: [MATLAB] Add a static constructor method named `fromM…
…ATLAB` to `arrow.array.StructArray` (apache#37998) ### Rationale for this change Right now, the only way to construct an `arrow.array.StructArray` is to call its static method `fromArrays` method. Doing so requires users to first construct the individual field arrays before creating the `StructArray`. ```matlab >> a1 = arrow.array([1 2 3 4]); >> a2 = arrow.array(["A" "B" "C" "D"]); >> s1 = arrow.array.StructArray.fromArrays(a1, a2, FieldNames=["Number" "String"]); >> class(s1) ans = 'arrow.array.StructArray' ``` It would be nice if users could construct `StructArray`s from MATLAB `table`s by either calling `arrow.array.StructArray.fromMATLAB()` or by passing a `table` to `arrow.array()`: ```matlab >> t = table([1 2 3 4]', ["A1" "A2" "A3" "A4"]', VariableNames=["Number", "String"]) % Call fromMATLAB method >> s1 = arrow.array.StructArray.fromMATLAB(t); >> class(s1) ans = 'arrow.array.StructArray' % Pass table to arrow.array() >> class(s2) ans = 'arrow.array.StructArray' ``` ### What changes are included in this PR? 1. Added static constructor method `fromMATLAB` to `arrow.array.StructArray`. It accepts a `table` as input and optionally two name-value pairs: `FieldNames` and `Valid`. 2. Set the `ArrayStaticConstructor` property of `arrow.type.traits.StructTraits` to `@ arrow.array.StructArray.fromMATLAB`. Previously, it was set to `missing`. 3. Updated `arrow.type.traits.traits(className)` to return `StructTraits` if `className` is the string `"table"`. 4. Updated `arrow.array` to accept a MATLAB `table` as input and return an `arrow.array.StructArray` if given a `table`. 5. Changed the signature of `arrow.array()` to accept `varargin` instead of pre-determined name-value pairs. The name-value pairs accepted depends on the type of array being constructed. For example, you can supply `TimeUnit` when constructing an `arrow.array.TimestampArray`, but `TimeUnit` will not be accepted when creating an `arrow.array.Int8Array`. ### Are these changes tested? Yes. Added new tests cases to `tArray.m`, `tStructArray.m`, `ttraits.m`, and `tStructTraits.m`. ### Are there any user-facing changes? Yes, users can now create `StructArray`s directly from MATLAB `table`s by calling either `arrow.array()` or `arrow.array.StructArray.fromMATLAB`. * Closes: apache#37996 Authored-by: Sarah Gilmore <[email protected]> Signed-off-by: Kevin Gurney <[email protected]>
- Loading branch information
1 parent
45588a7
commit 081e354
Showing
8 changed files
with
154 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters