You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by "sgilmore10 (via GitHub)" <gi...@apache.org> on 2023/06/27 19:02:47 UTC

[GitHub] [arrow] sgilmore10 opened a new pull request, #36333: GH-36217: [MATLAB] Add arrow.array.TimestampArray

sgilmore10 opened a new pull request, #36333:
URL: https://github.com/apache/arrow/pull/36333

   ### Rationale for this change
   
   We would like to extend the MATLAB interface to support timestamp data.
   
   ### What changes are included in this PR?
   
   1. Added a new `arrow.array.MATLABArray` class that can be converted to/from a MATLAB `datetime` array.
   2. Added a new type class called `arrow.type.TimestampType`. 
   3. Added a new enum  class called `arrow.type.TimeUnit`.
    
   **Example**
   
   ```matlab
   >> dates = datetime(2023, 6, 27) + days(0:3)'
   
   dates = 
   
     3×1 datetime array
   
      27-Jun-2023
      28-Jun-2023
      29-Jun-2023
   
   >> timestampArray = arrow.array.TimestampArray(dates)
   
   timestampArray = 
   
   [
     2023-06-27 00:00:00.000000,
     2023-06-28 00:00:00.000000,
     2023-06-29 00:00:00.000000
   ]
   
   >> fromArrow = datetime(timestampArray)
   
   fromArrow = 
   
     3×1 datetime array
   
      27-Jun-2023
      28-Jun-2023
      29-Jun-2023
   
   >> isequal(dates, fromArrow)
   
   ans =
   
     logical
   
      1
   ``` 
   
   `TimestampArray` uses `Microsecond` as the default `TimeUnit.` However, you can specify the `TimeUnit` via a name-value pair during construction.
   
   ```matlab
   
   >> timestampArray = arrow.array.TimestampArray(dates, TimeUnit="second")
   
   timestampArray = 
   
   [
     2023-06-27 00:00:00,
     2023-06-28 00:00:00,
     2023-06-29 00:00:00
   ]
   
   >> timestampArray.Type
   
   ans = 
   
     TimestampType with properties:
   
         TimeZone: ""
         TimeUnit: Second
               ID: Timestamp
         BitWidth: 64
        NumFields: 0
       NumBuffers: 2
   ```
   
   The `TimestampArray` is timezone-aware if the MATLAB `datetime` array's TimeZone property is set:
   
   ```matlab
   >> dates = datetime(2023, 6, 27, TimeZone="America/Anchorage") + days(0:3)';
   >> timestampArray = arrow.array.TimestampArray(dates);
   >> timestampArray.Type.TimeZone
   
   ans = 
   
       "America/Anchorage"
   ```
   
   Lastly, `arrow.array.TimestampArray` treats `NaT` as null values by default. However, users can control this behavior by supplying either `InferNulls` or `Valid` as name-value pairs.
   
   ```matlab
   >> dates = [datetime(2023, 6, 27) NaT datetime(2023, 6, 29)];
   >> timestampArray = arrow.array.TimestampArray(dates)
   
   timestampArray = 
   
   [
     2023-06-27 00:00:00.000000,
     null,
     2023-06-29 00:00:00.000000
   ]
   
   >> timestampArray = arrow.array.TimestampArray(dates, Valid=3)
   
   timestampArray = 
   
   [
     null,
     null,
     2023-06-29 00:00:00.000000
   ]
   ```
   
   ### Are these changes tested?
   
   Added three new test files:
   
   1. `tTimestampArray.m`
   2.`tTimestampType.m`
   3. `tTimeUnit.m`
   
   ### Are there any user-facing changes?
   Yes.
   
   1. Added `arrow.array.TimestampArray`
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [arrow] sgilmore10 commented on a diff in pull request #36333: GH-36217: [MATLAB] Add arrow.array.TimestampArray

Posted by "sgilmore10 (via GitHub)" <gi...@apache.org>.
sgilmore10 commented on code in PR #36333:
URL: https://github.com/apache/arrow/pull/36333#discussion_r1244514853


##########
matlab/src/cpp/arrow/matlab/array/proxy/timestamp_array.cc:
##########
@@ -0,0 +1,92 @@
+// 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.
+
+#include "arrow/matlab/array/proxy/timestamp_array.h"
+
+#include "arrow/matlab/error/error.h"
+#include "arrow/matlab/bit/pack.h"
+#include "arrow/matlab/bit/unpack.h"
+
+#include "arrow/matlab/type/time_unit.h"
+#include "arrow/util/utf8.h"
+#include "arrow/type.h"
+#include "arrow/builder.h"
+
+
+namespace arrow::matlab::array::proxy {
+
+    namespace {
+        const uint8_t* getUnpackedValidityBitmap(const ::matlab::data::TypedArray<bool>& valid_elements) {

Review Comment:
   Thanks @kou! I've made an [issue](https://github.com/apache/arrow/issues/36335) to track this.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [arrow] kou commented on a diff in pull request #36333: GH-36217: [MATLAB] Add arrow.array.TimestampArray

Posted by "kou (via GitHub)" <gi...@apache.org>.
kou commented on code in PR #36333:
URL: https://github.com/apache/arrow/pull/36333#discussion_r1244287980


##########
matlab/src/cpp/arrow/matlab/array/proxy/timestamp_array.cc:
##########
@@ -0,0 +1,92 @@
+// 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.
+
+#include "arrow/matlab/array/proxy/timestamp_array.h"
+
+#include "arrow/matlab/error/error.h"
+#include "arrow/matlab/bit/pack.h"
+#include "arrow/matlab/bit/unpack.h"
+
+#include "arrow/matlab/type/time_unit.h"
+#include "arrow/util/utf8.h"
+#include "arrow/type.h"
+#include "arrow/builder.h"
+
+
+namespace arrow::matlab::array::proxy {
+
+    namespace {
+        const uint8_t* getUnpackedValidityBitmap(const ::matlab::data::TypedArray<bool>& valid_elements) {

Review Comment:
   Can we unify this and a similar function in `numeric_array.h`?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [arrow] kou merged pull request #36333: GH-36217: [MATLAB] Add arrow.array.TimestampArray

Posted by "kou (via GitHub)" <gi...@apache.org>.
kou merged PR #36333:
URL: https://github.com/apache/arrow/pull/36333


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [arrow] sgilmore10 commented on a diff in pull request #36333: GH-36217: [MATLAB] Add arrow.array.TimestampArray

Posted by "sgilmore10 (via GitHub)" <gi...@apache.org>.
sgilmore10 commented on code in PR #36333:
URL: https://github.com/apache/arrow/pull/36333#discussion_r1244328596


##########
matlab/src/cpp/arrow/matlab/array/proxy/timestamp_array.cc:
##########
@@ -0,0 +1,92 @@
+// 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.
+
+#include "arrow/matlab/array/proxy/timestamp_array.h"
+
+#include "arrow/matlab/error/error.h"
+#include "arrow/matlab/bit/pack.h"
+#include "arrow/matlab/bit/unpack.h"
+
+#include "arrow/matlab/type/time_unit.h"
+#include "arrow/util/utf8.h"
+#include "arrow/type.h"
+#include "arrow/builder.h"
+
+
+namespace arrow::matlab::array::proxy {
+
+    namespace {
+        const uint8_t* getUnpackedValidityBitmap(const ::matlab::data::TypedArray<bool>& valid_elements) {

Review Comment:
   Definitely! That's a good idea.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [arrow] kou commented on a diff in pull request #36333: GH-36217: [MATLAB] Add arrow.array.TimestampArray

Posted by "kou (via GitHub)" <gi...@apache.org>.
kou commented on code in PR #36333:
URL: https://github.com/apache/arrow/pull/36333#discussion_r1244503119


##########
matlab/src/cpp/arrow/matlab/array/proxy/timestamp_array.cc:
##########
@@ -0,0 +1,92 @@
+// 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.
+
+#include "arrow/matlab/array/proxy/timestamp_array.h"
+
+#include "arrow/matlab/error/error.h"
+#include "arrow/matlab/bit/pack.h"
+#include "arrow/matlab/bit/unpack.h"
+
+#include "arrow/matlab/type/time_unit.h"
+#include "arrow/util/utf8.h"
+#include "arrow/type.h"
+#include "arrow/builder.h"
+
+
+namespace arrow::matlab::array::proxy {
+
+    namespace {
+        const uint8_t* getUnpackedValidityBitmap(const ::matlab::data::TypedArray<bool>& valid_elements) {

Review Comment:
   OK. I merge this.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [arrow] conbench-apache-arrow[bot] commented on pull request #36333: GH-36217: [MATLAB] Add arrow.array.TimestampArray

Posted by "conbench-apache-arrow[bot] (via GitHub)" <gi...@apache.org>.
conbench-apache-arrow[bot] commented on PR #36333:
URL: https://github.com/apache/arrow/pull/36333#issuecomment-1615858231

   Conbench analyzed the 6 benchmark runs on commit `0344a2cd`.
   
   There were 3 benchmark results indicating a performance regression:
   
   - Commit Run on `arm64-m6g-linux-compute` at [2023-06-28 01:47:26Z](http://conbench.ursa.dev/compare/runs/1301752082454fb78c2007fff8102376...304fa5241f1b4552b26f9cc4568135e1/)
     - [params=DecodeArrow_Dense/4096, source=cpp-micro, suite=parquet-encoding-benchmark](http://conbench.ursa.dev/compare/benchmarks/0649b65ba0527f3c8000b9f3070f1e50...0649b919bc107b03800085beda739cf2)
     - [params=DecodeArrowNonNull_Dense/4096, source=cpp-micro, suite=parquet-encoding-benchmark](http://conbench.ursa.dev/compare/benchmarks/0649b65b9c23765d80000e397be35d25...0649b919b83b757a80000512895a479f)
   - and 1 more (see the report linked below)
   
   The [full Conbench report](https://github.com/apache/arrow/runs/14706807606) has more details.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [arrow] sgilmore10 commented on a diff in pull request #36333: GH-36217: [MATLAB] Add arrow.array.TimestampArray

Posted by "sgilmore10 (via GitHub)" <gi...@apache.org>.
sgilmore10 commented on code in PR #36333:
URL: https://github.com/apache/arrow/pull/36333#discussion_r1244499347


##########
matlab/src/cpp/arrow/matlab/array/proxy/timestamp_array.cc:
##########
@@ -0,0 +1,92 @@
+// 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.
+
+#include "arrow/matlab/array/proxy/timestamp_array.h"
+
+#include "arrow/matlab/error/error.h"
+#include "arrow/matlab/bit/pack.h"
+#include "arrow/matlab/bit/unpack.h"
+
+#include "arrow/matlab/type/time_unit.h"
+#include "arrow/util/utf8.h"
+#include "arrow/type.h"
+#include "arrow/builder.h"
+
+
+namespace arrow::matlab::array::proxy {
+
+    namespace {
+        const uint8_t* getUnpackedValidityBitmap(const ::matlab::data::TypedArray<bool>& valid_elements) {

Review Comment:
   Actually, it looks like @kevingurney has already done this. He's currently working on adding an `arrow.array.StringArray` class and created a shared utility called [unpacked_as_ptr](https://github.com/mathworks/arrow/blob/cd4c7cc36e2d21894399387fb51ceda9cf86d532/matlab/src/cpp/arrow/matlab/bit/unpack.cc#L42).  Is it alright if I create an issue to use that utility in `timestamp_array.cc` once Kevin's changes are merged? 



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org