This is an automated email from the ASF dual-hosted git repository.
kevingurney pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/arrow.git
The following commit(s) were added to refs/heads/main by this push:
new de23a7e54e GH-36601: [MATLAB] Add a MATLAB "type traits" class
hierarchy (#36653)
de23a7e54e is described below
commit de23a7e54ebe3cb2d0cf68f38044d42595957849
Author: Kevin Gurney <[email protected]>
AuthorDate: Thu Jul 13 13:34:21 2023 -0400
GH-36601: [MATLAB] Add a MATLAB "type traits" class hierarchy (#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.TypeTraits` 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.TypeTraits` 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 opportunties to leverage "type traits" to simplify code in
the MATLAB interface.
### Notes
1. Thanks @ sgilmore10 for your help with this pull request!
* Closes: #36601
Lead-authored-by: Kevin Gurney <[email protected]>
Co-authored-by: Sarah Gilmore <[email protected]>
Co-authored-by: Fiona La <[email protected]>
Signed-off-by: Kevin Gurney <[email protected]>
---
.../matlab/+arrow/+type/+traits/BooleanTraits.m | 29 ++
.../matlab/+arrow/+type/+traits/Float32Traits.m | 29 ++
.../matlab/+arrow/+type/+traits/Float64Traits.m | 29 ++
.../src/matlab/+arrow/+type/+traits/Int16Traits.m | 29 ++
.../src/matlab/+arrow/+type/+traits/Int32Traits.m | 29 ++
.../src/matlab/+arrow/+type/+traits/Int64Traits.m | 29 ++
.../src/matlab/+arrow/+type/+traits/Int8Traits.m | 29 ++
.../src/matlab/+arrow/+type/+traits/StringTraits.m | 29 ++
.../matlab/+arrow/+type/+traits/TimestampTraits.m | 29 ++
.../src/matlab/+arrow/+type/+traits/TypeTraits.m | 29 ++
.../src/matlab/+arrow/+type/+traits/UInt16Traits.m | 29 ++
.../src/matlab/+arrow/+type/+traits/UInt32Traits.m | 29 ++
.../src/matlab/+arrow/+type/+traits/UInt64Traits.m | 29 ++
.../src/matlab/+arrow/+type/+traits/UInt8Traits.m | 29 ++
matlab/src/matlab/+arrow/+type/+traits/traits.m | 89 ++++++
matlab/src/matlab/+arrow/+type/Type.m | 1 +
matlab/test/arrow/type/traits/hTypeTraits.m | 78 +++++
matlab/test/arrow/type/traits/tBooleanTraits.m | 30 ++
matlab/test/arrow/type/traits/tInt16Traits.m | 30 ++
matlab/test/arrow/type/traits/tInt32Traits.m | 30 ++
matlab/test/arrow/type/traits/tInt64Traits.m | 30 ++
matlab/test/arrow/type/traits/tInt8Traits.m | 30 ++
matlab/test/arrow/type/traits/tStringTraits.m | 30 ++
matlab/test/arrow/type/traits/tTimestampTraits.m | 30 ++
matlab/test/arrow/type/traits/tUInt16Traits.m | 30 ++
matlab/test/arrow/type/traits/tUInt32Traits.m | 30 ++
matlab/test/arrow/type/traits/tUInt64Traits.m | 30 ++
matlab/test/arrow/type/traits/tUInt8Traits.m | 30 ++
matlab/test/arrow/type/traits/ttraits.m | 320 +++++++++++++++++++++
29 files changed, 1224 insertions(+)
diff --git a/matlab/src/matlab/+arrow/+type/+traits/BooleanTraits.m
b/matlab/src/matlab/+arrow/+type/+traits/BooleanTraits.m
new file mode 100644
index 0000000000..82a8b6b1e2
--- /dev/null
+++ b/matlab/src/matlab/+arrow/+type/+traits/BooleanTraits.m
@@ -0,0 +1,29 @@
+% Licensed to the Apache Software Foundation (ASF) under one or more
+% contributor license agreements. See the NOTICE file distributed with
+% this work for additional information regarding copyright ownership.
+% The ASF licenses this file to you under the Apache License, Version
+% 2.0 (the "License"); you may not use this file except in compliance
+% with the License. You may obtain a copy of the License at
+%
+% http://www.apache.org/licenses/LICENSE-2.0
+%
+% Unless required by applicable law or agreed to in writing, software
+% distributed under the License is distributed on an "AS IS" BASIS,
+% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+% implied. See the License for the specific language governing
+% permissions and limitations under the License.
+
+classdef BooleanTraits < arrow.type.traits.TypeTraits
+
+ properties (Constant)
+ 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"
+ end
+
+end
\ No newline at end of file
diff --git a/matlab/src/matlab/+arrow/+type/+traits/Float32Traits.m
b/matlab/src/matlab/+arrow/+type/+traits/Float32Traits.m
new file mode 100644
index 0000000000..7dc0d17474
--- /dev/null
+++ b/matlab/src/matlab/+arrow/+type/+traits/Float32Traits.m
@@ -0,0 +1,29 @@
+% Licensed to the Apache Software Foundation (ASF) under one or more
+% contributor license agreements. See the NOTICE file distributed with
+% this work for additional information regarding copyright ownership.
+% The ASF licenses this file to you under the Apache License, Version
+% 2.0 (the "License"); you may not use this file except in compliance
+% with the License. You may obtain a copy of the License at
+%
+% http://www.apache.org/licenses/LICENSE-2.0
+%
+% Unless required by applicable law or agreed to in writing, software
+% distributed under the License is distributed on an "AS IS" BASIS,
+% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+% implied. See the License for the specific language governing
+% permissions and limitations under the License.
+
+classdef Float32Traits < arrow.type.traits.TypeTraits
+
+ properties (Constant)
+ ArrayConstructor = @arrow.array.Float32Array
+ ArrayClassName = "arrow.array.Float32Array"
+ ArrayProxyClassName = "arrow.array.proxy.Float32Array"
+ TypeConstructor = @arrow.type.Float32Type;
+ TypeClassName = "arrow.type.Float32Type"
+ TypeProxyClassName = "arrow.type.proxy.Float32Type"
+ MatlabConstructor = @single
+ MatlabClassName = "single"
+ end
+
+end
\ No newline at end of file
diff --git a/matlab/src/matlab/+arrow/+type/+traits/Float64Traits.m
b/matlab/src/matlab/+arrow/+type/+traits/Float64Traits.m
new file mode 100644
index 0000000000..9c52634b2c
--- /dev/null
+++ b/matlab/src/matlab/+arrow/+type/+traits/Float64Traits.m
@@ -0,0 +1,29 @@
+% Licensed to the Apache Software Foundation (ASF) under one or more
+% contributor license agreements. See the NOTICE file distributed with
+% this work for additional information regarding copyright ownership.
+% The ASF licenses this file to you under the Apache License, Version
+% 2.0 (the "License"); you may not use this file except in compliance
+% with the License. You may obtain a copy of the License at
+%
+% http://www.apache.org/licenses/LICENSE-2.0
+%
+% Unless required by applicable law or agreed to in writing, software
+% distributed under the License is distributed on an "AS IS" BASIS,
+% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+% implied. See the License for the specific language governing
+% permissions and limitations under the License.
+
+classdef Float64Traits < arrow.type.traits.TypeTraits
+
+ properties (Constant)
+ ArrayConstructor = @arrow.array.Float64Array
+ ArrayClassName = "arrow.array.Float64Array"
+ ArrayProxyClassName = "arrow.array.proxy.Float64Array"
+ TypeConstructor = @arrow.type.Float64Type;
+ TypeClassName = "arrow.type.Float64Type"
+ TypeProxyClassName = "arrow.type.proxy.Float64Type"
+ MatlabConstructor = @double
+ MatlabClassName = "double"
+ end
+
+end
\ No newline at end of file
diff --git a/matlab/src/matlab/+arrow/+type/+traits/Int16Traits.m
b/matlab/src/matlab/+arrow/+type/+traits/Int16Traits.m
new file mode 100644
index 0000000000..46b67b43c1
--- /dev/null
+++ b/matlab/src/matlab/+arrow/+type/+traits/Int16Traits.m
@@ -0,0 +1,29 @@
+% Licensed to the Apache Software Foundation (ASF) under one or more
+% contributor license agreements. See the NOTICE file distributed with
+% this work for additional information regarding copyright ownership.
+% The ASF licenses this file to you under the Apache License, Version
+% 2.0 (the "License"); you may not use this file except in compliance
+% with the License. You may obtain a copy of the License at
+%
+% http://www.apache.org/licenses/LICENSE-2.0
+%
+% Unless required by applicable law or agreed to in writing, software
+% distributed under the License is distributed on an "AS IS" BASIS,
+% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+% implied. See the License for the specific language governing
+% permissions and limitations under the License.
+
+classdef Int16Traits < arrow.type.traits.TypeTraits
+
+ properties (Constant)
+ ArrayConstructor = @arrow.array.Int16Array
+ ArrayClassName = "arrow.array.Int16Array"
+ ArrayProxyClassName = "arrow.array.proxy.Int16Array"
+ TypeConstructor = @arrow.type.Int16Type;
+ TypeClassName = "arrow.type.Int16Type"
+ TypeProxyClassName = "arrow.type.proxy.Int16Type"
+ MatlabConstructor = @int16
+ MatlabClassName = "int16"
+ end
+
+end
\ No newline at end of file
diff --git a/matlab/src/matlab/+arrow/+type/+traits/Int32Traits.m
b/matlab/src/matlab/+arrow/+type/+traits/Int32Traits.m
new file mode 100644
index 0000000000..4117271e50
--- /dev/null
+++ b/matlab/src/matlab/+arrow/+type/+traits/Int32Traits.m
@@ -0,0 +1,29 @@
+% Licensed to the Apache Software Foundation (ASF) under one or more
+% contributor license agreements. See the NOTICE file distributed with
+% this work for additional information regarding copyright ownership.
+% The ASF licenses this file to you under the Apache License, Version
+% 2.0 (the "License"); you may not use this file except in compliance
+% with the License. You may obtain a copy of the License at
+%
+% http://www.apache.org/licenses/LICENSE-2.0
+%
+% Unless required by applicable law or agreed to in writing, software
+% distributed under the License is distributed on an "AS IS" BASIS,
+% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+% implied. See the License for the specific language governing
+% permissions and limitations under the License.
+
+classdef Int32Traits < arrow.type.traits.TypeTraits
+
+ properties (Constant)
+ ArrayConstructor = @arrow.array.Int32Array
+ ArrayClassName = "arrow.array.Int32Array"
+ ArrayProxyClassName = "arrow.array.proxy.Int32Array"
+ TypeConstructor = @arrow.type.Int32Type;
+ TypeClassName = "arrow.type.Int32Type"
+ TypeProxyClassName = "arrow.type.proxy.Int32Type"
+ MatlabConstructor = @int32
+ MatlabClassName = "int32"
+ end
+
+end
\ No newline at end of file
diff --git a/matlab/src/matlab/+arrow/+type/+traits/Int64Traits.m
b/matlab/src/matlab/+arrow/+type/+traits/Int64Traits.m
new file mode 100644
index 0000000000..e25da953aa
--- /dev/null
+++ b/matlab/src/matlab/+arrow/+type/+traits/Int64Traits.m
@@ -0,0 +1,29 @@
+% Licensed to the Apache Software Foundation (ASF) under one or more
+% contributor license agreements. See the NOTICE file distributed with
+% this work for additional information regarding copyright ownership.
+% The ASF licenses this file to you under the Apache License, Version
+% 2.0 (the "License"); you may not use this file except in compliance
+% with the License. You may obtain a copy of the License at
+%
+% http://www.apache.org/licenses/LICENSE-2.0
+%
+% Unless required by applicable law or agreed to in writing, software
+% distributed under the License is distributed on an "AS IS" BASIS,
+% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+% implied. See the License for the specific language governing
+% permissions and limitations under the License.
+
+classdef Int64Traits < arrow.type.traits.TypeTraits
+
+ properties (Constant)
+ ArrayConstructor = @arrow.array.Int64Array
+ ArrayClassName = "arrow.array.Int64Array"
+ ArrayProxyClassName = "arrow.array.proxy.Int64Array"
+ TypeConstructor = @arrow.type.Int64Type;
+ TypeClassName = "arrow.type.Int64Type"
+ TypeProxyClassName = "arrow.type.proxy.Int64Type"
+ MatlabConstructor = @int64
+ MatlabClassName = "int64"
+ end
+
+end
\ No newline at end of file
diff --git a/matlab/src/matlab/+arrow/+type/+traits/Int8Traits.m
b/matlab/src/matlab/+arrow/+type/+traits/Int8Traits.m
new file mode 100644
index 0000000000..9f73bd2667
--- /dev/null
+++ b/matlab/src/matlab/+arrow/+type/+traits/Int8Traits.m
@@ -0,0 +1,29 @@
+% Licensed to the Apache Software Foundation (ASF) under one or more
+% contributor license agreements. See the NOTICE file distributed with
+% this work for additional information regarding copyright ownership.
+% The ASF licenses this file to you under the Apache License, Version
+% 2.0 (the "License"); you may not use this file except in compliance
+% with the License. You may obtain a copy of the License at
+%
+% http://www.apache.org/licenses/LICENSE-2.0
+%
+% Unless required by applicable law or agreed to in writing, software
+% distributed under the License is distributed on an "AS IS" BASIS,
+% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+% implied. See the License for the specific language governing
+% permissions and limitations under the License.
+
+classdef Int8Traits < arrow.type.traits.TypeTraits
+
+ properties (Constant)
+ ArrayConstructor = @arrow.array.Int8Array
+ ArrayClassName = "arrow.array.Int8Array"
+ ArrayProxyClassName = "arrow.array.proxy.Int8Array"
+ TypeConstructor = @arrow.type.Int8Type;
+ TypeClassName = "arrow.type.Int8Type"
+ TypeProxyClassName = "arrow.type.proxy.Int8Type"
+ MatlabConstructor = @int8
+ MatlabClassName = "int8"
+ end
+
+end
\ No newline at end of file
diff --git a/matlab/src/matlab/+arrow/+type/+traits/StringTraits.m
b/matlab/src/matlab/+arrow/+type/+traits/StringTraits.m
new file mode 100644
index 0000000000..0730657270
--- /dev/null
+++ b/matlab/src/matlab/+arrow/+type/+traits/StringTraits.m
@@ -0,0 +1,29 @@
+% Licensed to the Apache Software Foundation (ASF) under one or more
+% contributor license agreements. See the NOTICE file distributed with
+% this work for additional information regarding copyright ownership.
+% The ASF licenses this file to you under the Apache License, Version
+% 2.0 (the "License"); you may not use this file except in compliance
+% with the License. You may obtain a copy of the License at
+%
+% http://www.apache.org/licenses/LICENSE-2.0
+%
+% Unless required by applicable law or agreed to in writing, software
+% distributed under the License is distributed on an "AS IS" BASIS,
+% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+% implied. See the License for the specific language governing
+% permissions and limitations under the License.
+
+classdef StringTraits < arrow.type.traits.TypeTraits
+
+ properties (Constant)
+ 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"
+ end
+
+end
\ No newline at end of file
diff --git a/matlab/src/matlab/+arrow/+type/+traits/TimestampTraits.m
b/matlab/src/matlab/+arrow/+type/+traits/TimestampTraits.m
new file mode 100644
index 0000000000..488a5e7314
--- /dev/null
+++ b/matlab/src/matlab/+arrow/+type/+traits/TimestampTraits.m
@@ -0,0 +1,29 @@
+% Licensed to the Apache Software Foundation (ASF) under one or more
+% contributor license agreements. See the NOTICE file distributed with
+% this work for additional information regarding copyright ownership.
+% The ASF licenses this file to you under the Apache License, Version
+% 2.0 (the "License"); you may not use this file except in compliance
+% with the License. You may obtain a copy of the License at
+%
+% http://www.apache.org/licenses/LICENSE-2.0
+%
+% Unless required by applicable law or agreed to in writing, software
+% distributed under the License is distributed on an "AS IS" BASIS,
+% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+% implied. See the License for the specific language governing
+% permissions and limitations under the License.
+
+classdef TimestampTraits < arrow.type.traits.TypeTraits
+
+ properties (Constant)
+ ArrayConstructor = @arrow.array.TimestampArray
+ ArrayClassName = "arrow.array.TimestampArray"
+ ArrayProxyClassName = "arrow.array.proxy.TimestampArray"
+ TypeConstructor = @arrow.type.TimestampType;
+ TypeClassName = "arrow.type.TimestampType"
+ TypeProxyClassName = "arrow.type.proxy.TimestampType"
+ MatlabConstructor = @datetime
+ MatlabClassName = "datetime"
+ end
+
+end
\ No newline at end of file
diff --git a/matlab/src/matlab/+arrow/+type/+traits/TypeTraits.m
b/matlab/src/matlab/+arrow/+type/+traits/TypeTraits.m
new file mode 100644
index 0000000000..54b8fc0a77
--- /dev/null
+++ b/matlab/src/matlab/+arrow/+type/+traits/TypeTraits.m
@@ -0,0 +1,29 @@
+% Licensed to the Apache Software Foundation (ASF) under one or more
+% contributor license agreements. See the NOTICE file distributed with
+% this work for additional information regarding copyright ownership.
+% The ASF licenses this file to you under the Apache License, Version
+% 2.0 (the "License"); you may not use this file except in compliance
+% with the License. You may obtain a copy of the License at
+%
+% http://www.apache.org/licenses/LICENSE-2.0
+%
+% Unless required by applicable law or agreed to in writing, software
+% distributed under the License is distributed on an "AS IS" BASIS,
+% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+% implied. See the License for the specific language governing
+% permissions and limitations under the License.
+
+classdef TypeTraits
+
+ properties (Abstract, Constant)
+ ArrayConstructor
+ ArrayClassName
+ ArrayProxyClassName
+ TypeConstructor
+ TypeClassName
+ TypeProxyClassName
+ MatlabConstructor
+ MatlabClassName
+ end
+
+end
\ No newline at end of file
diff --git a/matlab/src/matlab/+arrow/+type/+traits/UInt16Traits.m
b/matlab/src/matlab/+arrow/+type/+traits/UInt16Traits.m
new file mode 100644
index 0000000000..b90e6294ce
--- /dev/null
+++ b/matlab/src/matlab/+arrow/+type/+traits/UInt16Traits.m
@@ -0,0 +1,29 @@
+% Licensed to the Apache Software Foundation (ASF) under one or more
+% contributor license agreements. See the NOTICE file distributed with
+% this work for additional information regarding copyright ownership.
+% The ASF licenses this file to you under the Apache License, Version
+% 2.0 (the "License"); you may not use this file except in compliance
+% with the License. You may obtain a copy of the License at
+%
+% http://www.apache.org/licenses/LICENSE-2.0
+%
+% Unless required by applicable law or agreed to in writing, software
+% distributed under the License is distributed on an "AS IS" BASIS,
+% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+% implied. See the License for the specific language governing
+% permissions and limitations under the License.
+
+classdef UInt16Traits < arrow.type.traits.TypeTraits
+
+ properties (Constant)
+ ArrayConstructor = @arrow.array.UInt16Array
+ ArrayClassName = "arrow.array.UInt16Array"
+ ArrayProxyClassName = "arrow.array.proxy.UInt16Array"
+ TypeConstructor = @arrow.type.UInt16Type;
+ TypeClassName = "arrow.type.UInt16Type"
+ TypeProxyClassName = "arrow.type.proxy.UInt16Type"
+ MatlabConstructor = @uint16
+ MatlabClassName = "uint16"
+ end
+
+end
\ No newline at end of file
diff --git a/matlab/src/matlab/+arrow/+type/+traits/UInt32Traits.m
b/matlab/src/matlab/+arrow/+type/+traits/UInt32Traits.m
new file mode 100644
index 0000000000..ff79bd9579
--- /dev/null
+++ b/matlab/src/matlab/+arrow/+type/+traits/UInt32Traits.m
@@ -0,0 +1,29 @@
+% Licensed to the Apache Software Foundation (ASF) under one or more
+% contributor license agreements. See the NOTICE file distributed with
+% this work for additional information regarding copyright ownership.
+% The ASF licenses this file to you under the Apache License, Version
+% 2.0 (the "License"); you may not use this file except in compliance
+% with the License. You may obtain a copy of the License at
+%
+% http://www.apache.org/licenses/LICENSE-2.0
+%
+% Unless required by applicable law or agreed to in writing, software
+% distributed under the License is distributed on an "AS IS" BASIS,
+% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+% implied. See the License for the specific language governing
+% permissions and limitations under the License.
+
+classdef UInt32Traits < arrow.type.traits.TypeTraits
+
+ properties (Constant)
+ ArrayConstructor = @arrow.array.UInt32Array
+ ArrayClassName = "arrow.array.UInt32Array"
+ ArrayProxyClassName = "arrow.array.proxy.UInt32Array"
+ TypeConstructor = @arrow.type.UInt32Type;
+ TypeClassName = "arrow.type.UInt32Type"
+ TypeProxyClassName = "arrow.type.proxy.UInt32Type"
+ MatlabConstructor = @uint32
+ MatlabClassName = "uint32"
+ end
+
+end
\ No newline at end of file
diff --git a/matlab/src/matlab/+arrow/+type/+traits/UInt64Traits.m
b/matlab/src/matlab/+arrow/+type/+traits/UInt64Traits.m
new file mode 100644
index 0000000000..a6b0de3752
--- /dev/null
+++ b/matlab/src/matlab/+arrow/+type/+traits/UInt64Traits.m
@@ -0,0 +1,29 @@
+% Licensed to the Apache Software Foundation (ASF) under one or more
+% contributor license agreements. See the NOTICE file distributed with
+% this work for additional information regarding copyright ownership.
+% The ASF licenses this file to you under the Apache License, Version
+% 2.0 (the "License"); you may not use this file except in compliance
+% with the License. You may obtain a copy of the License at
+%
+% http://www.apache.org/licenses/LICENSE-2.0
+%
+% Unless required by applicable law or agreed to in writing, software
+% distributed under the License is distributed on an "AS IS" BASIS,
+% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+% implied. See the License for the specific language governing
+% permissions and limitations under the License.
+
+classdef UInt64Traits < arrow.type.traits.TypeTraits
+
+ properties (Constant)
+ ArrayConstructor = @arrow.array.UInt64Array
+ ArrayClassName = "arrow.array.UInt64Array"
+ ArrayProxyClassName = "arrow.array.proxy.UInt64Array"
+ TypeConstructor = @arrow.type.UInt64Type;
+ TypeClassName = "arrow.type.UInt64Type"
+ TypeProxyClassName = "arrow.type.proxy.UInt64Type"
+ MatlabConstructor = @uint64
+ MatlabClassName = "uint64"
+ end
+
+end
\ No newline at end of file
diff --git a/matlab/src/matlab/+arrow/+type/+traits/UInt8Traits.m
b/matlab/src/matlab/+arrow/+type/+traits/UInt8Traits.m
new file mode 100644
index 0000000000..ff2377ff81
--- /dev/null
+++ b/matlab/src/matlab/+arrow/+type/+traits/UInt8Traits.m
@@ -0,0 +1,29 @@
+% Licensed to the Apache Software Foundation (ASF) under one or more
+% contributor license agreements. See the NOTICE file distributed with
+% this work for additional information regarding copyright ownership.
+% The ASF licenses this file to you under the Apache License, Version
+% 2.0 (the "License"); you may not use this file except in compliance
+% with the License. You may obtain a copy of the License at
+%
+% http://www.apache.org/licenses/LICENSE-2.0
+%
+% Unless required by applicable law or agreed to in writing, software
+% distributed under the License is distributed on an "AS IS" BASIS,
+% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+% implied. See the License for the specific language governing
+% permissions and limitations under the License.
+
+classdef UInt8Traits < arrow.type.traits.TypeTraits
+
+ properties (Constant)
+ ArrayConstructor = @arrow.array.UInt8Array
+ ArrayClassName = "arrow.array.UInt8Array"
+ ArrayProxyClassName = "arrow.array.proxy.UInt8Array"
+ TypeConstructor = @arrow.type.UInt8Type;
+ TypeClassName = "arrow.type.UInt8Type"
+ TypeProxyClassName = "arrow.type.proxy.UInt8Type"
+ MatlabConstructor = @uint8
+ MatlabClassName = "uint8"
+ end
+
+end
\ No newline at end of file
diff --git a/matlab/src/matlab/+arrow/+type/+traits/traits.m
b/matlab/src/matlab/+arrow/+type/+traits/traits.m
new file mode 100644
index 0000000000..af59e2822d
--- /dev/null
+++ b/matlab/src/matlab/+arrow/+type/+traits/traits.m
@@ -0,0 +1,89 @@
+% Licensed to the Apache Software Foundation (ASF) under one or more
+% contributor license agreements. See the NOTICE file distributed with
+% this work for additional information regarding copyright ownership.
+% The ASF licenses this file to you under the Apache License, Version
+% 2.0 (the "License"); you may not use this file except in compliance
+% with the License. You may obtain a copy of the License at
+%
+% http://www.apache.org/licenses/LICENSE-2.0
+%
+% Unless required by applicable law or agreed to in writing, software
+% distributed under the License is distributed on an "AS IS" BASIS,
+% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+% implied. See the License for the specific language governing
+% permissions and limitations under the License.
+
+function typeTraits = traits(type)
+ % "Gateway" function that links an arrow Type ID enumeration (e.g.
+ % arrow.type.ID.String) or a MATLAB class string (e.g. "datetime")
+ % to associated type information.
+ import arrow.type.traits.*
+ import arrow.type.*
+
+ if isa(type, "arrow.type.ID")
+ switch type
+ case ID.UInt8
+ typeTraits = UInt8Traits();
+ case ID.UInt16
+ typeTraits = UInt16Traits();
+ case ID.UInt32
+ typeTraits = UInt32Traits();
+ case ID.UInt64
+ typeTraits = UInt64Traits();
+ case ID.Int8
+ typeTraits = Int8Traits();
+ case ID.Int16
+ typeTraits = Int16Traits();
+ case ID.Int32
+ typeTraits = Int32Traits();
+ case ID.Int64
+ typeTraits = Int64Traits();
+ case ID.Float32
+ typeTraits = Float32Traits();
+ case ID.Float64
+ typeTraits = Float64Traits();
+ case ID.Boolean
+ typeTraits = BooleanTraits();
+ case ID.String
+ typeTraits = StringTraits();
+ case ID.Timestamp
+ typeTraits = TimestampTraits();
+ otherwise
+ error("arrow:type:traits:UnsupportedArrowTypeID", "Unsupported
Arrow type ID: " + type);
+ end
+ elseif isa(type, "string") % MATLAB class string
+ switch type
+ case "uint8"
+ typeTraits = UInt8Traits();
+ case "uint16"
+ typeTraits = UInt16Traits();
+ case "uint32"
+ typeTraits = UInt32Traits();
+ case "uint64"
+ typeTraits = UInt64Traits();
+ case "int8"
+ typeTraits = Int8Traits();
+ case "int16"
+ typeTraits = Int16Traits();
+ case "int32"
+ typeTraits = Int32Traits();
+ case "int64"
+ typeTraits = Int64Traits();
+ case "single"
+ typeTraits = Float32Traits();
+ case "double"
+ typeTraits = Float64Traits();
+ case "logical"
+ typeTraits = BooleanTraits();
+ case "string"
+ typeTraits = StringTraits();
+ case "datetime"
+ typeTraits = TimestampTraits();
+ otherwise
+ error("arrow:type:traits:UnsupportedMatlabClass", "Unsupported
MATLAB class: " + type);
+ end
+ else
+ error("arrow:type:traits:UnsupportedInputType", "The input argument to
the traits function " + ...
+ "must be a MATLAB
class string or an arrow.type.ID enumeration.");
+ end
+end
\ No newline at end of file
diff --git a/matlab/src/matlab/+arrow/+type/Type.m
b/matlab/src/matlab/+arrow/+type/Type.m
index d6efc32be3..466f393c7d 100644
--- a/matlab/src/matlab/+arrow/+type/Type.m
+++ b/matlab/src/matlab/+arrow/+type/Type.m
@@ -45,4 +45,5 @@ classdef (Abstract) Type < matlab.mixin.CustomDisplay
propgrp = matlab.mixin.util.PropertyGroup(proplist);
end
end
+
end
diff --git a/matlab/test/arrow/type/traits/hTypeTraits.m
b/matlab/test/arrow/type/traits/hTypeTraits.m
new file mode 100644
index 0000000000..df62fdd325
--- /dev/null
+++ b/matlab/test/arrow/type/traits/hTypeTraits.m
@@ -0,0 +1,78 @@
+% Licensed to the Apache Software Foundation (ASF) under one or more
+% contributor license agreements. See the NOTICE file distributed with
+% this work for additional information regarding copyright ownership.
+% The ASF licenses this file to you under the Apache License, Version
+% 2.0 (the "License"); you may not use this file except in compliance
+% with the License. You may obtain a copy of the License at
+%
+% http://www.apache.org/licenses/LICENSE-2.0
+%
+% Unless required by applicable law or agreed to in writing, software
+% distributed under the License is distributed on an "AS IS" BASIS,
+% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+% implied. See the License for the specific language governing
+% permissions and limitations under the License.
+
+classdef hTypeTraits < matlab.unittest.TestCase
+% Superclass for tests that validate the behavior of "type trait" objects
+% like arrow.type.traits.StringTraits.
+
+ properties (Abstract)
+ TraitsConstructor
+ ArrayConstructor
+ ArrayClassName
+ ArrayProxyClassName
+ TypeConstructor
+ TypeClassName
+ TypeProxyClassName
+ MatlabConstructor
+ MatlabClassName
+ end
+
+ properties
+ Traits
+ end
+
+ methods (TestMethodSetup)
+ function setupTraits(testCase)
+ testCase.Traits = testCase.TraitsConstructor();
+ end
+ end
+
+ methods(Test)
+
+ function TestArrayConstructor(testCase)
+ testCase.verifyEqual(testCase.Traits.ArrayConstructor,
testCase.ArrayConstructor);
+ end
+
+ function TestArrayClassName(testCase)
+ testCase.verifyEqual(testCase.Traits.ArrayClassName,
testCase.ArrayClassName);
+ end
+
+ function TestArrayProxyClassName(testCase)
+ testCase.verifyEqual(testCase.Traits.ArrayProxyClassName,
testCase.ArrayProxyClassName);
+ end
+
+ function TestTypeConstructor(testCase)
+ testCase.verifyEqual(testCase.Traits.TypeConstructor,
testCase.TypeConstructor);
+ end
+
+ function TestTypeClassName(testCase)
+ testCase.verifyEqual(testCase.Traits.TypeClassName,
testCase.TypeClassName);
+ end
+
+ function TestTypeProxyClassName(testCase)
+ testCase.verifyEqual(testCase.Traits.TypeProxyClassName,
testCase.TypeProxyClassName);
+ end
+
+ function TestMatlabConstructor(testCase)
+ testCase.verifyEqual(testCase.Traits.MatlabConstructor,
testCase.MatlabConstructor);
+ end
+
+ function TestMatlabClassName(testCase)
+ testCase.verifyEqual(testCase.Traits.MatlabClassName,
testCase.MatlabClassName);
+ end
+
+ end
+
+end
\ No newline at end of file
diff --git a/matlab/test/arrow/type/traits/tBooleanTraits.m
b/matlab/test/arrow/type/traits/tBooleanTraits.m
new file mode 100644
index 0000000000..859dc630a1
--- /dev/null
+++ b/matlab/test/arrow/type/traits/tBooleanTraits.m
@@ -0,0 +1,30 @@
+% Licensed to the Apache Software Foundation (ASF) under one or more
+% contributor license agreements. See the NOTICE file distributed with
+% this work for additional information regarding copyright ownership.
+% The ASF licenses this file to you under the Apache License, Version
+% 2.0 (the "License"); you may not use this file except in compliance
+% with the License. You may obtain a copy of the License at
+%
+% http://www.apache.org/licenses/LICENSE-2.0
+%
+% Unless required by applicable law or agreed to in writing, software
+% distributed under the License is distributed on an "AS IS" BASIS,
+% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+% implied. See the License for the specific language governing
+% permissions and limitations under the License.
+
+classdef tBooleanTraits < hTypeTraits
+
+ properties
+ TraitsConstructor = @arrow.type.traits.BooleanTraits
+ 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"
+ end
+
+end
\ No newline at end of file
diff --git a/matlab/test/arrow/type/traits/tInt16Traits.m
b/matlab/test/arrow/type/traits/tInt16Traits.m
new file mode 100644
index 0000000000..bde308d28e
--- /dev/null
+++ b/matlab/test/arrow/type/traits/tInt16Traits.m
@@ -0,0 +1,30 @@
+% Licensed to the Apache Software Foundation (ASF) under one or more
+% contributor license agreements. See the NOTICE file distributed with
+% this work for additional information regarding copyright ownership.
+% The ASF licenses this file to you under the Apache License, Version
+% 2.0 (the "License"); you may not use this file except in compliance
+% with the License. You may obtain a copy of the License at
+%
+% http://www.apache.org/licenses/LICENSE-2.0
+%
+% Unless required by applicable law or agreed to in writing, software
+% distributed under the License is distributed on an "AS IS" BASIS,
+% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+% implied. See the License for the specific language governing
+% permissions and limitations under the License.
+
+classdef tInt16Traits < hTypeTraits
+
+ properties
+ TraitsConstructor = @arrow.type.traits.Int16Traits
+ ArrayConstructor = @arrow.array.Int16Array
+ ArrayClassName = "arrow.array.Int16Array"
+ ArrayProxyClassName = "arrow.array.proxy.Int16Array"
+ TypeConstructor = @arrow.type.Int16Type
+ TypeClassName = "arrow.type.Int16Type"
+ TypeProxyClassName = "arrow.type.proxy.Int16Type"
+ MatlabConstructor = @int16
+ MatlabClassName = "int16"
+ end
+
+end
\ No newline at end of file
diff --git a/matlab/test/arrow/type/traits/tInt32Traits.m
b/matlab/test/arrow/type/traits/tInt32Traits.m
new file mode 100644
index 0000000000..651f647455
--- /dev/null
+++ b/matlab/test/arrow/type/traits/tInt32Traits.m
@@ -0,0 +1,30 @@
+% Licensed to the Apache Software Foundation (ASF) under one or more
+% contributor license agreements. See the NOTICE file distributed with
+% this work for additional information regarding copyright ownership.
+% The ASF licenses this file to you under the Apache License, Version
+% 2.0 (the "License"); you may not use this file except in compliance
+% with the License. You may obtain a copy of the License at
+%
+% http://www.apache.org/licenses/LICENSE-2.0
+%
+% Unless required by applicable law or agreed to in writing, software
+% distributed under the License is distributed on an "AS IS" BASIS,
+% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+% implied. See the License for the specific language governing
+% permissions and limitations under the License.
+
+classdef tInt32Traits < hTypeTraits
+
+ properties
+ TraitsConstructor = @arrow.type.traits.Int32Traits
+ ArrayConstructor = @arrow.array.Int32Array
+ ArrayClassName = "arrow.array.Int32Array"
+ ArrayProxyClassName = "arrow.array.proxy.Int32Array"
+ TypeConstructor = @arrow.type.Int32Type
+ TypeClassName = "arrow.type.Int32Type"
+ TypeProxyClassName = "arrow.type.proxy.Int32Type"
+ MatlabConstructor = @int32
+ MatlabClassName = "int32"
+ end
+
+end
\ No newline at end of file
diff --git a/matlab/test/arrow/type/traits/tInt64Traits.m
b/matlab/test/arrow/type/traits/tInt64Traits.m
new file mode 100644
index 0000000000..4f16c91eb4
--- /dev/null
+++ b/matlab/test/arrow/type/traits/tInt64Traits.m
@@ -0,0 +1,30 @@
+% Licensed to the Apache Software Foundation (ASF) under one or more
+% contributor license agreements. See the NOTICE file distributed with
+% this work for additional information regarding copyright ownership.
+% The ASF licenses this file to you under the Apache License, Version
+% 2.0 (the "License"); you may not use this file except in compliance
+% with the License. You may obtain a copy of the License at
+%
+% http://www.apache.org/licenses/LICENSE-2.0
+%
+% Unless required by applicable law or agreed to in writing, software
+% distributed under the License is distributed on an "AS IS" BASIS,
+% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+% implied. See the License for the specific language governing
+% permissions and limitations under the License.
+
+classdef tInt64Traits < hTypeTraits
+
+ properties
+ TraitsConstructor = @arrow.type.traits.Int64Traits
+ ArrayConstructor = @arrow.array.Int64Array
+ ArrayClassName = "arrow.array.Int64Array"
+ ArrayProxyClassName = "arrow.array.proxy.Int64Array"
+ TypeConstructor = @arrow.type.Int64Type
+ TypeClassName = "arrow.type.Int64Type"
+ TypeProxyClassName = "arrow.type.proxy.Int64Type"
+ MatlabConstructor = @int64
+ MatlabClassName = "int64"
+ end
+
+end
\ No newline at end of file
diff --git a/matlab/test/arrow/type/traits/tInt8Traits.m
b/matlab/test/arrow/type/traits/tInt8Traits.m
new file mode 100644
index 0000000000..3e767abbeb
--- /dev/null
+++ b/matlab/test/arrow/type/traits/tInt8Traits.m
@@ -0,0 +1,30 @@
+% Licensed to the Apache Software Foundation (ASF) under one or more
+% contributor license agreements. See the NOTICE file distributed with
+% this work for additional information regarding copyright ownership.
+% The ASF licenses this file to you under the Apache License, Version
+% 2.0 (the "License"); you may not use this file except in compliance
+% with the License. You may obtain a copy of the License at
+%
+% http://www.apache.org/licenses/LICENSE-2.0
+%
+% Unless required by applicable law or agreed to in writing, software
+% distributed under the License is distributed on an "AS IS" BASIS,
+% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+% implied. See the License for the specific language governing
+% permissions and limitations under the License.
+
+classdef tInt8Traits < hTypeTraits
+
+ properties
+ TraitsConstructor = @arrow.type.traits.Int8Traits
+ ArrayConstructor = @arrow.array.Int8Array
+ ArrayClassName = "arrow.array.Int8Array"
+ ArrayProxyClassName = "arrow.array.proxy.Int8Array"
+ TypeConstructor = @arrow.type.Int8Type
+ TypeClassName = "arrow.type.Int8Type"
+ TypeProxyClassName = "arrow.type.proxy.Int8Type"
+ MatlabConstructor = @int8
+ MatlabClassName = "int8"
+ end
+
+end
\ No newline at end of file
diff --git a/matlab/test/arrow/type/traits/tStringTraits.m
b/matlab/test/arrow/type/traits/tStringTraits.m
new file mode 100644
index 0000000000..68f061d1b0
--- /dev/null
+++ b/matlab/test/arrow/type/traits/tStringTraits.m
@@ -0,0 +1,30 @@
+% Licensed to the Apache Software Foundation (ASF) under one or more
+% contributor license agreements. See the NOTICE file distributed with
+% this work for additional information regarding copyright ownership.
+% The ASF licenses this file to you under the Apache License, Version
+% 2.0 (the "License"); you may not use this file except in compliance
+% with the License. You may obtain a copy of the License at
+%
+% http://www.apache.org/licenses/LICENSE-2.0
+%
+% Unless required by applicable law or agreed to in writing, software
+% distributed under the License is distributed on an "AS IS" BASIS,
+% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+% implied. See the License for the specific language governing
+% permissions and limitations under the License.
+
+classdef tStringTraits < hTypeTraits
+
+ properties
+ TraitsConstructor = @arrow.type.traits.StringTraits
+ 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"
+ end
+
+end
\ No newline at end of file
diff --git a/matlab/test/arrow/type/traits/tTimestampTraits.m
b/matlab/test/arrow/type/traits/tTimestampTraits.m
new file mode 100644
index 0000000000..5f451c0631
--- /dev/null
+++ b/matlab/test/arrow/type/traits/tTimestampTraits.m
@@ -0,0 +1,30 @@
+% Licensed to the Apache Software Foundation (ASF) under one or more
+% contributor license agreements. See the NOTICE file distributed with
+% this work for additional information regarding copyright ownership.
+% The ASF licenses this file to you under the Apache License, Version
+% 2.0 (the "License"); you may not use this file except in compliance
+% with the License. You may obtain a copy of the License at
+%
+% http://www.apache.org/licenses/LICENSE-2.0
+%
+% Unless required by applicable law or agreed to in writing, software
+% distributed under the License is distributed on an "AS IS" BASIS,
+% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+% implied. See the License for the specific language governing
+% permissions and limitations under the License.
+
+classdef tTimestampTraits < hTypeTraits
+
+ properties
+ TraitsConstructor = @arrow.type.traits.TimestampTraits
+ ArrayConstructor = @arrow.array.TimestampArray
+ ArrayClassName = "arrow.array.TimestampArray"
+ ArrayProxyClassName = "arrow.array.proxy.TimestampArray"
+ TypeConstructor = @arrow.type.TimestampType
+ TypeClassName = "arrow.type.TimestampType"
+ TypeProxyClassName = "arrow.type.proxy.TimestampType"
+ MatlabConstructor = @datetime
+ MatlabClassName = "datetime"
+ end
+
+end
\ No newline at end of file
diff --git a/matlab/test/arrow/type/traits/tUInt16Traits.m
b/matlab/test/arrow/type/traits/tUInt16Traits.m
new file mode 100644
index 0000000000..4a9eef6f29
--- /dev/null
+++ b/matlab/test/arrow/type/traits/tUInt16Traits.m
@@ -0,0 +1,30 @@
+% Licensed to the Apache Software Foundation (ASF) under one or more
+% contributor license agreements. See the NOTICE file distributed with
+% this work for additional information regarding copyright ownership.
+% The ASF licenses this file to you under the Apache License, Version
+% 2.0 (the "License"); you may not use this file except in compliance
+% with the License. You may obtain a copy of the License at
+%
+% http://www.apache.org/licenses/LICENSE-2.0
+%
+% Unless required by applicable law or agreed to in writing, software
+% distributed under the License is distributed on an "AS IS" BASIS,
+% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+% implied. See the License for the specific language governing
+% permissions and limitations under the License.
+
+classdef tUInt16Traits < hTypeTraits
+
+ properties
+ TraitsConstructor = @arrow.type.traits.UInt16Traits
+ ArrayConstructor = @arrow.array.UInt16Array
+ ArrayClassName = "arrow.array.UInt16Array"
+ ArrayProxyClassName = "arrow.array.proxy.UInt16Array"
+ TypeConstructor = @arrow.type.UInt16Type
+ TypeClassName = "arrow.type.UInt16Type"
+ TypeProxyClassName = "arrow.type.proxy.UInt16Type"
+ MatlabConstructor = @uint16
+ MatlabClassName = "uint16"
+ end
+
+end
\ No newline at end of file
diff --git a/matlab/test/arrow/type/traits/tUInt32Traits.m
b/matlab/test/arrow/type/traits/tUInt32Traits.m
new file mode 100644
index 0000000000..227e42c4eb
--- /dev/null
+++ b/matlab/test/arrow/type/traits/tUInt32Traits.m
@@ -0,0 +1,30 @@
+% Licensed to the Apache Software Foundation (ASF) under one or more
+% contributor license agreements. See the NOTICE file distributed with
+% this work for additional information regarding copyright ownership.
+% The ASF licenses this file to you under the Apache License, Version
+% 2.0 (the "License"); you may not use this file except in compliance
+% with the License. You may obtain a copy of the License at
+%
+% http://www.apache.org/licenses/LICENSE-2.0
+%
+% Unless required by applicable law or agreed to in writing, software
+% distributed under the License is distributed on an "AS IS" BASIS,
+% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+% implied. See the License for the specific language governing
+% permissions and limitations under the License.
+
+classdef tUInt32Traits < hTypeTraits
+
+ properties
+ TraitsConstructor = @arrow.type.traits.UInt32Traits
+ ArrayConstructor = @arrow.array.UInt32Array
+ ArrayClassName = "arrow.array.UInt32Array"
+ ArrayProxyClassName = "arrow.array.proxy.UInt32Array"
+ TypeConstructor = @arrow.type.UInt32Type
+ TypeClassName = "arrow.type.UInt32Type"
+ TypeProxyClassName = "arrow.type.proxy.UInt32Type"
+ MatlabConstructor = @uint32
+ MatlabClassName = "uint32"
+ end
+
+end
\ No newline at end of file
diff --git a/matlab/test/arrow/type/traits/tUInt64Traits.m
b/matlab/test/arrow/type/traits/tUInt64Traits.m
new file mode 100644
index 0000000000..370e905f27
--- /dev/null
+++ b/matlab/test/arrow/type/traits/tUInt64Traits.m
@@ -0,0 +1,30 @@
+% Licensed to the Apache Software Foundation (ASF) under one or more
+% contributor license agreements. See the NOTICE file distributed with
+% this work for additional information regarding copyright ownership.
+% The ASF licenses this file to you under the Apache License, Version
+% 2.0 (the "License"); you may not use this file except in compliance
+% with the License. You may obtain a copy of the License at
+%
+% http://www.apache.org/licenses/LICENSE-2.0
+%
+% Unless required by applicable law or agreed to in writing, software
+% distributed under the License is distributed on an "AS IS" BASIS,
+% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+% implied. See the License for the specific language governing
+% permissions and limitations under the License.
+
+classdef tUInt64Traits < hTypeTraits
+
+ properties
+ TraitsConstructor = @arrow.type.traits.UInt64Traits
+ ArrayConstructor = @arrow.array.UInt64Array
+ ArrayClassName = "arrow.array.UInt64Array"
+ ArrayProxyClassName = "arrow.array.proxy.UInt64Array"
+ TypeConstructor = @arrow.type.UInt64Type
+ TypeClassName = "arrow.type.UInt64Type"
+ TypeProxyClassName = "arrow.type.proxy.UInt64Type"
+ MatlabConstructor = @uint64
+ MatlabClassName = "uint64"
+ end
+
+end
\ No newline at end of file
diff --git a/matlab/test/arrow/type/traits/tUInt8Traits.m
b/matlab/test/arrow/type/traits/tUInt8Traits.m
new file mode 100644
index 0000000000..d93f9d3c1b
--- /dev/null
+++ b/matlab/test/arrow/type/traits/tUInt8Traits.m
@@ -0,0 +1,30 @@
+% Licensed to the Apache Software Foundation (ASF) under one or more
+% contributor license agreements. See the NOTICE file distributed with
+% this work for additional information regarding copyright ownership.
+% The ASF licenses this file to you under the Apache License, Version
+% 2.0 (the "License"); you may not use this file except in compliance
+% with the License. You may obtain a copy of the License at
+%
+% http://www.apache.org/licenses/LICENSE-2.0
+%
+% Unless required by applicable law or agreed to in writing, software
+% distributed under the License is distributed on an "AS IS" BASIS,
+% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+% implied. See the License for the specific language governing
+% permissions and limitations under the License.
+
+classdef tUInt8Traits < hTypeTraits
+
+ properties
+ TraitsConstructor = @arrow.type.traits.UInt8Traits
+ ArrayConstructor = @arrow.array.UInt8Array
+ ArrayClassName = "arrow.array.UInt8Array"
+ ArrayProxyClassName = "arrow.array.proxy.UInt8Array"
+ TypeConstructor = @arrow.type.UInt8Type
+ TypeClassName = "arrow.type.UInt8Type"
+ TypeProxyClassName = "arrow.type.proxy.UInt8Type"
+ MatlabConstructor = @uint8
+ MatlabClassName = "uint8"
+ end
+
+end
\ No newline at end of file
diff --git a/matlab/test/arrow/type/traits/ttraits.m
b/matlab/test/arrow/type/traits/ttraits.m
new file mode 100644
index 0000000000..14149a5ebf
--- /dev/null
+++ b/matlab/test/arrow/type/traits/ttraits.m
@@ -0,0 +1,320 @@
+% Licensed to the Apache Software Foundation (ASF) under one or more
+% contributor license agreements. See the NOTICE file distributed with
+% this work for additional information regarding copyright ownership.
+% The ASF licenses this file to you under the Apache License, Version
+% 2.0 (the "License"); you may not use this file except in compliance
+% with the License. You may obtain a copy of the License at
+%
+% http://www.apache.org/licenses/LICENSE-2.0
+%
+% Unless required by applicable law or agreed to in writing, software
+% distributed under the License is distributed on an "AS IS" BASIS,
+% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+% implied. See the License for the specific language governing
+% permissions and limitations under the License.
+
+classdef ttraits < matlab.unittest.TestCase
+ % Tests for the type traits (i.e. arrow.type.traits.traits)
+ % "gateway" function.
+
+ methods(Test)
+
+ function TestUInt8(testCase)
+ import arrow.type.traits.*
+ import arrow.type.*
+
+ typeID = ID.UInt8;
+ expectedTraits = UInt8Traits();
+
+ actualTraits = traits(typeID);
+
+ testCase.verifyEqual(actualTraits, expectedTraits);
+ end
+
+ function TestUInt16(testCase)
+ import arrow.type.traits.*
+ import arrow.type.*
+
+ type = ID.UInt16;
+ expectedTraits = UInt16Traits();
+
+ actualTraits = traits(type);
+
+ testCase.verifyEqual(actualTraits, expectedTraits);
+ end
+
+ function TestUInt32(testCase)
+ import arrow.type.traits.*
+ import arrow.type.*
+
+ type = ID.UInt32;
+ expectedTraits = UInt32Traits();
+
+ actualTraits = traits(type);
+
+ testCase.verifyEqual(actualTraits, expectedTraits);
+ end
+
+ function TestUInt64(testCase)
+ import arrow.type.traits.*
+ import arrow.type.*
+
+ type = ID.UInt64;
+ expectedTraits = UInt64Traits();
+
+ actualTraits = traits(type);
+
+ testCase.verifyEqual(actualTraits, expectedTraits);
+ end
+
+ function TestInt8(testCase)
+ import arrow.type.traits.*
+ import arrow.type.*
+
+ type = ID.Int8;
+ expectedTraits = Int8Traits();
+
+ actualTraits = traits(type);
+
+ testCase.verifyEqual(actualTraits, expectedTraits);
+ end
+
+ function TestInt16(testCase)
+ import arrow.type.traits.*
+ import arrow.type.*
+
+ type = ID.Int16;
+ expectedTraits = Int16Traits();
+
+ actualTraits = traits(type);
+
+ testCase.verifyEqual(actualTraits, expectedTraits);
+ end
+
+ function TestInt32(testCase)
+ import arrow.type.traits.*
+ import arrow.type.*
+
+ type = ID.Int32;
+ expectedTraits = Int32Traits();
+
+ actualTraits = traits(type);
+
+ testCase.verifyEqual(actualTraits, expectedTraits);
+ end
+
+ function TestInt64(testCase)
+ import arrow.type.traits.*
+ import arrow.type.*
+
+ type = ID.Int64;
+ expectedTraits = Int64Traits();
+
+ actualTraits = traits(type);
+
+ testCase.verifyEqual(actualTraits, expectedTraits);
+ end
+
+ function TestString(testCase)
+ import arrow.type.traits.*
+ import arrow.type.*
+
+ type = ID.String;
+ expectedTraits = StringTraits();
+
+ actualTraits = traits(type);
+
+ testCase.verifyEqual(actualTraits, expectedTraits);
+ end
+
+ function TestTimestamp(testCase)
+ import arrow.type.traits.*
+ import arrow.type.*
+
+ type = ID.Timestamp;
+ expectedTraits = TimestampTraits();
+
+ actualTraits = traits(type);
+
+ testCase.verifyEqual(actualTraits, expectedTraits);
+ end
+
+ function TestBoolean(testCase)
+ import arrow.type.traits.*
+ import arrow.type.*
+
+ type = ID.Boolean;
+ expectedTraits = BooleanTraits();
+
+ actualTraits = traits(type);
+
+ testCase.verifyEqual(actualTraits, expectedTraits);
+ end
+
+ function TestMatlabUInt8(testCase)
+ import arrow.type.traits.*
+
+ type = "uint8";
+ expectedTraits = UInt8Traits();
+
+ actualTraits = traits(type);
+
+ testCase.verifyEqual(actualTraits, expectedTraits);
+ end
+
+ function TestMatlabUInt16(testCase)
+ import arrow.type.traits.*
+
+ type = "uint16";
+ expectedTraits = UInt16Traits();
+
+ actualTraits = traits(type);
+
+ testCase.verifyEqual(actualTraits, expectedTraits);
+ end
+
+ function TestMatlabUInt32(testCase)
+ import arrow.type.traits.*
+
+ type = "uint32";
+ expectedTraits = UInt32Traits();
+
+ actualTraits = traits(type);
+
+ testCase.verifyEqual(actualTraits, expectedTraits);
+ end
+
+ function TestMatlabUInt64(testCase)
+ import arrow.type.traits.*
+
+ type = "uint64";
+ expectedTraits = UInt64Traits();
+
+ actualTraits = traits(type);
+
+ testCase.verifyEqual(actualTraits, expectedTraits);
+ end
+
+ function TestMatlabInt8(testCase)
+ import arrow.type.traits.*
+
+ type = "int8";
+ expectedTraits = Int8Traits();
+
+ actualTraits = traits(type);
+
+ testCase.verifyEqual(actualTraits, expectedTraits);
+ end
+
+ function TestMatlabInt16(testCase)
+ import arrow.type.traits.*
+
+ type = "int16";
+ expectedTraits = Int16Traits();
+
+ actualTraits = traits(type);
+
+ testCase.verifyEqual(actualTraits, expectedTraits);
+ end
+
+ function TestMatlabInt32(testCase)
+ import arrow.type.traits.*
+
+ type = "int32";
+ expectedTraits = Int32Traits();
+
+ actualTraits = traits(type);
+
+ testCase.verifyEqual(actualTraits, expectedTraits);
+ end
+
+ function TestMatlabInt64(testCase)
+ import arrow.type.traits.*
+
+ type = "int64";
+ expectedTraits = Int64Traits();
+
+ actualTraits = traits(type);
+
+ testCase.verifyEqual(actualTraits, expectedTraits);
+ end
+
+ function TestMatlabSingle(testCase)
+ import arrow.type.traits.*
+
+ type = "single";
+ expectedTraits = Float32Traits();
+
+ actualTraits = traits(type);
+
+ testCase.verifyEqual(actualTraits, expectedTraits);
+ end
+
+ function TestMatlabDouble(testCase)
+ import arrow.type.traits.*
+
+ type = "double";
+ expectedTraits = Float64Traits();
+
+ actualTraits = traits(type);
+
+ testCase.verifyEqual(actualTraits, expectedTraits);
+ end
+
+ function TestMatlabLogical(testCase)
+ import arrow.type.traits.*
+
+ type = "logical";
+ expectedTraits = BooleanTraits();
+
+ actualTraits = traits(type);
+
+ testCase.verifyEqual(actualTraits, expectedTraits);
+ end
+
+ function TestMatlabString(testCase)
+ import arrow.type.traits.*
+
+ type = "string";
+ expectedTraits = StringTraits();
+
+ actualTraits = traits(type);
+
+ testCase.verifyEqual(actualTraits, expectedTraits);
+ end
+
+ function TestMatlabDatetime(testCase)
+ import arrow.type.traits.*
+
+ type = "datetime";
+ expectedTraits = TimestampTraits();
+
+ actualTraits = traits(type);
+
+ testCase.verifyEqual(actualTraits, expectedTraits);
+ end
+
+ function TestErrorIfUnsupportedMatlabClass(testCase)
+ import arrow.type.traits.*
+
+ type = "not-a-class";
+
+ testCase.verifyError(@() traits(type),
"arrow:type:traits:UnsupportedMatlabClass");
+ end
+
+ function TestErrorIfUnsupportedInputType(testCase)
+ import arrow.type.traits.*
+
+ type = 123;
+ testCase.verifyError(@() traits(type),
"arrow:type:traits:UnsupportedInputType");
+
+ type = {'double'};
+ testCase.verifyError(@() traits(type),
"arrow:type:traits:UnsupportedInputType");
+
+ type = datetime(2023, 1, 1);
+ testCase.verifyError(@() traits(type),
"arrow:type:traits:UnsupportedInputType");
+ end
+
+ end
+
+end
\ No newline at end of file