Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GH-37996: [MATLAB] Add a static constructor method named fromMATLAB to arrow.array.StructArray #37998

Merged
merged 7 commits into from
Oct 3, 2023

Conversation

sgilmore10
Copy link
Member

@sgilmore10 sgilmore10 commented Oct 3, 2023

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.

>> 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 StructArrays from MATLAB tables by either calling arrow.array.StructArray.fromMATLAB() or by passing a table to arrow.array():

>> 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 StructArrays directly from MATLAB tables by calling either arrow.array() or arrow.array.StructArray.fromMATLAB.

Copy link
Member

@kevingurney kevingurney left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for making this change!

matlab/test/arrow/array/tStructArray.m Outdated Show resolved Hide resolved
matlab/test/arrow/array/tStructArray.m Outdated Show resolved Hide resolved
matlab/test/arrow/array/tStructArray.m Outdated Show resolved Hide resolved
@github-actions github-actions bot added awaiting changes Awaiting changes and removed awaiting review Awaiting review labels Oct 3, 2023
@github-actions github-actions bot added awaiting change review Awaiting change review and removed awaiting changes Awaiting changes labels Oct 3, 2023
@github-actions github-actions bot added awaiting merge Awaiting merge and removed awaiting change review Awaiting change review labels Oct 3, 2023
@kevingurney
Copy link
Member

+1

@kevingurney kevingurney merged commit 081e354 into apache:main Oct 3, 2023
9 of 10 checks passed
@kevingurney kevingurney deleted the GH-37996 branch October 3, 2023 20:35
@kevingurney kevingurney removed the awaiting merge Awaiting merge label Oct 3, 2023
@conbench-apache-arrow
Copy link

After merging your PR, Conbench analyzed the 5 benchmarking runs that have been run so far on merge-commit 081e354.

There were no benchmark performance regressions. 🎉

The full Conbench report has more details. It also includes information about 1 possible false positive for unstable benchmarks that are known to sometimes produce them.

JerAguilon pushed a commit to JerAguilon/arrow that referenced this pull request Oct 23, 2023
…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 <sgilmore@mathworks.com>
Signed-off-by: Kevin Gurney <kgurney@mathworks.com>
loicalleyne pushed a commit to loicalleyne/arrow that referenced this pull request Nov 13, 2023
…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 <sgilmore@mathworks.com>
Signed-off-by: Kevin Gurney <kgurney@mathworks.com>
dgreiss pushed a commit to dgreiss/arrow that referenced this pull request Feb 19, 2024
…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 <sgilmore@mathworks.com>
Signed-off-by: Kevin Gurney <kgurney@mathworks.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[MATLAB] Add a static constructor method named fromMATLAB to arrow.array.StructArray
2 participants