in src/nanoarrow/array.c [671:748]
static int ArrowArrayViewSetArrayInternal(struct ArrowArrayView* array_view,
struct ArrowArray* array,
struct ArrowError* error) {
// Check length and offset
if (array->offset < 0) {
ArrowErrorSet(error, "Expected array offset >= 0 but found array offset of %ld",
(long)array->offset);
return EINVAL;
}
if (array->length < 0) {
ArrowErrorSet(error, "Expected array length >= 0 but found array length of %ld",
(long)array->length);
return EINVAL;
}
array_view->array = array;
array_view->offset = array->offset;
array_view->length = array->length;
array_view->null_count = array->null_count;
int64_t buffers_required = 0;
for (int i = 0; i < 3; i++) {
if (array_view->layout.buffer_type[i] == NANOARROW_BUFFER_TYPE_NONE) {
break;
}
buffers_required++;
// Set buffer pointer
array_view->buffer_views[i].data.data = array->buffers[i];
// If non-null, set buffer size to unknown.
if (array->buffers[i] == NULL) {
array_view->buffer_views[i].size_bytes = 0;
} else {
array_view->buffer_views[i].size_bytes = -1;
}
}
// Check the number of buffers
if (buffers_required != array->n_buffers) {
ArrowErrorSet(error, "Expected array with %d buffer(s) but found %d buffer(s)",
(int)buffers_required, (int)array->n_buffers);
return EINVAL;
}
// Check number of children
if (array_view->n_children != array->n_children) {
ArrowErrorSet(error, "Expected %ld children but found %ld children",
(long)array_view->n_children, (long)array->n_children);
return EINVAL;
}
// Recurse for children
for (int64_t i = 0; i < array_view->n_children; i++) {
NANOARROW_RETURN_NOT_OK(ArrowArrayViewSetArrayInternal(array_view->children[i],
array->children[i], error));
}
// Check dictionary
if (array->dictionary == NULL && array_view->dictionary != NULL) {
ArrowErrorSet(error, "Expected dictionary but found NULL");
return EINVAL;
}
if (array->dictionary != NULL && array_view->dictionary == NULL) {
ArrowErrorSet(error, "Expected NULL dictionary but found dictionary member");
return EINVAL;
}
if (array->dictionary != NULL) {
NANOARROW_RETURN_NOT_OK(
ArrowArrayViewSetArrayInternal(array_view->dictionary, array->dictionary, error));
}
return NANOARROW_OK;
}