This is an automated email from the ASF dual-hosted git repository.
github-bot pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/arrow-nanoarrow.git
The following commit(s) were added to refs/heads/main by this push:
new df6d023 Update dist/ for commit
695f08d7a07a64c0e13eb3444d61b2a6a8d8e5df
df6d023 is described below
commit df6d0239e13db3d8c88167706886c39840b8981d
Author: GitHub Actions <[email protected]>
AuthorDate: Thu Dec 8 20:08:38 2022 +0000
Update dist/ for commit 695f08d7a07a64c0e13eb3444d61b2a6a8d8e5df
---
dist/nanoarrow.c | 20 ++++++++++++++++++++
dist/nanoarrow.h | 56 +++++++++++++++++++++++++++++++++++++++++++++++++++++---
2 files changed, 73 insertions(+), 3 deletions(-)
diff --git a/dist/nanoarrow.c b/dist/nanoarrow.c
index d2b3c59..7f9d18c 100644
--- a/dist/nanoarrow.c
+++ b/dist/nanoarrow.c
@@ -2266,6 +2266,22 @@ ArrowErrorCode ArrowArrayViewInitFromSchema(struct
ArrowArrayView* array_view,
}
}
+ if (array_view->storage_type == NANOARROW_TYPE_SPARSE_UNION ||
+ array_view->storage_type == NANOARROW_TYPE_DENSE_UNION) {
+ array_view->union_type_id_map = (int8_t*)ArrowMalloc(256 * sizeof(int8_t));
+ if (array_view->union_type_id_map == NULL) {
+ return ENOMEM;
+ }
+
+ memset(array_view->union_type_id_map, -1, 256);
+ int8_t n_type_ids = _ArrowParseUnionTypeIds(schema_view.union_type_ids,
+ array_view->union_type_id_map
+ 128);
+ for (int8_t child_index = 0; child_index < n_type_ids; child_index++) {
+ int8_t type_id = array_view->union_type_id_map[128 + child_index];
+ array_view->union_type_id_map[type_id] = child_index;
+ }
+ }
+
return NANOARROW_OK;
}
@@ -2281,6 +2297,10 @@ void ArrowArrayViewReset(struct ArrowArrayView*
array_view) {
ArrowFree(array_view->children);
}
+ if (array_view->union_type_id_map != NULL) {
+ ArrowFree(array_view->union_type_id_map);
+ }
+
ArrowArrayViewInitFromType(array_view, NANOARROW_TYPE_UNINITIALIZED);
}
diff --git a/dist/nanoarrow.h b/dist/nanoarrow.h
index ff3ee7c..7f29e71 100644
--- a/dist/nanoarrow.h
+++ b/dist/nanoarrow.h
@@ -29,7 +29,7 @@
// #define NANOARROW_NAMESPACE YourNamespaceHere
-#define NANOARROW_BUILD_ID "ghaec0824dcf064448648cc6eb5ef7873962fa23339"
+#define NANOARROW_BUILD_ID "gha695f08d7a07a64c0e13eb3444d61b2a6a8d8e5df"
#endif
// Licensed to the Apache Software Foundation (ASF) under one
@@ -532,6 +532,13 @@ struct ArrowArrayView {
/// \brief Pointers to views of this array's children
struct ArrowArrayView** children;
+
+ /// \brief Union type id to child index mapping
+ ///
+ /// If storage_type is a union type, a 256-byte ArrowMalloc()ed buffer
+ /// such that child_index == union_type_id_map[type_id] and
+ /// type_id == union_type_id_map[128 + child_index]
+ int8_t* union_type_id_map;
};
// Used as the private data member for ArrowArrays allocated here and accessed
@@ -1473,6 +1480,16 @@ void ArrowArrayViewReset(struct ArrowArrayView*
array_view);
/// \brief Check for a null element in an ArrowArrayView
static inline int8_t ArrowArrayViewIsNull(struct ArrowArrayView* array_view,
int64_t i);
+/// \brief Get the type id of a union array element
+static inline int8_t ArrowArrayViewUnionTypeId(struct ArrowArrayView*
array_view, int64_t i);
+
+/// \brief Get the child index of a union array element
+static inline int8_t ArrowArrayViewUnionChildIndex(struct ArrowArrayView*
array_view, int64_t i);
+
+/// \brief Get the index to use into the relevant union child array
+static inline int64_t ArrowArrayViewUnionChildOffset(struct ArrowArrayView*
array_view,
+ int64_t i);
+
/// \brief Get an element in an ArrowArrayView as an integer
///
/// This function does not check for null values, that values are actually
integers, or
@@ -2669,13 +2686,46 @@ static inline int8_t ArrowArrayViewIsNull(struct
ArrowArrayView* array_view, int
return 0x01;
case NANOARROW_TYPE_DENSE_UNION:
case NANOARROW_TYPE_SPARSE_UNION:
- // Not supported yet
- return -1;
+ // Unions are "never null" in Arrow land
+ return 0x00;
default:
return validity_buffer != NULL && !ArrowBitGet(validity_buffer, i);
}
}
+static inline int8_t ArrowArrayViewUnionTypeId(struct ArrowArrayView*
array_view,
+ int64_t i) {
+ switch (array_view->storage_type) {
+ case NANOARROW_TYPE_DENSE_UNION:
+ case NANOARROW_TYPE_SPARSE_UNION:
+ return array_view->buffer_views[0].data.as_int8[i];
+ default:
+ return -1;
+ }
+}
+
+static inline int8_t ArrowArrayViewUnionChildIndex(struct ArrowArrayView*
array_view,
+ int64_t i) {
+ int8_t type_id = ArrowArrayViewUnionTypeId(array_view, i);
+ if (array_view->union_type_id_map == NULL) {
+ return type_id;
+ } else {
+ return array_view->union_type_id_map[type_id];
+ }
+}
+
+static inline int64_t ArrowArrayViewUnionChildOffset(struct ArrowArrayView*
array_view,
+ int64_t i) {
+ switch (array_view->storage_type) {
+ case NANOARROW_TYPE_DENSE_UNION:
+ return array_view->buffer_views[1].data.as_int32[i];
+ case NANOARROW_TYPE_SPARSE_UNION:
+ return i;
+ default:
+ return -1;
+ }
+}
+
static inline int64_t ArrowArrayViewGetIntUnsafe(struct ArrowArrayView*
array_view,
int64_t i) {
struct ArrowBufferView* data_view = &array_view->buffer_views[1];