From 10d1ae7cb32e8390b67c6addd2db7119f603c367 Mon Sep 17 00:00:00 2001 From: Sarah Gilmore Date: Thu, 7 Sep 2023 10:13:36 -0400 Subject: [PATCH 1/9] Add abstract, hidden method called preallocateMATLABArray to arrow.type.Type --- matlab/src/matlab/+arrow/+type/Type.m | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/matlab/src/matlab/+arrow/+type/Type.m b/matlab/src/matlab/+arrow/+type/Type.m index 8f4ce4dd6c7..24f83e02670 100644 --- a/matlab/src/matlab/+arrow/+type/Type.m +++ b/matlab/src/matlab/+arrow/+type/Type.m @@ -93,6 +93,10 @@ function displayScalarHandleToDeletedObject(obj) end end + methods(Abstract, Hidden) + data = preallocateMATLABArray(obj, length) + end + methods (Sealed) function tf = isequal(obj, varargin) From 78c424df77ccd1d431fbbe2670b472c39e1de53e Mon Sep 17 00:00:00 2001 From: Sarah Gilmore Date: Thu, 7 Sep 2023 10:15:18 -0400 Subject: [PATCH 2/9] Add preallocateMATLABArray method to TimeType, DateType, BooleanType, StringType, and TimestampType --- matlab/src/matlab/+arrow/+type/BooleanType.m | 6 ++++++ matlab/src/matlab/+arrow/+type/DateType.m | 6 ++++++ matlab/src/matlab/+arrow/+type/StringType.m | 6 ++++++ matlab/src/matlab/+arrow/+type/TimeType.m | 7 +++++++ matlab/src/matlab/+arrow/+type/TimestampType.m | 6 ++++++ 5 files changed, 31 insertions(+) diff --git a/matlab/src/matlab/+arrow/+type/BooleanType.m b/matlab/src/matlab/+arrow/+type/BooleanType.m index 197ab515838..fcc5985ad26 100644 --- a/matlab/src/matlab/+arrow/+type/BooleanType.m +++ b/matlab/src/matlab/+arrow/+type/BooleanType.m @@ -32,4 +32,10 @@ groups = matlab.mixin.util.PropertyGroup(targets); end end + + methods(Hidden) + function data = preallocateMATLABArray(~, length) + data = false([length 1]); + end + end end \ No newline at end of file diff --git a/matlab/src/matlab/+arrow/+type/DateType.m b/matlab/src/matlab/+arrow/+type/DateType.m index ac6ece47ced..513538c8485 100644 --- a/matlab/src/matlab/+arrow/+type/DateType.m +++ b/matlab/src/matlab/+arrow/+type/DateType.m @@ -42,4 +42,10 @@ end end + methods(Hidden) + function data = preallocateMATLABArray(~, length) + data = NaT([length 1]); + end + end + end diff --git a/matlab/src/matlab/+arrow/+type/StringType.m b/matlab/src/matlab/+arrow/+type/StringType.m index 53c73b3e33e..e85e94cf90d 100644 --- a/matlab/src/matlab/+arrow/+type/StringType.m +++ b/matlab/src/matlab/+arrow/+type/StringType.m @@ -32,5 +32,11 @@ groups = matlab.mixin.util.PropertyGroup(targets); end end + + methods(Hidden) + function data = preallocateMATLABArray(~, length) + data = strings(length, 1); + end + end end diff --git a/matlab/src/matlab/+arrow/+type/TimeType.m b/matlab/src/matlab/+arrow/+type/TimeType.m index a0f8beb7049..9e3e4fadbe4 100644 --- a/matlab/src/matlab/+arrow/+type/TimeType.m +++ b/matlab/src/matlab/+arrow/+type/TimeType.m @@ -42,4 +42,11 @@ end end + methods(Hidden) + function data = preallocateMATLABArray(~, length) + data = NaN([length 1]); + data = seconds(data); + end + end + end \ No newline at end of file diff --git a/matlab/src/matlab/+arrow/+type/TimestampType.m b/matlab/src/matlab/+arrow/+type/TimestampType.m index 07e61f95707..8aa9b308edd 100644 --- a/matlab/src/matlab/+arrow/+type/TimestampType.m +++ b/matlab/src/matlab/+arrow/+type/TimestampType.m @@ -47,4 +47,10 @@ groups = matlab.mixin.util.PropertyGroup(targets); end end + + methods(Hidden) + function data = preallocateMATLABArray(obj, length) + data = NaT([length, 1], TimeZone=obj.TimeZone); + end + end end \ No newline at end of file From 8f4727e3f15ecc0add7f9c37ba9c65ca83be70c3 Mon Sep 17 00:00:00 2001 From: Sarah Gilmore Date: Thu, 7 Sep 2023 10:15:53 -0400 Subject: [PATCH 3/9] Add base class NumericType that implements preallocateMATLABArray for all Numeric Types --- matlab/src/matlab/+arrow/+type/NumericType.m | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 matlab/src/matlab/+arrow/+type/NumericType.m diff --git a/matlab/src/matlab/+arrow/+type/NumericType.m b/matlab/src/matlab/+arrow/+type/NumericType.m new file mode 100644 index 00000000000..7ceb0bf6006 --- /dev/null +++ b/matlab/src/matlab/+arrow/+type/NumericType.m @@ -0,0 +1,19 @@ +classdef NumericType < arrow.type.FixedWidthType + + methods + function obj = NumericType(proxy) + arguments + proxy(1, 1) libmexclass.proxy.Proxy + end + + obj@arrow.type.FixedWidthType(proxy); + end + end + + methods(Hidden) + function data = preallocateMATLABArray(obj, length) + traits = arrow.type.traits.traits(obj.Type.ID); + data = zeros([length 1], traits.MatlabClassName); + end + end +end \ No newline at end of file From e5ac23281921909f4ebcd7a21201f005fbc392f7 Mon Sep 17 00:00:00 2001 From: Sarah Gilmore Date: Thu, 7 Sep 2023 10:22:45 -0400 Subject: [PATCH 4/9] Update all type classes representing numeric types to inherit from NumericType --- matlab/src/matlab/+arrow/+type/Float32Type.m | 7 ++++--- matlab/src/matlab/+arrow/+type/Float64Type.m | 7 ++++--- matlab/src/matlab/+arrow/+type/Int16Type.m | 7 ++++--- matlab/src/matlab/+arrow/+type/Int32Type.m | 7 ++++--- matlab/src/matlab/+arrow/+type/Int64Type.m | 7 ++++--- matlab/src/matlab/+arrow/+type/Int8Type.m | 7 ++++--- matlab/src/matlab/+arrow/+type/NumericType.m | 2 +- matlab/src/matlab/+arrow/+type/UInt16Type.m | 7 ++++--- matlab/src/matlab/+arrow/+type/UInt32Type.m | 7 ++++--- matlab/src/matlab/+arrow/+type/UInt64Type.m | 7 ++++--- matlab/src/matlab/+arrow/+type/UInt8Type.m | 7 ++++--- 11 files changed, 41 insertions(+), 31 deletions(-) diff --git a/matlab/src/matlab/+arrow/+type/Float32Type.m b/matlab/src/matlab/+arrow/+type/Float32Type.m index 98c9f5fd79a..c5abda031de 100644 --- a/matlab/src/matlab/+arrow/+type/Float32Type.m +++ b/matlab/src/matlab/+arrow/+type/Float32Type.m @@ -1,3 +1,5 @@ +%FLOAT32TYPE Type class for float32 data. + % 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. @@ -13,8 +15,7 @@ % implied. See the License for the specific language governing % permissions and limitations under the License. -classdef Float32Type < arrow.type.FixedWidthType -%FLOAT32TYPE Type class for float32 data. +classdef Float32Type < arrow.type.NumericType methods function obj = Float32Type(proxy) @@ -22,7 +23,7 @@ proxy(1, 1) libmexclass.proxy.Proxy {validate(proxy, "arrow.type.proxy.Float32Type")} end import arrow.internal.proxy.validate - obj@arrow.type.FixedWidthType(proxy); + obj@arrow.type.NumericType(proxy); end end diff --git a/matlab/src/matlab/+arrow/+type/Float64Type.m b/matlab/src/matlab/+arrow/+type/Float64Type.m index 634e7d1a5cc..1350301d1e3 100644 --- a/matlab/src/matlab/+arrow/+type/Float64Type.m +++ b/matlab/src/matlab/+arrow/+type/Float64Type.m @@ -1,3 +1,5 @@ +%FLOAT64TYPE Type class for float64 data. + % 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. @@ -13,8 +15,7 @@ % implied. See the License for the specific language governing % permissions and limitations under the License. -classdef Float64Type < arrow.type.FixedWidthType -%FLOAT64Type Type class for float64 data. +classdef Float64Type < arrow.type.NumericType methods function obj = Float64Type(proxy) @@ -22,7 +23,7 @@ proxy(1, 1) libmexclass.proxy.Proxy {validate(proxy, "arrow.type.proxy.Float64Type")} end import arrow.internal.proxy.validate - obj@arrow.type.FixedWidthType(proxy); + obj@arrow.type.NumericType(proxy); end end diff --git a/matlab/src/matlab/+arrow/+type/Int16Type.m b/matlab/src/matlab/+arrow/+type/Int16Type.m index ca59f1c0778..afed4dfc332 100644 --- a/matlab/src/matlab/+arrow/+type/Int16Type.m +++ b/matlab/src/matlab/+arrow/+type/Int16Type.m @@ -1,3 +1,5 @@ +%INT16TYPE Type class for int16 data. + % 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. @@ -13,11 +15,10 @@ % implied. See the License for the specific language governing % permissions and limitations under the License. -classdef Int16Type < arrow.type.FixedWidthType -%INT16TYPE Type class for int8 data. +classdef Int16Type < arrow.type.NumericType methods - function obj = Int16Type(proxy) + function obj = NumericType(proxy) arguments proxy(1, 1) libmexclass.proxy.Proxy {validate(proxy, "arrow.type.proxy.Int16Type")} end diff --git a/matlab/src/matlab/+arrow/+type/Int32Type.m b/matlab/src/matlab/+arrow/+type/Int32Type.m index 68036d64859..f641c3bdeb7 100644 --- a/matlab/src/matlab/+arrow/+type/Int32Type.m +++ b/matlab/src/matlab/+arrow/+type/Int32Type.m @@ -1,3 +1,5 @@ +%INT32TYPE Type class for int32 data. + % 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. @@ -13,8 +15,7 @@ % implied. See the License for the specific language governing % permissions and limitations under the License. -classdef Int32Type < arrow.type.FixedWidthType -%INT32TYPE Type class for int32 data. +classdef Int32Type < arrow.type.NumericType methods function obj = Int32Type(proxy) @@ -22,7 +23,7 @@ proxy(1, 1) libmexclass.proxy.Proxy {validate(proxy, "arrow.type.proxy.Int32Type")} end import arrow.internal.proxy.validate - obj@arrow.type.FixedWidthType(proxy); + obj@arrow.type.NumericType(proxy); end end diff --git a/matlab/src/matlab/+arrow/+type/Int64Type.m b/matlab/src/matlab/+arrow/+type/Int64Type.m index d5bd7ff3a56..70eb9560d0c 100644 --- a/matlab/src/matlab/+arrow/+type/Int64Type.m +++ b/matlab/src/matlab/+arrow/+type/Int64Type.m @@ -1,3 +1,5 @@ +%INT64TYPE Type class for int64 data. + % 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. @@ -13,8 +15,7 @@ % implied. See the License for the specific language governing % permissions and limitations under the License. -classdef Int64Type < arrow.type.FixedWidthType -%INT64TYPE Type class for int64 data. +classdef Int64Type < arrow.type.NumericType methods function obj = Int64Type(proxy) @@ -22,7 +23,7 @@ proxy(1, 1) libmexclass.proxy.Proxy {validate(proxy, "arrow.type.proxy.Int64Type")} end import arrow.internal.proxy.validate - obj@arrow.type.FixedWidthType(proxy); + obj@arrow.type.NumericType(proxy); end end diff --git a/matlab/src/matlab/+arrow/+type/Int8Type.m b/matlab/src/matlab/+arrow/+type/Int8Type.m index 5df75afe760..14c031e5a80 100644 --- a/matlab/src/matlab/+arrow/+type/Int8Type.m +++ b/matlab/src/matlab/+arrow/+type/Int8Type.m @@ -1,3 +1,5 @@ +%INT8TYPE Type class for int8 data. + % 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. @@ -13,8 +15,7 @@ % implied. See the License for the specific language governing % permissions and limitations under the License. -classdef Int8Type < arrow.type.FixedWidthType -%INT8TYPE Type class for int8 data. +classdef Int8Type < arrow.type.NumericType methods function obj = Int8Type(proxy) @@ -22,7 +23,7 @@ proxy(1, 1) libmexclass.proxy.Proxy {validate(proxy, "arrow.type.proxy.Int8Type")} end import arrow.internal.proxy.validate - obj@arrow.type.FixedWidthType(proxy); + obj@arrow.type.NumericType(proxy); end end diff --git a/matlab/src/matlab/+arrow/+type/NumericType.m b/matlab/src/matlab/+arrow/+type/NumericType.m index 7ceb0bf6006..c1c19666fbf 100644 --- a/matlab/src/matlab/+arrow/+type/NumericType.m +++ b/matlab/src/matlab/+arrow/+type/NumericType.m @@ -12,7 +12,7 @@ methods(Hidden) function data = preallocateMATLABArray(obj, length) - traits = arrow.type.traits.traits(obj.Type.ID); + traits = arrow.type.traits.traits(obj.ID); data = zeros([length 1], traits.MatlabClassName); end end diff --git a/matlab/src/matlab/+arrow/+type/UInt16Type.m b/matlab/src/matlab/+arrow/+type/UInt16Type.m index d7600c982bc..78cd83f9d51 100644 --- a/matlab/src/matlab/+arrow/+type/UInt16Type.m +++ b/matlab/src/matlab/+arrow/+type/UInt16Type.m @@ -1,3 +1,5 @@ +%UINT16TYPE Type class for uint16 data. + % 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. @@ -13,8 +15,7 @@ % implied. See the License for the specific language governing % permissions and limitations under the License. -classdef UInt16Type < arrow.type.FixedWidthType -%UINT16TYPE Type class for uint16 data. +classdef UInt16Type < arrow.type.NumericType methods function obj = UInt16Type(proxy) @@ -22,7 +23,7 @@ proxy(1, 1) libmexclass.proxy.Proxy {validate(proxy, "arrow.type.proxy.UInt16Type")} end import arrow.internal.proxy.validate - obj@arrow.type.FixedWidthType(proxy); + obj@arrow.type.NumericType(proxy); end end diff --git a/matlab/src/matlab/+arrow/+type/UInt32Type.m b/matlab/src/matlab/+arrow/+type/UInt32Type.m index e16699cba5c..9598eadf263 100644 --- a/matlab/src/matlab/+arrow/+type/UInt32Type.m +++ b/matlab/src/matlab/+arrow/+type/UInt32Type.m @@ -1,3 +1,5 @@ +%UINT32TYPE Type class for uint32 data. + % 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. @@ -13,8 +15,7 @@ % implied. See the License for the specific language governing % permissions and limitations under the License. -classdef UInt32Type < arrow.type.FixedWidthType -%UINT32TYPE Type class for uint32 data. +classdef UInt32Type < arrow.type.NumericType methods function obj = UInt32Type(proxy) @@ -22,7 +23,7 @@ proxy(1, 1) libmexclass.proxy.Proxy {validate(proxy, "arrow.type.proxy.UInt32Type")} end import arrow.internal.proxy.validate - obj@arrow.type.FixedWidthType(proxy); + obj@arrow.type.NumericType(proxy); end end diff --git a/matlab/src/matlab/+arrow/+type/UInt64Type.m b/matlab/src/matlab/+arrow/+type/UInt64Type.m index c190f252ab4..a61bb388196 100644 --- a/matlab/src/matlab/+arrow/+type/UInt64Type.m +++ b/matlab/src/matlab/+arrow/+type/UInt64Type.m @@ -1,3 +1,5 @@ +%UINT64TYPE Type class for uint64 data. + % 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. @@ -13,8 +15,7 @@ % implied. See the License for the specific language governing % permissions and limitations under the License. -classdef UInt64Type < arrow.type.FixedWidthType -%UINT64TYPE Type class for uint64 data. +classdef UInt64Type < arrow.type.NumericType methods function obj = UInt64Type(proxy) @@ -22,7 +23,7 @@ proxy(1, 1) libmexclass.proxy.Proxy {validate(proxy, "arrow.type.proxy.UInt64Type")} end import arrow.internal.proxy.validate - obj@arrow.type.FixedWidthType(proxy); + obj@arrow.type.NumericType(proxy); end end diff --git a/matlab/src/matlab/+arrow/+type/UInt8Type.m b/matlab/src/matlab/+arrow/+type/UInt8Type.m index 89715991ed5..75626e55624 100644 --- a/matlab/src/matlab/+arrow/+type/UInt8Type.m +++ b/matlab/src/matlab/+arrow/+type/UInt8Type.m @@ -1,3 +1,5 @@ +%UINT8TYPE Type class for uint8 data. + % 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. @@ -13,8 +15,7 @@ % implied. See the License for the specific language governing % permissions and limitations under the License. -classdef UInt8Type < arrow.type.FixedWidthType -%UINT8TYPE Type class for uint8 data. +classdef UInt8Type < arrow.type.NumericType methods function obj = UInt8Type(proxy) @@ -22,7 +23,7 @@ proxy(1, 1) libmexclass.proxy.Proxy {validate(proxy, "arrow.type.proxy.UInt8Type")} end import arrow.internal.proxy.validate - obj@arrow.type.FixedWidthType(proxy); + obj@arrow.type.NumericType(proxy); end end From 580e0beeede10bc6bd2439608bfcadf4525bde4e Mon Sep 17 00:00:00 2001 From: Sarah Gilmore Date: Thu, 7 Sep 2023 10:26:48 -0400 Subject: [PATCH 5/9] Implement getDisplayPropertyGroups on NumericType --- matlab/src/matlab/+arrow/+type/Float32Type.m | 7 ------- matlab/src/matlab/+arrow/+type/Float64Type.m | 7 ------- matlab/src/matlab/+arrow/+type/Int16Type.m | 7 ------- matlab/src/matlab/+arrow/+type/Int32Type.m | 7 ------- matlab/src/matlab/+arrow/+type/Int64Type.m | 7 ------- matlab/src/matlab/+arrow/+type/Int8Type.m | 7 ------- matlab/src/matlab/+arrow/+type/NumericType.m | 7 +++++++ matlab/src/matlab/+arrow/+type/UInt16Type.m | 8 -------- matlab/src/matlab/+arrow/+type/UInt32Type.m | 8 -------- matlab/src/matlab/+arrow/+type/UInt64Type.m | 7 ------- matlab/src/matlab/+arrow/+type/UInt8Type.m | 7 ------- 11 files changed, 7 insertions(+), 72 deletions(-) diff --git a/matlab/src/matlab/+arrow/+type/Float32Type.m b/matlab/src/matlab/+arrow/+type/Float32Type.m index c5abda031de..14b9187ca6b 100644 --- a/matlab/src/matlab/+arrow/+type/Float32Type.m +++ b/matlab/src/matlab/+arrow/+type/Float32Type.m @@ -26,11 +26,4 @@ obj@arrow.type.NumericType(proxy); end end - - methods (Access=protected) - function groups = getDisplayPropertyGroups(~) - targets = "ID"; - groups = matlab.mixin.util.PropertyGroup(targets); - end - end end \ No newline at end of file diff --git a/matlab/src/matlab/+arrow/+type/Float64Type.m b/matlab/src/matlab/+arrow/+type/Float64Type.m index 1350301d1e3..7c934b784e8 100644 --- a/matlab/src/matlab/+arrow/+type/Float64Type.m +++ b/matlab/src/matlab/+arrow/+type/Float64Type.m @@ -26,11 +26,4 @@ obj@arrow.type.NumericType(proxy); end end - - methods (Access=protected) - function groups = getDisplayPropertyGroups(~) - targets = "ID"; - groups = matlab.mixin.util.PropertyGroup(targets); - end - end end \ No newline at end of file diff --git a/matlab/src/matlab/+arrow/+type/Int16Type.m b/matlab/src/matlab/+arrow/+type/Int16Type.m index afed4dfc332..0ed37f9d0b5 100644 --- a/matlab/src/matlab/+arrow/+type/Int16Type.m +++ b/matlab/src/matlab/+arrow/+type/Int16Type.m @@ -26,12 +26,5 @@ obj@arrow.type.FixedWidthType(proxy); end end - - methods (Access=protected) - function groups = getDisplayPropertyGroups(~) - targets = "ID"; - groups = matlab.mixin.util.PropertyGroup(targets); - end - end end diff --git a/matlab/src/matlab/+arrow/+type/Int32Type.m b/matlab/src/matlab/+arrow/+type/Int32Type.m index f641c3bdeb7..2f1a6549158 100644 --- a/matlab/src/matlab/+arrow/+type/Int32Type.m +++ b/matlab/src/matlab/+arrow/+type/Int32Type.m @@ -26,12 +26,5 @@ obj@arrow.type.NumericType(proxy); end end - - methods (Access=protected) - function groups = getDisplayPropertyGroups(~) - targets = "ID"; - groups = matlab.mixin.util.PropertyGroup(targets); - end - end end diff --git a/matlab/src/matlab/+arrow/+type/Int64Type.m b/matlab/src/matlab/+arrow/+type/Int64Type.m index 70eb9560d0c..52cd30ac3eb 100644 --- a/matlab/src/matlab/+arrow/+type/Int64Type.m +++ b/matlab/src/matlab/+arrow/+type/Int64Type.m @@ -26,11 +26,4 @@ obj@arrow.type.NumericType(proxy); end end - - methods (Access=protected) - function groups = getDisplayPropertyGroups(~) - targets = "ID"; - groups = matlab.mixin.util.PropertyGroup(targets); - end - end end \ No newline at end of file diff --git a/matlab/src/matlab/+arrow/+type/Int8Type.m b/matlab/src/matlab/+arrow/+type/Int8Type.m index 14c031e5a80..bf07d0de449 100644 --- a/matlab/src/matlab/+arrow/+type/Int8Type.m +++ b/matlab/src/matlab/+arrow/+type/Int8Type.m @@ -26,12 +26,5 @@ obj@arrow.type.NumericType(proxy); end end - - methods (Access=protected) - function groups = getDisplayPropertyGroups(~) - targets = "ID"; - groups = matlab.mixin.util.PropertyGroup(targets); - end - end end diff --git a/matlab/src/matlab/+arrow/+type/NumericType.m b/matlab/src/matlab/+arrow/+type/NumericType.m index c1c19666fbf..83b11a290fa 100644 --- a/matlab/src/matlab/+arrow/+type/NumericType.m +++ b/matlab/src/matlab/+arrow/+type/NumericType.m @@ -16,4 +16,11 @@ data = zeros([length 1], traits.MatlabClassName); end end + + methods (Access=protected) + function groups = getDisplayPropertyGroups(~) + targets = "ID"; + groups = matlab.mixin.util.PropertyGroup(targets); + end + end end \ No newline at end of file diff --git a/matlab/src/matlab/+arrow/+type/UInt16Type.m b/matlab/src/matlab/+arrow/+type/UInt16Type.m index 78cd83f9d51..abe40d1824e 100644 --- a/matlab/src/matlab/+arrow/+type/UInt16Type.m +++ b/matlab/src/matlab/+arrow/+type/UInt16Type.m @@ -26,12 +26,4 @@ obj@arrow.type.NumericType(proxy); end end - - - methods (Access=protected) - function groups = getDisplayPropertyGroups(~) - targets = "ID"; - groups = matlab.mixin.util.PropertyGroup(targets); - end - end end \ No newline at end of file diff --git a/matlab/src/matlab/+arrow/+type/UInt32Type.m b/matlab/src/matlab/+arrow/+type/UInt32Type.m index 9598eadf263..a81c70aa43d 100644 --- a/matlab/src/matlab/+arrow/+type/UInt32Type.m +++ b/matlab/src/matlab/+arrow/+type/UInt32Type.m @@ -26,12 +26,4 @@ obj@arrow.type.NumericType(proxy); end end - - - methods (Access=protected) - function groups = getDisplayPropertyGroups(~) - targets = "ID"; - groups = matlab.mixin.util.PropertyGroup(targets); - end - end end \ No newline at end of file diff --git a/matlab/src/matlab/+arrow/+type/UInt64Type.m b/matlab/src/matlab/+arrow/+type/UInt64Type.m index a61bb388196..488120c5fae 100644 --- a/matlab/src/matlab/+arrow/+type/UInt64Type.m +++ b/matlab/src/matlab/+arrow/+type/UInt64Type.m @@ -26,11 +26,4 @@ obj@arrow.type.NumericType(proxy); end end - - methods (Access=protected) - function groups = getDisplayPropertyGroups(~) - targets = "ID"; - groups = matlab.mixin.util.PropertyGroup(targets); - end - end end \ No newline at end of file diff --git a/matlab/src/matlab/+arrow/+type/UInt8Type.m b/matlab/src/matlab/+arrow/+type/UInt8Type.m index 75626e55624..e7a87569942 100644 --- a/matlab/src/matlab/+arrow/+type/UInt8Type.m +++ b/matlab/src/matlab/+arrow/+type/UInt8Type.m @@ -26,11 +26,4 @@ obj@arrow.type.NumericType(proxy); end end - - methods (Access=protected) - function groups = getDisplayPropertyGroups(~) - targets = "ID"; - groups = matlab.mixin.util.PropertyGroup(targets); - end - end end \ No newline at end of file From a754845d9adff33415506584cdcdbdf7baa93255 Mon Sep 17 00:00:00 2001 From: Sarah Gilmore Date: Thu, 7 Sep 2023 10:56:04 -0400 Subject: [PATCH 6/9] Fix typo in Int16Type.m --- matlab/src/matlab/+arrow/+type/Int16Type.m | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/matlab/src/matlab/+arrow/+type/Int16Type.m b/matlab/src/matlab/+arrow/+type/Int16Type.m index 0ed37f9d0b5..a7343b39050 100644 --- a/matlab/src/matlab/+arrow/+type/Int16Type.m +++ b/matlab/src/matlab/+arrow/+type/Int16Type.m @@ -18,12 +18,12 @@ classdef Int16Type < arrow.type.NumericType methods - function obj = NumericType(proxy) + function obj = Int16Type(proxy) arguments proxy(1, 1) libmexclass.proxy.Proxy {validate(proxy, "arrow.type.proxy.Int16Type")} end import arrow.internal.proxy.validate - obj@arrow.type.FixedWidthType(proxy); + obj@arrow.type.NumericType(proxy); end end end From 8160ef85a402b7b62c529f731d751220e9919387 Mon Sep 17 00:00:00 2001 From: Sarah Gilmore Date: Thu, 7 Sep 2023 11:19:21 -0400 Subject: [PATCH 7/9] Add toMATLAB method to ChunkedArray --- .../src/matlab/+arrow/+array/ChunkedArray.m | 11 + matlab/test/arrow/array/tChunkedArray.m | 223 ++++++++++++++++++ 2 files changed, 234 insertions(+) diff --git a/matlab/src/matlab/+arrow/+array/ChunkedArray.m b/matlab/src/matlab/+arrow/+array/ChunkedArray.m index e6ee812866f..96d7bb57a40 100644 --- a/matlab/src/matlab/+arrow/+array/ChunkedArray.m +++ b/matlab/src/matlab/+arrow/+array/ChunkedArray.m @@ -60,6 +60,17 @@ array = traits.ArrayConstructor(proxy); end + function data = toMATLAB(obj) + data = preallocateMATLABArray(obj.Type, obj.Length); + startIndex = 1; + for ii = 1:obj.NumChunks + chunk = obj.chunk(ii); + endIndex = startIndex + chunk.Length - 1; + data(startIndex:endIndex) = toMATLAB(chunk); + startIndex = endIndex + 1; + end + end + function tf = isequal(obj, varargin) narginchk(2, inf); diff --git a/matlab/test/arrow/array/tChunkedArray.m b/matlab/test/arrow/array/tChunkedArray.m index e075d0c31ae..bc010697759 100644 --- a/matlab/test/arrow/array/tChunkedArray.m +++ b/matlab/test/arrow/array/tChunkedArray.m @@ -24,6 +24,21 @@ Float64Type = arrow.float64() end + properties(TestParameter) + IntegerMatlabClass = {"uint8", ... + "uint16", ... + "uint32", ... + "uint64", ... + "int8", ... + "int16", ... + "int32", ... + "int64"}; + + FloatMatlabClass = {"single", "double"} + + TimeZone = {"America/New_York", ""} + end + methods (Test) function FromArraysTooFewInputsError(testCase) % Verify an error is thrown when neither the Type nv-pair nor @@ -240,6 +255,214 @@ function NumericIndexEmptyChunkedArrayError(testCase) fcn = @() chunkedArray.chunk(2); testCase.verifyError(fcn, "arrow:chunkedarray:NumericIndexWithEmptyChunkedArray"); end + + function ToMATLABBooleanType(testCase) + % Verify toMATLAB returns the expected MATLAB array when the + % Chunked Array contains boolean arrays. + import arrow.array.ChunkedArray + + bools = true([1 11]); + bools([2 3 7 8 9]) = false; + a1 = arrow.array(bools(1:8)); + a2 = arrow.array(bools(8:7)); + a3 = arrow.array(bools(9:11)); + + % ChunkedArray with three chunks and nonzero length + chunkedArray1 = ChunkedArray.fromArrays(a1, a2, a3); + actualArray1 = toMATLAB(chunkedArray1); + expectedArray1 = bools'; + testCase.verifyEqual(actualArray1, expectedArray1); + + % ChunkedArray with zero chunks and zero length + chunkedArray2 = ChunkedArray.fromArrays(Type=a1.Type); + actualArray2 = toMATLAB(chunkedArray2); + expectedArray2 = logical.empty(0, 1); + testCase.verifyEqual(actualArray2, expectedArray2); + + % ChunkedArray with two chunks and zero length + chunkedArray3 = ChunkedArray.fromArrays(a2, a2); + actualArray3 = toMATLAB(chunkedArray3); + expectedArray3 = logical.empty(0, 1); + testCase.verifyEqual(actualArray3, expectedArray3); + end + + function ToMATLABIntegerTypes(testCase, IntegerMatlabClass) + % Verify toMATLAB returns the expected MATLAB array when the + % Chunked Array contains integer arrays. + import arrow.array.ChunkedArray + + a1 = arrow.array(cast([1 2 3 4], IntegerMatlabClass)); + a2 = arrow.array(cast([], IntegerMatlabClass)); + a3 = arrow.array(cast([5 6 7 8 9], IntegerMatlabClass)); + + % ChunkedArray with three chunks and nonzero length + chunkedArray1 = ChunkedArray.fromArrays(a1, a2, a3); + actualArray1 = toMATLAB(chunkedArray1); + expectedArray1 = cast((1:9)', IntegerMatlabClass); + testCase.verifyEqual(actualArray1, expectedArray1); + + % ChunkedArray with zero chunks and zero length + chunkedArray2 = ChunkedArray.fromArrays(Type=a1.Type); + actualArray2 = toMATLAB(chunkedArray2); + expectedArray2 = cast(double.empty(0, 1), IntegerMatlabClass); + testCase.verifyEqual(actualArray2, expectedArray2); + + % ChunkedArray with two chunks and zero length + chunkedArray3 = ChunkedArray.fromArrays(a2, a2); + actualArray3 = toMATLAB(chunkedArray3); + expectedArray3 = cast(double.empty(0, 1), IntegerMatlabClass); + testCase.verifyEqual(actualArray3, expectedArray3); + end + + function ToMATLABFloatTypes(testCase, FloatMatlabClass) + % Verify toMATLAB returns the expected MATLAB array when the + % Chunked Array contains float arrays. + import arrow.array.ChunkedArray + + a1 = arrow.array(cast([1 NaN 3 4], FloatMatlabClass)); + a2 = arrow.array(cast([], FloatMatlabClass)); + a3 = arrow.array(cast([5 6 7 NaN 9], FloatMatlabClass)); + + % ChunkedArray with three chunks and nonzero length + chunkedArray1 = ChunkedArray.fromArrays(a1, a2, a3); + actualArray1 = toMATLAB(chunkedArray1); + expectedArray1 = cast((1:9)', FloatMatlabClass); + expectedArray1([2 8]) = NaN; + testCase.verifyEqual(actualArray1, expectedArray1); + + % ChunkedArray with zero chunks and zero length + chunkedArray2 = ChunkedArray.fromArrays(Type=a1.Type); + actualArray2 = toMATLAB(chunkedArray2); + expectedArray2 = cast(double.empty(0, 1), FloatMatlabClass); + testCase.verifyEqual(actualArray2, expectedArray2); + + % ChunkedArray with two chunks and zero length + chunkedArray3 = ChunkedArray.fromArrays(a2, a2); + actualArray3 = toMATLAB(chunkedArray3); + expectedArray3 = cast(double.empty(0, 1), FloatMatlabClass); + testCase.verifyEqual(actualArray3, expectedArray3); + end + + function ToMATLABTimeTypes(testCase) + % Verify toMATLAB returns the expected MATLAB array when the + % Chunked Array contains time arrays. + import arrow.array.ChunkedArray + + a1 = arrow.array(seconds([1 NaN 3 4])); + a2 = arrow.array(seconds([])); + a3 = arrow.array(seconds([5 6 7 NaN 9])); + + % ChunkedArray with three chunks and nonzero length + chunkedArray1 = ChunkedArray.fromArrays(a1, a2, a3); + actualArray1 = toMATLAB(chunkedArray1); + expectedArray1 = seconds((1:9)'); + expectedArray1([2 8]) = NaN; + testCase.verifyEqual(actualArray1, expectedArray1); + + % ChunkedArray with zero chunks and zero length + chunkedArray2 = ChunkedArray.fromArrays(Type=a1.Type); + actualArray2 = toMATLAB(chunkedArray2); + expectedArray2 = duration.empty(0, 1); + testCase.verifyEqual(actualArray2, expectedArray2); + + % ChunkedArray with two chunks and zero length + chunkedArray3 = ChunkedArray.fromArrays(a2, a2); + actualArray3 = toMATLAB(chunkedArray3); + expectedArray3 = duration.empty(0, 1); + testCase.verifyEqual(actualArray3, expectedArray3); + end + + function ToMATLABDateTypes(testCase) + % Verify toMATLAB returns the expected MATLAB array when the + % Chunked Array contains date arrays. + import arrow.array.* + + dates = datetime(2023, 9, 7) + days(0:10); + dates([5 9]) = NaT; + a1 = Date64Array.fromMATLAB(dates(1:5)); + a2 = Date64Array.fromMATLAB(dates(6:5)); + a3 = Date64Array.fromMATLAB(dates(6:end)); + + % ChunkedArray with three chunks and nonzero length + chunkedArray1 = ChunkedArray.fromArrays(a1, a2, a3); + actualArray1 = toMATLAB(chunkedArray1); + expectedArray1 = dates'; + testCase.verifyEqual(actualArray1, expectedArray1); + + % ChunkedArray with zero chunks and zero length + chunkedArray2 = ChunkedArray.fromArrays(Type=a1.Type); + actualArray2 = toMATLAB(chunkedArray2); + expectedArray2 = datetime.empty(0, 1); + testCase.verifyEqual(actualArray2, expectedArray2); + + % ChunkedArray with two chunks and zero length + chunkedArray3 = ChunkedArray.fromArrays(a2, a2); + actualArray3 = toMATLAB(chunkedArray3); + expectedArray3 = datetime.empty(0, 1); + testCase.verifyEqual(actualArray3, expectedArray3); + end + + function ToMATLABTimestampType(testCase, TimeZone) + % Verify toMATLAB returns the expected MATLAB array when the + % Chunked Array contains timestamp arrays. + import arrow.array.ChunkedArray + + dates = datetime(2023, 9, 7, TimeZone=TimeZone) + days(0:10); + dates([5 9]) = NaT; + a1 = arrow.array(dates(1:5)); + a2 = arrow.array(dates(6:5)); + a3 = arrow.array(dates(6:end)); + + % ChunkedArray with three chunks and nonzero length + chunkedArray1 = ChunkedArray.fromArrays(a1, a2, a3); + actualArray1 = toMATLAB(chunkedArray1); + expectedArray1 = dates'; + testCase.verifyEqual(actualArray1, expectedArray1); + + % ChunkedArray with zero chunks and zero length + chunkedArray2 = ChunkedArray.fromArrays(Type=a1.Type); + actualArray2 = toMATLAB(chunkedArray2); + expectedArray2 = datetime.empty(0, 1); + expectedArray2.TimeZone = TimeZone; + testCase.verifyEqual(actualArray2, expectedArray2); + + % ChunkedArray with two chunks and zero length + chunkedArray3 = ChunkedArray.fromArrays(a2, a2); + actualArray3 = toMATLAB(chunkedArray3); + expectedArray3 = datetime.empty(0, 1); + expectedArray3.TimeZone = TimeZone; + testCase.verifyEqual(actualArray3, expectedArray3); + end + + function ToMATLABStringType(testCase) + % Verify toMATLAB returns the expected MATLAB array when the + % Chunked Array contains string arrays. + import arrow.array.* + + strs = compose("%d", 1:11); + strs([5 9]) = missing; + a1 = arrow.array(strs(1:7)); + a2 = arrow.array(strs(7:6)); + a3 = arrow.array(strs(8:11)); + + % ChunkedArray with three chunks and nonzero length + chunkedArray1 = ChunkedArray.fromArrays(a1, a2, a3); + actualArray1 = toMATLAB(chunkedArray1); + expectedArray1 = strs'; + testCase.verifyEqual(actualArray1, expectedArray1); + + % ChunkedArray with zero chunks and zero length + chunkedArray2 = ChunkedArray.fromArrays(Type=a1.Type); + actualArray2 = toMATLAB(chunkedArray2); + expectedArray2 = string.empty(0, 1); + testCase.verifyEqual(actualArray2, expectedArray2); + + % ChunkedArray with two chunks and zero length + chunkedArray3 = ChunkedArray.fromArrays(a2, a2); + actualArray3 = toMATLAB(chunkedArray3); + expectedArray3 = string.empty(0, 1); + testCase.verifyEqual(actualArray3, expectedArray3); + end end methods From 2bab750a9d9cda770a392fd1126044e40b253882 Mon Sep 17 00:00:00 2001 From: Sarah Gilmore Date: Thu, 7 Sep 2023 13:04:08 -0400 Subject: [PATCH 8/9] Fix indentation --- matlab/test/arrow/array/tChunkedArray.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/matlab/test/arrow/array/tChunkedArray.m b/matlab/test/arrow/array/tChunkedArray.m index bc010697759..3c7a52501f1 100644 --- a/matlab/test/arrow/array/tChunkedArray.m +++ b/matlab/test/arrow/array/tChunkedArray.m @@ -315,7 +315,7 @@ function ToMATLABIntegerTypes(testCase, IntegerMatlabClass) end function ToMATLABFloatTypes(testCase, FloatMatlabClass) - % Verify toMATLAB returns the expected MATLAB array when the + % Verify toMATLAB returns the expected MATLAB array when the % Chunked Array contains float arrays. import arrow.array.ChunkedArray From 2a750ec9ddce6e7633870fe31ecd78b19ca1d75a Mon Sep 17 00:00:00 2001 From: Sarah Gilmore Date: Thu, 7 Sep 2023 13:13:08 -0400 Subject: [PATCH 9/9] Add license header to NumericType.m --- matlab/src/matlab/+arrow/+type/NumericType.m | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/matlab/src/matlab/+arrow/+type/NumericType.m b/matlab/src/matlab/+arrow/+type/NumericType.m index 83b11a290fa..b23fad7897b 100644 --- a/matlab/src/matlab/+arrow/+type/NumericType.m +++ b/matlab/src/matlab/+arrow/+type/NumericType.m @@ -1,3 +1,20 @@ +%NUMERICTYPE Type class for numeric data + +% 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 NumericType < arrow.type.FixedWidthType methods