kevingurney opened a new pull request, #36653: URL: https://github.com/apache/arrow/pull/36653
### Rationale for this change To make it easier to write generic code for `arrow.array.Array` and associated objects in the MATLAB interface, it would be helpful to have some kind of ["type traits"-like](https://github.com/apache/arrow/blob/d676078c13a02ad920eeea2acd5fa517f14526e2/cpp/src/arrow/type_traits.h#L105) objects (e.g. `arrow.type.traits.StringTraits`, `arrow.type.traits.UInt8Traits`, etc.). These "type traits" objects would help centralize various type-specific information in one place (e.g. MATLAB `double` <-> `arrow.type.Float64Type` <-> `arrow.array.Float64Array`), simplifying generic client code. This would help reduce the number of "switch-like" statements across the MATLAB code base that branch based on type. ### What changes are included in this PR? 1. Added new `arrow.type.traits.Traits` classes (e.g. `arrow.type.traits.UInt8Traits` and `arrow.type.traits.StringTraits`). 2. Added new `arrow.type.traits.traits` "gateway" function for creating "type traits" objects from MATLAB class strings (e.g. "double" or "datetime") and `arrow.type.ID` enumeration values (e.g. `arrow.type.ID.Timestamp` or `arrow.type.ID.UInt8`). ### Are these changes tested? Yes. 1. Added MATLAB tests for the new `arrow.type.traits.Traits` classes. 2. Added MATLAB tests (`ttraits.m`) for the new `arrow.type.traits.traits` "gateway" function. ### Are there any user-facing changes? Yes. There are now MATLAB "type traits" classes that can be used to simplify writing generic client code that switches based on type. **Note**: It may make sense to eventually mark these "type traits" APIs as "internal" so that they aren't encouraged to be used by client code outside of the MATLAB interface. The "type traits" classes expose some implementation details such as the `Proxy` classes that are used under the hood to represent a given `Array` object in C++. **Example** ```matlab % Construct a "type traits" object from an arrow.type.ID enumeration value >> logicalTraits = arrow.type.traits.traits(arrow.type.ID.Boolean) logicalTraits = BooleanTraits with properties: ArrayConstructor: @arrow.array.BooleanArray ArrayClassName: "arrow.array.BooleanArray" ArrayProxyClassName: "arrow.array.proxy.BooleanArray" TypeConstructor: @arrow.type.BooleanType TypeClassName: "arrow.type.BooleanType" TypeProxyClassName: "arrow.type.proxy.BooleanType" MatlabConstructor: @logical MatlabClassName: "logical" % Construct a "type traits" object from a MATLAB class string >> stringTraits = arrow.type.traits.traits("string") stringTraits = StringTraits with properties: ArrayConstructor: @arrow.array.StringArray ArrayClassName: "arrow.array.StringArray" ArrayProxyClassName: "arrow.array.proxy.StringArray" TypeConstructor: @arrow.type.StringType TypeClassName: "arrow.type.StringType" TypeProxyClassName: "arrow.type.proxy.StringType" MatlabConstructor: @string MatlabClassName: "string" ``` ### Future Directions 1. Re-implement `switch` statement in `RecordBatch` code to use "type traits" classes instead. 2. Look for more opportuntiies to leverage "type traits" to simplify code in the MATLAB interface. ### Notes 1. Thanks @sgilmore10 for your help with this pull request! -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
