You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by "paleolimbot (via GitHub)" <gi...@apache.org> on 2023/07/29 13:25:41 UTC

[GitHub] [arrow-nanoarrow] paleolimbot commented on a diff in pull request #270: Add ArrowArrayViewGetIntervalUnsafe

paleolimbot commented on code in PR #270:
URL: https://github.com/apache/arrow-nanoarrow/pull/270#discussion_r1278296512


##########
src/nanoarrow/array_inline.h:
##########
@@ -928,6 +928,34 @@ static inline struct ArrowBufferView ArrowArrayViewGetBytesUnsafe(
   return view;
 }
 
+static inline void ArrowArrayViewGetIntervalUnsafe(struct ArrowArrayView* array_view,
+                                                   int64_t i, struct ArrowInterval* out) {
+  const uint8_t* data_view = array_view->buffer_views[1].data.as_uint8;
+  switch (array_view->storage_type) {
+    case NANOARROW_TYPE_INTERVAL_MONTHS: {
+      const size_t size = 4;
+      memcpy(&out->months, data_view + i * size, 4);

Review Comment:
   Could the `4`s and `8`s here be `sizeof(int32_t)` and `sizeof(int64_t)` for readability?
   
   ```suggestion
         memcpy(&out->months, data_view + i * size, sizeof(int32_t));
   ```



##########
src/nanoarrow/array_inline.h:
##########
@@ -928,6 +928,34 @@ static inline struct ArrowBufferView ArrowArrayViewGetBytesUnsafe(
   return view;
 }
 
+static inline void ArrowArrayViewGetIntervalUnsafe(struct ArrowArrayView* array_view,
+                                                   int64_t i, struct ArrowInterval* out) {
+  const uint8_t* data_view = array_view->buffer_views[1].data.as_uint8;
+  switch (array_view->storage_type) {
+    case NANOARROW_TYPE_INTERVAL_MONTHS: {
+      const size_t size = 4;
+      memcpy(&out->months, data_view + i * size, 4);
+      break;
+    }
+    case NANOARROW_TYPE_INTERVAL_DAY_TIME: {
+      const size_t size = 8;
+      memcpy(&out->days, data_view + i * size, 4);
+      memcpy(&out->ms, data_view + i * size + 4, 4);
+      break;
+    }
+    case NANOARROW_TYPE_INTERVAL_MONTH_DAY_NANO: {
+      const size_t size = 16;
+      memcpy(&out->months, data_view + i * size, 4);
+      memcpy(&out->days, data_view + i * size + 4, 4);
+      memcpy(&out->ns, data_view + i * size + 8, 8);
+      break;
+    }
+    default:
+      out = NULL;

Review Comment:
   maybe `memset(out, 0, sizeof(struct ArrowInterval)`?



##########
src/nanoarrow/array_test.cc:
##########
@@ -2453,6 +2453,84 @@ TEST(ArrayViewTest, ArrayViewTestGetString) {
   TestGetFromBinary<FixedSizeBinaryBuilder>(fixed_size_builder);
 }
 
+TEST(ArrayViewTest, ArrayViewTestGetIntervalYearMonth) {
+  GTEST_SKIP() << "MonthIntervalBuilder not implemented in Arrow";

Review Comment:
   Would it be possible to copy some code from the previous test you added to build up one of these arrays?



-- 
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