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 48a8e8f Update dist/ for commit
36025e25999301f77b0447bee93e00055ff89541
48a8e8f is described below
commit 48a8e8f0dda1f6fa1f627ae4d518187a96e561c3
Author: GitHub Actions <[email protected]>
AuthorDate: Fri Dec 2 19:04:04 2022 +0000
Update dist/ for commit 36025e25999301f77b0447bee93e00055ff89541
---
dist/nanoarrow.c | 152 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
dist/nanoarrow.h | 119 ++++++++++++++++++++++++++++++++++++++++---
2 files changed, 263 insertions(+), 8 deletions(-)
diff --git a/dist/nanoarrow.c b/dist/nanoarrow.c
index 9e85add..703c11a 100644
--- a/dist/nanoarrow.c
+++ b/dist/nanoarrow.c
@@ -2373,3 +2373,155 @@ ArrowErrorCode ArrowArrayViewSetArray(struct
ArrowArrayView* array_view,
return NANOARROW_OK;
}
+// 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 <errno.h>
+
+#include "nanoarrow.h"
+
+struct BasicArrayStreamPrivate {
+ struct ArrowSchema schema;
+ int64_t n_arrays;
+ struct ArrowArray* arrays;
+ int64_t arrays_i;
+};
+
+static int ArrowBasicArrayStreamGetSchema(struct ArrowArrayStream*
array_stream,
+ struct ArrowSchema* schema) {
+ if (array_stream == NULL || array_stream->release == NULL) {
+ return EINVAL;
+ }
+
+ struct BasicArrayStreamPrivate* private =
+ (struct BasicArrayStreamPrivate*)array_stream->private_data;
+ return ArrowSchemaDeepCopy(&private->schema, schema);
+}
+
+static int ArrowBasicArrayStreamGetNext(struct ArrowArrayStream* array_stream,
+ struct ArrowArray* array) {
+ if (array_stream == NULL || array_stream->release == NULL) {
+ return EINVAL;
+ }
+
+ struct BasicArrayStreamPrivate* private =
+ (struct BasicArrayStreamPrivate*)array_stream->private_data;
+
+ if (private->arrays_i == private->n_arrays) {
+ array->release = NULL;
+ return NANOARROW_OK;
+ }
+
+ ArrowArrayMove(&private->arrays[private->arrays_i++], array);
+ return NANOARROW_OK;
+}
+
+static const char* ArrowBasicArrayStreamGetLastError(
+ struct ArrowArrayStream* array_stream) {
+ return NULL;
+}
+
+static void ArrowBasicArrayStreamRelease(struct ArrowArrayStream*
array_stream) {
+ if (array_stream == NULL || array_stream->release == NULL) {
+ return;
+ }
+
+ struct BasicArrayStreamPrivate* private =
+ (struct BasicArrayStreamPrivate*)array_stream->private_data;
+
+ if (private->schema.release != NULL) {
+ private->schema.release(&private->schema);
+ }
+
+ for (int64_t i = 0; i < private->n_arrays; i++) {
+ if (private->arrays[i].release != NULL) {
+ private->arrays[i].release(&private->arrays[i]);
+ }
+ }
+
+ if (private->arrays != NULL) {
+ ArrowFree(private->arrays);
+ }
+
+ ArrowFree(private);
+ array_stream->release = NULL;
+}
+
+ArrowErrorCode ArrowBasicArrayStreamInit(struct ArrowArrayStream* array_stream,
+ struct ArrowSchema* schema, int64_t
n_arrays) {
+ struct BasicArrayStreamPrivate* private = (struct
BasicArrayStreamPrivate*)ArrowMalloc(
+ sizeof(struct BasicArrayStreamPrivate));
+ if (private == NULL) {
+ return ENOMEM;
+ }
+
+ ArrowSchemaMove(schema, &private->schema);
+
+ private->n_arrays = n_arrays;
+ private->arrays = NULL;
+ private->arrays_i = 0;
+
+ if (n_arrays > 0) {
+ private->arrays =
+ (struct ArrowArray*)ArrowMalloc(n_arrays * sizeof(struct ArrowArray));
+ if (private->arrays == NULL) {
+ ArrowBasicArrayStreamRelease(array_stream);
+ return ENOMEM;
+ }
+ }
+
+ for (int64_t i = 0; i < private->n_arrays; i++) {
+ private->arrays[i].release = NULL;
+ }
+
+ array_stream->get_schema = &ArrowBasicArrayStreamGetSchema;
+ array_stream->get_next = &ArrowBasicArrayStreamGetNext;
+ array_stream->get_last_error = ArrowBasicArrayStreamGetLastError;
+ array_stream->release = ArrowBasicArrayStreamRelease;
+ array_stream->private_data = private;
+ return NANOARROW_OK;
+}
+
+void ArrowBasicArrayStreamSetArray(struct ArrowArrayStream* array_stream,
int64_t i,
+ struct ArrowArray* array) {
+ struct BasicArrayStreamPrivate* private =
+ (struct BasicArrayStreamPrivate*)array_stream->private_data;
+ ArrowArrayMove(array, &private->arrays[i]);
+}
+
+ArrowErrorCode ArrowBasicArrayStreamValidate(struct ArrowArrayStream*
array_stream,
+ struct ArrowError* error) {
+ struct BasicArrayStreamPrivate* private =
+ (struct BasicArrayStreamPrivate*)array_stream->private_data;
+
+ struct ArrowArrayView array_view;
+ NANOARROW_RETURN_NOT_OK(
+ ArrowArrayViewInitFromSchema(&array_view, &private->schema, error));
+
+ for (int64_t i = 0; i < private->n_arrays; i++) {
+ if (private->arrays[i].release != NULL) {
+ int result = ArrowArrayViewSetArray(&array_view, &private->arrays[i],
error);
+ if (result != NANOARROW_OK) {
+ ArrowArrayViewReset(&array_view);
+ return result;
+ }
+ }
+ }
+
+ ArrowArrayViewReset(&array_view);
+ return NANOARROW_OK;
+}
diff --git a/dist/nanoarrow.h b/dist/nanoarrow.h
index f4dd307..697d209 100644
--- a/dist/nanoarrow.h
+++ b/dist/nanoarrow.h
@@ -29,7 +29,7 @@
// #define NANOARROW_NAMESPACE YourNamespaceHere
-#define NANOARROW_BUILD_ID "gha5eccbdd1cdcfaafd0493d96283963dc73dfa4b59"
+#define NANOARROW_BUILD_ID "gha36025e25999301f77b0447bee93e00055ff89541"
#endif
// Licensed to the Apache Software Foundation (ASF) under one
@@ -159,6 +159,25 @@ struct ArrowArrayStream {
#endif // ARROW_C_STREAM_INTERFACE
#endif // ARROW_FLAG_DICTIONARY_ORDERED
+/// \brief Move the contents of src into dst and set src->release to NULL
+static inline void ArrowSchemaMove(struct ArrowSchema* src, struct
ArrowSchema* dst) {
+ memcpy(dst, src, sizeof(struct ArrowSchema));
+ src->release = NULL;
+}
+
+/// \brief Move the contents of src into dst and set src->release to NULL
+static inline void ArrowArrayMove(struct ArrowArray* src, struct ArrowArray*
dst) {
+ memcpy(dst, src, sizeof(struct ArrowArray));
+ src->release = NULL;
+}
+
+/// \brief Move the contents of src into dst and set src->release to NULL
+static inline void ArrowArrayStreamMove(struct ArrowArrayStream* src,
+ struct ArrowArrayStream* dst) {
+ memcpy(dst, src, sizeof(struct ArrowArrayStream));
+ src->release = NULL;
+}
+
/// @}
// Utility macros
@@ -649,6 +668,12 @@ struct ArrowArrayPrivateData {
#define ArrowArrayViewSetArray \
NANOARROW_SYMBOL(NANOARROW_NAMESPACE, ArrowArrayViewSetArray)
#define ArrowArrayViewReset NANOARROW_SYMBOL(NANOARROW_NAMESPACE,
ArrowArrayViewReset)
+#define ArrowBasicArrayStreamInit \
+ NANOARROW_SYMBOL(NANOARROW_NAMESPACE, ArrowBasicArrayStreamInit)
+#define ArrowBasicArrayStreamSetArray \
+ NANOARROW_SYMBOL(NANOARROW_NAMESPACE, ArrowBasicArrayStreamSetArray)
+#define ArrowBasicArrayStreamValidate \
+ NANOARROW_SYMBOL(NANOARROW_NAMESPACE, ArrowBasicArrayStreamValidate)
#endif
@@ -1027,8 +1052,7 @@ static inline void ArrowBufferReset(struct ArrowBuffer*
buffer);
///
/// Transfers the buffer data and lifecycle management to another
/// address and resets buffer.
-static inline void ArrowBufferMove(struct ArrowBuffer* buffer,
- struct ArrowBuffer* buffer_out);
+static inline void ArrowBufferMove(struct ArrowBuffer* src, struct
ArrowBuffer* dst);
/// \brief Grow or shrink a buffer to a given capacity
///
@@ -1108,6 +1132,14 @@ static inline ArrowErrorCode
ArrowBufferAppendDouble(struct ArrowBuffer* buffer,
static inline ArrowErrorCode ArrowBufferAppendFloat(struct ArrowBuffer* buffer,
float value);
+/// \brief Write an ArrowStringView to a buffer
+static inline ArrowErrorCode ArrowBufferAppendStringView(struct ArrowBuffer*
buffer,
+ struct
ArrowStringView value);
+
+/// \brief Write an ArrowBufferView to a buffer
+static inline ArrowErrorCode ArrowBufferAppendBufferView(struct ArrowBuffer*
buffer,
+ struct
ArrowBufferView value);
+
/// @}
/// \defgroup nanoarrow-bitmap Bitmap utilities
@@ -1138,6 +1170,12 @@ static inline int64_t ArrowBitCountSet(const uint8_t*
bits, int64_t i_from, int6
/// Initialize the builder's buffer, empty its cache, and reset the size to
zero
static inline void ArrowBitmapInit(struct ArrowBitmap* bitmap);
+/// \brief Move an ArrowBitmap
+///
+/// Transfers the underlying buffer data and lifecycle management to another
+/// address and resets the bitmap.
+static inline void ArrowBitmapMove(struct ArrowBitmap* src, struct
ArrowBitmap* dst);
+
/// \brief Ensure a bitmap builder has at least a given additional capacity
///
/// Ensures that the buffer has space to append at least
@@ -1336,6 +1374,13 @@ ArrowErrorCode ArrowArrayFinishBuilding(struct
ArrowArray* array,
/// \brief Initialize the contents of an ArrowArrayView
void ArrowArrayViewInit(struct ArrowArrayView* array_view, enum ArrowType
storage_type);
+/// \brief Move an ArrowArrayView
+///
+/// Transfers the ArrowArrayView data and lifecycle management to another
+/// address and resets the contents of src.
+static inline void ArrowArrayViewMove(struct ArrowArrayView* src,
+ struct ArrowArrayView* dst);
+
/// \brief Initialize the contents of an ArrowArrayView from an ArrowSchema
ArrowErrorCode ArrowArrayViewInitFromSchema(struct ArrowArrayView* array_view,
struct ArrowSchema* schema,
@@ -1395,6 +1440,43 @@ static inline struct ArrowBufferView
ArrowArrayViewGetBytesUnsafe(
/// @}
+/// \defgroup nanoarrow-basic-array-stream Basic ArrowArrayStream
implementation
+///
+/// An implementation of an ArrowArrayStream based on a collection of
+/// zero or more previously-existing ArrowArray objects. Users should
+/// initialize and/or validate the contents before transferring the
+/// responsibility of the ArrowArrayStream elsewhere.
+///
+/// @{
+
+/// \brief Initialize an ArrowArrayStream backed by this implementation
+///
+/// This function moves the ownership of schema to the array_stream. If
+/// this function returns NANOARROW_OK, the caller is responsible for
+/// releasing the ArrowArrayStream.
+ArrowErrorCode ArrowBasicArrayStreamInit(struct ArrowArrayStream* array_stream,
+ struct ArrowSchema* schema, int64_t
n_arrays);
+
+/// \brief Set the ith ArrowArray in this ArrowArrayStream.
+///
+/// array_stream must have been initialized with ArrowBasicArrayStreamInit().
+/// This function move the ownership of array to the array_stream. i must
+/// be greater than zero and less than the value of n_arrays passed in
+/// ArrowBasicArrayStreamInit(). Callers are not required to fill all
+/// n_arrays members (i.e., n_arrays is a maximum bound).
+void ArrowBasicArrayStreamSetArray(struct ArrowArrayStream* array_stream,
int64_t i,
+ struct ArrowArray* array);
+
+/// \brief Validate the contents of this ArrowArrayStream
+///
+/// array_stream must have been initialized with ArrowBasicArrayStreamInit().
+/// This function uses ArrowArrayStreamInitFromSchema() and
ArrowArrayStreamSetArray()
+/// to validate the contents of the arrays.
+ArrowErrorCode ArrowBasicArrayStreamValidate(struct ArrowArrayStream*
array_stream,
+ struct ArrowError* error);
+
+/// @}
+
// Inline function definitions
@@ -1471,11 +1553,10 @@ static inline void ArrowBufferReset(struct ArrowBuffer*
buffer) {
buffer->size_bytes = 0;
}
-static inline void ArrowBufferMove(struct ArrowBuffer* buffer,
- struct ArrowBuffer* buffer_out) {
- memcpy(buffer_out, buffer, sizeof(struct ArrowBuffer));
- buffer->data = NULL;
- ArrowBufferReset(buffer);
+static inline void ArrowBufferMove(struct ArrowBuffer* src, struct
ArrowBuffer* dst) {
+ memcpy(dst, src, sizeof(struct ArrowBuffer));
+ src->data = NULL;
+ ArrowBufferReset(src);
}
static inline ArrowErrorCode ArrowBufferResize(struct ArrowBuffer* buffer,
@@ -1582,6 +1663,16 @@ static inline ArrowErrorCode
ArrowBufferAppendFloat(struct ArrowBuffer* buffer,
return ArrowBufferAppend(buffer, &value, sizeof(float));
}
+static inline ArrowErrorCode ArrowBufferAppendStringView(struct ArrowBuffer*
buffer,
+ struct
ArrowStringView value) {
+ return ArrowBufferAppend(buffer, value.data, value.n_bytes);
+}
+
+static inline ArrowErrorCode ArrowBufferAppendBufferView(struct ArrowBuffer*
buffer,
+ struct
ArrowBufferView value) {
+ return ArrowBufferAppend(buffer, value.data.data, value.n_bytes);
+}
+
static inline ArrowErrorCode ArrowBufferAppendFill(struct ArrowBuffer* buffer,
uint8_t value, int64_t
size_bytes) {
NANOARROW_RETURN_NOT_OK(ArrowBufferReserve(buffer, size_bytes));
@@ -1732,6 +1823,12 @@ static inline void ArrowBitmapInit(struct ArrowBitmap*
bitmap) {
bitmap->size_bits = 0;
}
+static inline void ArrowBitmapMove(struct ArrowBitmap* src, struct
ArrowBitmap* dst) {
+ ArrowBufferMove(&src->buffer, &dst->buffer);
+ dst->size_bits = src->size_bits;
+ src->size_bits = 0;
+}
+
static inline ArrowErrorCode ArrowBitmapReserve(struct ArrowBitmap* bitmap,
int64_t additional_size_bits) {
int64_t min_capacity_bits = bitmap->size_bits + additional_size_bits;
@@ -2325,6 +2422,12 @@ static inline ArrowErrorCode
ArrowArrayFinishElement(struct ArrowArray* array) {
return NANOARROW_OK;
}
+static inline void ArrowArrayViewMove(struct ArrowArrayView* src,
+ struct ArrowArrayView* dst) {
+ memcpy(dst, src, sizeof(struct ArrowArrayView));
+ ArrowArrayViewInit(src, NANOARROW_TYPE_UNINITIALIZED);
+}
+
static inline int8_t ArrowArrayViewIsNull(struct ArrowArrayView* array_view,
int64_t i) {
const uint8_t* validity_buffer = array_view->buffer_views[0].data.as_uint8;
i += array_view->array->offset;