You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@arrow.apache.org by gi...@apache.org on 2022/12/06 15:03:05 UTC
[arrow-nanoarrow] branch main updated: Update dist/ for commit db11c168ecab99ecac9028afbf71427c7107bb12
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 ab1441c Update dist/ for commit db11c168ecab99ecac9028afbf71427c7107bb12
ab1441c is described below
commit ab1441cd4e2d8024aee1b2a081b1be0a585b7ed5
Author: GitHub Actions <ac...@github.com>
AuthorDate: Tue Dec 6 15:02:59 2022 +0000
Update dist/ for commit db11c168ecab99ecac9028afbf71427c7107bb12
---
dist/nanoarrow.c | 196 ++++++++++++++++++++++++++++++++++++++-----------------
dist/nanoarrow.h | 139 ++++++++++++++++++++++++++-------------
2 files changed, 230 insertions(+), 105 deletions(-)
diff --git a/dist/nanoarrow.c b/dist/nanoarrow.c
index 703c11a..7965404 100644
--- a/dist/nanoarrow.c
+++ b/dist/nanoarrow.c
@@ -334,7 +334,37 @@ static const char* ArrowSchemaFormatTemplate(enum ArrowType data_type) {
}
}
-ArrowErrorCode ArrowSchemaInit(struct ArrowSchema* schema, enum ArrowType data_type) {
+static int ArrowSchemaInitChildrenIfNeeded(struct ArrowSchema* schema,
+ enum ArrowType data_type) {
+ switch (data_type) {
+ case NANOARROW_TYPE_LIST:
+ case NANOARROW_TYPE_LARGE_LIST:
+ case NANOARROW_TYPE_FIXED_SIZE_LIST:
+ NANOARROW_RETURN_NOT_OK(ArrowSchemaAllocateChildren(schema, 1));
+ ArrowSchemaInit(schema->children[0]);
+ NANOARROW_RETURN_NOT_OK(ArrowSchemaSetName(schema->children[0], "item"));
+ break;
+ case NANOARROW_TYPE_MAP:
+ NANOARROW_RETURN_NOT_OK(ArrowSchemaAllocateChildren(schema, 1));
+ NANOARROW_RETURN_NOT_OK(
+ ArrowSchemaInitFromType(schema->children[0], NANOARROW_TYPE_STRUCT));
+ NANOARROW_RETURN_NOT_OK(ArrowSchemaSetName(schema->children[0], "entries"));
+ NANOARROW_RETURN_NOT_OK(ArrowSchemaAllocateChildren(schema->children[0], 2));
+ ArrowSchemaInit(schema->children[0]->children[0]);
+ ArrowSchemaInit(schema->children[0]->children[1]);
+ NANOARROW_RETURN_NOT_OK(
+ ArrowSchemaSetName(schema->children[0]->children[0], "key"));
+ NANOARROW_RETURN_NOT_OK(
+ ArrowSchemaSetName(schema->children[0]->children[1], "value"));
+ break;
+ default:
+ break;
+ }
+
+ return NANOARROW_OK;
+}
+
+void ArrowSchemaInit(struct ArrowSchema* schema) {
schema->format = NULL;
schema->name = NULL;
schema->metadata = NULL;
@@ -344,7 +374,9 @@ ArrowErrorCode ArrowSchemaInit(struct ArrowSchema* schema, enum ArrowType data_t
schema->dictionary = NULL;
schema->private_data = NULL;
schema->release = &ArrowSchemaRelease;
+}
+ArrowErrorCode ArrowSchemaSetType(struct ArrowSchema* schema, enum ArrowType data_type) {
// We don't allocate the dictionary because it has to be nullptr
// for non-dictionary-encoded arrays.
@@ -353,11 +385,30 @@ ArrowErrorCode ArrowSchemaInit(struct ArrowSchema* schema, enum ArrowType data_t
// If data_type isn't recognized and not explicitly unset
if (template_format == NULL && data_type != NANOARROW_TYPE_UNINITIALIZED) {
- schema->release(schema);
return EINVAL;
}
- int result = ArrowSchemaSetFormat(schema, template_format);
+ NANOARROW_RETURN_NOT_OK(ArrowSchemaSetFormat(schema, template_format));
+
+ // For types with an umabiguous child structure, allocate children
+ return ArrowSchemaInitChildrenIfNeeded(schema, data_type);
+}
+
+ArrowErrorCode ArrowSchemaSetTypeStruct(struct ArrowSchema* schema, int64_t n_children) {
+ NANOARROW_RETURN_NOT_OK(ArrowSchemaSetType(schema, NANOARROW_TYPE_STRUCT));
+ NANOARROW_RETURN_NOT_OK(ArrowSchemaAllocateChildren(schema, n_children));
+ for (int64_t i = 0; i < n_children; i++) {
+ ArrowSchemaInit(schema->children[i]);
+ }
+
+ return NANOARROW_OK;
+}
+
+ArrowErrorCode ArrowSchemaInitFromType(struct ArrowSchema* schema,
+ enum ArrowType data_type) {
+ ArrowSchemaInit(schema);
+
+ int result = ArrowSchemaSetType(schema, data_type);
if (result != NANOARROW_OK) {
schema->release(schema);
return result;
@@ -366,12 +417,9 @@ ArrowErrorCode ArrowSchemaInit(struct ArrowSchema* schema, enum ArrowType data_t
return NANOARROW_OK;
}
-ArrowErrorCode ArrowSchemaInitFixedSize(struct ArrowSchema* schema,
- enum ArrowType data_type, int32_t fixed_size) {
- NANOARROW_RETURN_NOT_OK(ArrowSchemaInit(schema, NANOARROW_TYPE_UNINITIALIZED));
-
+ArrowErrorCode ArrowSchemaSetTypeFixedSize(struct ArrowSchema* schema,
+ enum ArrowType data_type, int32_t fixed_size) {
if (fixed_size <= 0) {
- schema->release(schema);
return EINVAL;
}
@@ -385,27 +433,24 @@ ArrowErrorCode ArrowSchemaInitFixedSize(struct ArrowSchema* schema,
n_chars = snprintf(buffer, sizeof(buffer), "+w:%d", (int)fixed_size);
break;
default:
- schema->release(schema);
return EINVAL;
}
buffer[n_chars] = '\0';
- int result = ArrowSchemaSetFormat(schema, buffer);
- if (result != NANOARROW_OK) {
- schema->release(schema);
- return result;
+ NANOARROW_RETURN_NOT_OK(ArrowSchemaSetFormat(schema, buffer));
+
+ if (data_type == NANOARROW_TYPE_FIXED_SIZE_LIST) {
+ NANOARROW_RETURN_NOT_OK(ArrowSchemaInitChildrenIfNeeded(schema, data_type));
}
return NANOARROW_OK;
}
-ArrowErrorCode ArrowSchemaInitDecimal(struct ArrowSchema* schema,
- enum ArrowType data_type, int32_t decimal_precision,
- int32_t decimal_scale) {
- NANOARROW_RETURN_NOT_OK(ArrowSchemaInit(schema, NANOARROW_TYPE_UNINITIALIZED));
-
+ArrowErrorCode ArrowSchemaSetTypeDecimal(struct ArrowSchema* schema,
+ enum ArrowType data_type,
+ int32_t decimal_precision,
+ int32_t decimal_scale) {
if (decimal_precision <= 0) {
- schema->release(schema);
return EINVAL;
}
@@ -421,19 +466,11 @@ ArrowErrorCode ArrowSchemaInitDecimal(struct ArrowSchema* schema,
decimal_scale);
break;
default:
- schema->release(schema);
return EINVAL;
}
buffer[n_chars] = '\0';
-
- int result = ArrowSchemaSetFormat(schema, buffer);
- if (result != NANOARROW_OK) {
- schema->release(schema);
- return result;
- }
-
- return NANOARROW_OK;
+ return ArrowSchemaSetFormat(schema, buffer);
}
static const char* ArrowTimeUnitFormatString(enum ArrowTimeUnit time_unit) {
@@ -451,18 +488,12 @@ static const char* ArrowTimeUnitFormatString(enum ArrowTimeUnit time_unit) {
}
}
-ArrowErrorCode ArrowSchemaInitDateTime(struct ArrowSchema* schema,
- enum ArrowType data_type,
- enum ArrowTimeUnit time_unit,
- const char* timezone) {
- int result = ArrowSchemaInit(schema, NANOARROW_TYPE_UNINITIALIZED);
- if (result != NANOARROW_OK) {
- return result;
- }
-
+ArrowErrorCode ArrowSchemaSetTypeDateTime(struct ArrowSchema* schema,
+ enum ArrowType data_type,
+ enum ArrowTimeUnit time_unit,
+ const char* timezone) {
const char* time_unit_str = ArrowTimeUnitFormatString(time_unit);
if (time_unit_str == NULL) {
- schema->release(schema);
return EINVAL;
}
@@ -472,7 +503,6 @@ ArrowErrorCode ArrowSchemaInitDateTime(struct ArrowSchema* schema,
case NANOARROW_TYPE_TIME32:
case NANOARROW_TYPE_TIME64:
if (timezone != NULL) {
- schema->release(schema);
return EINVAL;
}
n_chars = snprintf(buffer, sizeof(buffer), "tt%s", time_unit_str);
@@ -485,27 +515,68 @@ ArrowErrorCode ArrowSchemaInitDateTime(struct ArrowSchema* schema,
break;
case NANOARROW_TYPE_DURATION:
if (timezone != NULL) {
- schema->release(schema);
return EINVAL;
}
n_chars = snprintf(buffer, sizeof(buffer), "tD%s", time_unit_str);
break;
default:
- schema->release(schema);
return EINVAL;
}
if (((size_t)n_chars) >= sizeof(buffer)) {
- schema->release(schema);
return ERANGE;
}
buffer[n_chars] = '\0';
- result = ArrowSchemaSetFormat(schema, buffer);
- if (result != NANOARROW_OK) {
- schema->release(schema);
- return result;
+ return ArrowSchemaSetFormat(schema, buffer);
+}
+
+ArrowErrorCode ArrowSchemaSetTypeUnion(struct ArrowSchema* schema,
+ enum ArrowType data_type, int64_t n_children) {
+ if (n_children < 0 || n_children > 127) {
+ return EINVAL;
+ }
+
+ // Max valid size would be +ud:0,1,...126 = 401 characters + null terminator
+ char format_out[512];
+ int64_t format_out_size = 512;
+ memset(format_out, 0, format_out_size);
+ int n_chars;
+ char* format_cursor = format_out;
+
+ switch (data_type) {
+ case NANOARROW_TYPE_SPARSE_UNION:
+ n_chars = snprintf(format_cursor, format_out_size, "+us:");
+ format_cursor += n_chars;
+ format_out_size -= n_chars;
+ break;
+ case NANOARROW_TYPE_DENSE_UNION:
+ n_chars = snprintf(format_cursor, format_out_size, "+ud:");
+ format_cursor += n_chars;
+ format_out_size -= n_chars;
+ break;
+ default:
+ return EINVAL;
+ }
+
+ if (n_children > 0) {
+ n_chars = snprintf(format_cursor, format_out_size, "0");
+ format_cursor += n_chars;
+ format_out_size -= n_chars;
+
+ for (int64_t i = 1; i < n_children; i++) {
+ n_chars = snprintf(format_cursor, format_out_size, ",%d", (int)i);
+ format_cursor += n_chars;
+ format_out_size -= n_chars;
+ }
+ }
+
+ NANOARROW_RETURN_NOT_OK(ArrowSchemaSetFormat(schema, format_out));
+
+ NANOARROW_RETURN_NOT_OK(ArrowSchemaAllocateChildren(schema, n_children));
+ for (int64_t i = 0; i < n_children; i++) {
+ ArrowSchemaInit(schema->children[i]);
}
return NANOARROW_OK;
@@ -617,8 +688,9 @@ ArrowErrorCode ArrowSchemaAllocateDictionary(struct ArrowSchema* schema) {
return NANOARROW_OK;
}
-int ArrowSchemaDeepCopy(struct ArrowSchema* schema, struct ArrowSchema* schema_out) {
- NANOARROW_RETURN_NOT_OK(ArrowSchemaInit(schema_out, NANOARROW_TYPE_NA));
+ArrowErrorCode ArrowSchemaDeepCopy(struct ArrowSchema* schema,
+ struct ArrowSchema* schema_out) {
+ ArrowSchemaInit(schema_out);
int result = ArrowSchemaSetFormat(schema_out, schema->format);
if (result != NANOARROW_OK) {
@@ -1773,7 +1845,8 @@ static ArrowErrorCode ArrowArraySetStorageType(struct ArrowArray* array,
return NANOARROW_OK;
}
-ArrowErrorCode ArrowArrayInit(struct ArrowArray* array, enum ArrowType storage_type) {
+ArrowErrorCode ArrowArrayInitFromType(struct ArrowArray* array,
+ enum ArrowType storage_type) {
array->length = 0;
array->null_count = 0;
array->offset = 0;
@@ -1812,10 +1885,10 @@ ArrowErrorCode ArrowArrayInit(struct ArrowArray* array, enum ArrowType storage_t
return NANOARROW_OK;
}
-static ArrowErrorCode ArrowArrayInitFromArrayView(struct ArrowArray* array,
- struct ArrowArrayView* array_view,
- struct ArrowError* error) {
- ArrowArrayInit(array, array_view->storage_type);
+static ArrowErrorCode ArrowArrayInitFromTypeFromArrayView(
+ struct ArrowArray* array, struct ArrowArrayView* array_view,
+ struct ArrowError* error) {
+ ArrowArrayInitFromType(array, array_view->storage_type);
struct ArrowArrayPrivateData* private_data =
(struct ArrowArrayPrivateData*)array->private_data;
@@ -1828,8 +1901,8 @@ static ArrowErrorCode ArrowArrayInitFromArrayView(struct ArrowArray* array,
private_data->layout = array_view->layout;
for (int64_t i = 0; i < array_view->n_children; i++) {
- int result =
- ArrowArrayInitFromArrayView(array->children[i], array_view->children[i], error);
+ int result = ArrowArrayInitFromTypeFromArrayView(array->children[i],
+ array_view->children[i], error);
if (result != NANOARROW_OK) {
array->release(array);
return result;
@@ -1844,7 +1917,7 @@ ArrowErrorCode ArrowArrayInitFromSchema(struct ArrowArray* array,
struct ArrowError* error) {
struct ArrowArrayView array_view;
NANOARROW_RETURN_NOT_OK(ArrowArrayViewInitFromSchema(&array_view, schema, error));
- NANOARROW_RETURN_NOT_OK(ArrowArrayInitFromArrayView(array, &array_view, error));
+ NANOARROW_RETURN_NOT_OK(ArrowArrayInitFromTypeFromArrayView(array, &array_view, error));
ArrowArrayViewReset(&array_view);
return NANOARROW_OK;
}
@@ -1931,7 +2004,7 @@ static ArrowErrorCode ArrowArrayViewInitFromArray(struct ArrowArrayView* array_v
struct ArrowArrayPrivateData* private_data =
(struct ArrowArrayPrivateData*)array->private_data;
- ArrowArrayViewInit(array_view, private_data->storage_type);
+ ArrowArrayViewInitFromType(array_view, private_data->storage_type);
array_view->layout = private_data->layout;
array_view->array = array;
@@ -2105,7 +2178,8 @@ ArrowErrorCode ArrowArrayFinishBuilding(struct ArrowArray* array,
return result;
}
-void ArrowArrayViewInit(struct ArrowArrayView* array_view, enum ArrowType storage_type) {
+void ArrowArrayViewInitFromType(struct ArrowArrayView* array_view,
+ enum ArrowType storage_type) {
memset(array_view, 0, sizeof(struct ArrowArrayView));
array_view->storage_type = storage_type;
ArrowLayoutInit(&array_view->layout, storage_type);
@@ -2135,7 +2209,7 @@ ArrowErrorCode ArrowArrayViewAllocateChildren(struct ArrowArrayView* array_view,
if (array_view->children[i] == NULL) {
return ENOMEM;
}
- ArrowArrayViewInit(array_view->children[i], NANOARROW_TYPE_UNINITIALIZED);
+ ArrowArrayViewInitFromType(array_view->children[i], NANOARROW_TYPE_UNINITIALIZED);
}
return NANOARROW_OK;
@@ -2150,7 +2224,7 @@ ArrowErrorCode ArrowArrayViewInitFromSchema(struct ArrowArrayView* array_view,
return result;
}
- ArrowArrayViewInit(array_view, schema_view.storage_data_type);
+ ArrowArrayViewInitFromType(array_view, schema_view.storage_data_type);
array_view->layout = schema_view.layout;
result = ArrowArrayViewAllocateChildren(array_view, schema->n_children);
@@ -2183,7 +2257,7 @@ void ArrowArrayViewReset(struct ArrowArrayView* array_view) {
ArrowFree(array_view->children);
}
- ArrowArrayViewInit(array_view, NANOARROW_TYPE_UNINITIALIZED);
+ ArrowArrayViewInitFromType(array_view, NANOARROW_TYPE_UNINITIALIZED);
}
void ArrowArrayViewSetLength(struct ArrowArrayView* array_view, int64_t length) {
diff --git a/dist/nanoarrow.h b/dist/nanoarrow.h
index 697d209..960f143 100644
--- a/dist/nanoarrow.h
+++ b/dist/nanoarrow.h
@@ -29,7 +29,7 @@
// #define NANOARROW_NAMESPACE YourNamespaceHere
-#define NANOARROW_BUILD_ID "gha36025e25999301f77b0447bee93e00055ff89541"
+#define NANOARROW_BUILD_ID "ghadb11c168ecab99ecac9028afbf71427c7107bb12"
#endif
// Licensed to the Apache Software Foundation (ASF) under one
@@ -613,12 +613,19 @@ struct ArrowArrayPrivateData {
#define ArrowErrorSet NANOARROW_SYMBOL(NANOARROW_NAMESPACE, ArrowErrorSet)
#define ArrowLayoutInit NANOARROW_SYMBOL(NANOARROW_NAMESPACE, ArrowLayoutInit)
#define ArrowSchemaInit NANOARROW_SYMBOL(NANOARROW_NAMESPACE, ArrowSchemaInit)
-#define ArrowSchemaInitFixedSize \
- NANOARROW_SYMBOL(NANOARROW_NAMESPACE, ArrowSchemaInitFixedSize)
-#define ArrowSchemaInitDecimal \
- NANOARROW_SYMBOL(NANOARROW_NAMESPACE, ArrowSchemaInitDecimal)
-#define ArrowSchemaInitDateTime \
- NANOARROW_SYMBOL(NANOARROW_NAMESPACE, ArrowSchemaInitDateTime)
+#define ArrowSchemaInitFromType \
+ NANOARROW_SYMBOL(NANOARROW_NAMESPACE, ArrowSchemaInitFromType)
+#define ArrowSchemaSetType NANOARROW_SYMBOL(NANOARROW_NAMESPACE, ArrowSchemaSetType)
+#define ArrowSchemaSetTypeStruct \
+ NANOARROW_SYMBOL(NANOARROW_NAMESPACE, ArrowSchemaSetTypeStruct)
+#define ArrowSchemaSetTypeFixedSize \
+ NANOARROW_SYMBOL(NANOARROW_NAMESPACE, ArrowSchemaSetTypeFixedSize)
+#define ArrowSchemaSetTypeDecimal \
+ NANOARROW_SYMBOL(NANOARROW_NAMESPACE, ArrowSchemaSetTypeDecimal)
+#define ArrowSchemaSetTypeDateTime \
+ NANOARROW_SYMBOL(NANOARROW_NAMESPACE, ArrowSchemaSetTypeDateTime)
+#define ArrowSchemaSetTypeUnion \
+ NANOARROW_SYMBOL(NANOARROW_NAMESPACE, ArrowSchemaSetTypeUnion)
#define ArrowSchemaDeepCopy NANOARROW_SYMBOL(NANOARROW_NAMESPACE, ArrowSchemaDeepCopy)
#define ArrowSchemaSetFormat NANOARROW_SYMBOL(NANOARROW_NAMESPACE, ArrowSchemaSetFormat)
#define ArrowSchemaSetName NANOARROW_SYMBOL(NANOARROW_NAMESPACE, ArrowSchemaSetName)
@@ -645,7 +652,8 @@ struct ArrowArrayPrivateData {
NANOARROW_SYMBOL(NANOARROW_NAMESPACE, ArrowMetadataBuilderRemove)
#define ArrowSchemaViewInit NANOARROW_SYMBOL(NANOARROW_NAMESPACE, ArrowSchemaViewInit)
#define ArrowSchemaToString NANOARROW_SYMBOL(NANOARROW_NAMESPACE, ArrowSchemaToString)
-#define ArrowArrayInit NANOARROW_SYMBOL(NANOARROW_NAMESPACE, ArrowArrayInit)
+#define ArrowArrayInitFromType \
+ NANOARROW_SYMBOL(NANOARROW_NAMESPACE, ArrowArrayInitFromType)
#define ArrowArrayInitFromSchema \
NANOARROW_SYMBOL(NANOARROW_NAMESPACE, ArrowArrayInitFromSchema)
#define ArrowArrayAllocateChildren \
@@ -658,7 +666,8 @@ struct ArrowArrayPrivateData {
#define ArrowArrayReserve NANOARROW_SYMBOL(NANOARROW_NAMESPACE, ArrowArrayReserve)
#define ArrowArrayFinishBuilding \
NANOARROW_SYMBOL(NANOARROW_NAMESPACE, ArrowArrayFinishBuilding)
-#define ArrowArrayViewInit NANOARROW_SYMBOL(NANOARROW_NAMESPACE, ArrowArrayViewInit)
+#define ArrowArrayViewInitFromType \
+ NANOARROW_SYMBOL(NANOARROW_NAMESPACE, ArrowArrayViewInitFromType)
#define ArrowArrayViewInitFromSchema \
NANOARROW_SYMBOL(NANOARROW_NAMESPACE, ArrowArrayViewInitFromSchema)
#define ArrowArrayViewAllocateChildren \
@@ -778,12 +787,20 @@ static inline struct ArrowStringView ArrowCharView(const char* value);
///
/// @{
-/// \brief Initialize the fields of a schema
+/// \brief Initialize an ArrowSchema
///
/// Initializes the fields and release callback of schema_out. Caller
/// is responsible for calling the schema->release callback if
/// NANOARROW_OK is returned.
-ArrowErrorCode ArrowSchemaInit(struct ArrowSchema* schema, enum ArrowType type);
+void ArrowSchemaInit(struct ArrowSchema* schema);
+
+/// \brief Initialize an ArrowSchema from an ArrowType
+///
+/// A convenience constructor for that calls ArrowSchemaInit() and
+/// ArrowSchemaSetType() for the common case of constructing an
+/// unparameterized type. The caller is responsible for calling the schema->release
+/// callback if NANOARROW_OK is returned.
+ArrowErrorCode ArrowSchemaInitFromType(struct ArrowSchema* schema, enum ArrowType type);
/// \brief Get a human-readable summary of a Schema
///
@@ -794,31 +811,63 @@ ArrowErrorCode ArrowSchemaInit(struct ArrowSchema* schema, enum ArrowType type);
int64_t ArrowSchemaToString(struct ArrowSchema* schema, char* out, int64_t n,
char recursive);
-/// \brief Initialize the fields of a fixed-size schema
+/// \brief Set the format field of a schema from an ArrowType
+///
+/// Initializes the fields and release callback of schema_out. For
+/// NANOARROW_TYPE_LIST, NANOARROW_TYPE_LARGE_LIST, and
+/// NANOARROW_TYPE_MAP, the appropriate number of children are
+/// allocated, initialized, and named; however, the caller must
+/// ArrowSchemaSetType() on the preinitialized children. Schema must have been initialized
+/// using ArrowSchemaInit() or ArrowSchemaDeepCopy().
+ArrowErrorCode ArrowSchemaSetType(struct ArrowSchema* schema, enum ArrowType type);
+
+/// \brief Set the format field and initialize children of a struct schema
+///
+/// The specified number of children are initialized; however, the caller is responsible
+/// for calling ArrowSchemaSetType() and ArrowSchemaSetName() on each child.
+/// Schema must have been initialized using ArrowSchemaInit() or ArrowSchemaDeepCopy().
+ArrowErrorCode ArrowSchemaSetTypeStruct(struct ArrowSchema* schema, int64_t n_children);
+
+/// \brief Set the format field of a fixed-size schema
///
/// Returns EINVAL for fixed_size <= 0 or for data_type that is not
/// NANOARROW_TYPE_FIXED_SIZE_BINARY or NANOARROW_TYPE_FIXED_SIZE_LIST.
-ArrowErrorCode ArrowSchemaInitFixedSize(struct ArrowSchema* schema,
- enum ArrowType data_type, int32_t fixed_size);
+/// For NANOARROW_TYPE_FIXED_SIZE_LIST, the appropriate number of children are
+/// allocated, initialized, and named; however, the caller must
+/// ArrowSchemaSetType() the first child. Schema must have been initialized using
+/// ArrowSchemaInit() or ArrowSchemaDeepCopy().
+ArrowErrorCode ArrowSchemaSetTypeFixedSize(struct ArrowSchema* schema,
+ enum ArrowType data_type, int32_t fixed_size);
-/// \brief Initialize the fields of a decimal schema
+/// \brief Set the format field of a decimal schema
///
/// Returns EINVAL for scale <= 0 or for data_type that is not
-/// NANOARROW_TYPE_DECIMAL128 or NANOARROW_TYPE_DECIMAL256.
-ArrowErrorCode ArrowSchemaInitDecimal(struct ArrowSchema* schema,
- enum ArrowType data_type, int32_t decimal_precision,
- int32_t decimal_scale);
+/// NANOARROW_TYPE_DECIMAL128 or NANOARROW_TYPE_DECIMAL256. Schema must have been
+/// initialized using ArrowSchemaInit() or ArrowSchemaDeepCopy().
+ArrowErrorCode ArrowSchemaSetTypeDecimal(struct ArrowSchema* schema,
+ enum ArrowType data_type,
+ int32_t decimal_precision,
+ int32_t decimal_scale);
-/// \brief Initialize the fields of a time, timestamp, or duration schema
+/// \brief Set the format field of a time, timestamp, or duration schema
///
/// Returns EINVAL for data_type that is not
/// NANOARROW_TYPE_TIME32, NANOARROW_TYPE_TIME64,
/// NANOARROW_TYPE_TIMESTAMP, or NANOARROW_TYPE_DURATION. The
-/// timezone parameter must be NULL for a non-timestamp data_type.
-ArrowErrorCode ArrowSchemaInitDateTime(struct ArrowSchema* schema,
- enum ArrowType data_type,
- enum ArrowTimeUnit time_unit,
- const char* timezone);
+/// timezone parameter must be NULL for a non-timestamp data_type. Schema must have been
+/// initialized using ArrowSchemaInit() or ArrowSchemaDeepCopy().
+ArrowErrorCode ArrowSchemaSetTypeDateTime(struct ArrowSchema* schema,
+ enum ArrowType data_type,
+ enum ArrowTimeUnit time_unit,
+ const char* timezone);
+
+/// \brief Seet the format field of a union schema
+///
+/// Returns EINVAL for a data_type that is not NANOARROW_TYPE_DENSE_UNION
+/// or NANOARROW_TYPE_SPARSE_UNION. The specified number of children are
+/// allocated, and initialized.
+ArrowErrorCode ArrowSchemaSetTypeUnion(struct ArrowSchema* schema,
+ enum ArrowType data_type, int64_t n_children);
/// \brief Make a (recursive) copy of a schema
///
@@ -828,33 +877,33 @@ ArrowErrorCode ArrowSchemaDeepCopy(struct ArrowSchema* schema,
/// \brief Copy format into schema->format
///
-/// schema must have been allocated using ArrowSchemaInit() or
+/// schema must have been allocated using ArrowSchemaInitFromType() or
/// ArrowSchemaDeepCopy().
ArrowErrorCode ArrowSchemaSetFormat(struct ArrowSchema* schema, const char* format);
/// \brief Copy name into schema->name
///
-/// schema must have been allocated using ArrowSchemaInit() or
+/// schema must have been allocated using ArrowSchemaInitFromType() or
/// ArrowSchemaDeepCopy().
ArrowErrorCode ArrowSchemaSetName(struct ArrowSchema* schema, const char* name);
/// \brief Copy metadata into schema->metadata
///
-/// schema must have been allocated using ArrowSchemaInit() or
+/// schema must have been allocated using ArrowSchemaInitFromType() or
/// ArrowSchemaDeepCopy.
ArrowErrorCode ArrowSchemaSetMetadata(struct ArrowSchema* schema, const char* metadata);
/// \brief Allocate the schema->children array
///
/// Includes the memory for each child struct ArrowSchema.
-/// schema must have been allocated using ArrowSchemaInit() or
+/// schema must have been allocated using ArrowSchemaInitFromType() or
/// ArrowSchemaDeepCopy().
ArrowErrorCode ArrowSchemaAllocateChildren(struct ArrowSchema* schema,
int64_t n_children);
/// \brief Allocate the schema->dictionary member
///
-/// schema must have been allocated using ArrowSchemaInit() or
+/// schema must have been allocated using ArrowSchemaInitFromType() or
/// ArrowSchemaDeepCopy().
ArrowErrorCode ArrowSchemaAllocateDictionary(struct ArrowSchema* schema);
@@ -1231,7 +1280,8 @@ static inline void ArrowBitmapReset(struct ArrowBitmap* bitmap);
/// Initializes the fields and release callback of array. Caller
/// is responsible for calling the array->release callback if
/// NANOARROW_OK is returned.
-ArrowErrorCode ArrowArrayInit(struct ArrowArray* array, enum ArrowType storage_type);
+ArrowErrorCode ArrowArrayInitFromType(struct ArrowArray* array,
+ enum ArrowType storage_type);
/// \brief Initialize the contents of an ArrowArray from an ArrowSchema
///
@@ -1245,37 +1295,37 @@ ArrowErrorCode ArrowArrayInitFromSchema(struct ArrowArray* array,
///
/// Includes the memory for each child struct ArrowArray,
/// whose members are marked as released and may be subsequently initialized
-/// with ArrowArrayInit() or moved from an existing ArrowArray.
-/// schema must have been allocated using ArrowArrayInit().
+/// with ArrowArrayInitFromType() or moved from an existing ArrowArray.
+/// schema must have been allocated using ArrowArrayInitFromType().
ArrowErrorCode ArrowArrayAllocateChildren(struct ArrowArray* array, int64_t n_children);
/// \brief Allocate the array->dictionary member
///
/// Includes the memory for the struct ArrowArray, whose contents
/// is marked as released and may be subsequently initialized
-/// with ArrowArrayInit() or moved from an existing ArrowArray.
-/// array must have been allocated using ArrowArrayInit()
+/// with ArrowArrayInitFromType() or moved from an existing ArrowArray.
+/// array must have been allocated using ArrowArrayInitFromType()
ArrowErrorCode ArrowArrayAllocateDictionary(struct ArrowArray* array);
/// \brief Set the validity bitmap of an ArrowArray
///
-/// array must have been allocated using ArrowArrayInit()
+/// array must have been allocated using ArrowArrayInitFromType()
void ArrowArraySetValidityBitmap(struct ArrowArray* array, struct ArrowBitmap* bitmap);
/// \brief Set a buffer of an ArrowArray
///
-/// array must have been allocated using ArrowArrayInit()
+/// array must have been allocated using ArrowArrayInitFromType()
ArrowErrorCode ArrowArraySetBuffer(struct ArrowArray* array, int64_t i,
struct ArrowBuffer* buffer);
/// \brief Get the validity bitmap of an ArrowArray
///
-/// array must have been allocated using ArrowArrayInit()
+/// array must have been allocated using ArrowArrayInitFromType()
static inline struct ArrowBitmap* ArrowArrayValidityBitmap(struct ArrowArray* array);
/// \brief Get a buffer of an ArrowArray
///
-/// array must have been allocated using ArrowArrayInit()
+/// array must have been allocated using ArrowArrayInitFromType()
static inline struct ArrowBuffer* ArrowArrayBuffer(struct ArrowArray* array, int64_t i);
/// \brief Start element-wise appending to an ArrowArray
@@ -1283,7 +1333,7 @@ static inline struct ArrowBuffer* ArrowArrayBuffer(struct ArrowArray* array, int
/// Initializes any values needed to use ArrowArrayAppend*() functions.
/// All element-wise appenders append by value and return EINVAL if the exact value
/// cannot be represented by the underlying storage type.
-/// array must have been allocated using ArrowArrayInit()
+/// array must have been allocated using ArrowArrayInitFromType()
static inline ArrowErrorCode ArrowArrayStartAppending(struct ArrowArray* array);
/// \brief Reserve space for future appends
@@ -1351,7 +1401,7 @@ static inline ArrowErrorCode ArrowArrayFinishElement(struct ArrowArray* array);
/// \brief Shrink buffer capacity to the size required
///
/// Also applies shrinking to any child arrays. array must have been allocated using
-/// ArrowArrayInit
+/// ArrowArrayInitFromType
static inline ArrowErrorCode ArrowArrayShrinkToFit(struct ArrowArray* array);
/// \brief Finish building an ArrowArray
@@ -1359,7 +1409,7 @@ static inline ArrowErrorCode ArrowArrayShrinkToFit(struct ArrowArray* array);
/// Flushes any pointers from internal buffers that may have been reallocated
/// into the array->buffers array and checks the actual size of the buffers
/// against the expected size based on the final length.
-/// array must have been allocated using ArrowArrayInit()
+/// array must have been allocated using ArrowArrayInitFromType()
ArrowErrorCode ArrowArrayFinishBuilding(struct ArrowArray* array,
struct ArrowError* error);
@@ -1372,7 +1422,8 @@ ArrowErrorCode ArrowArrayFinishBuilding(struct ArrowArray* array,
/// @{
/// \brief Initialize the contents of an ArrowArrayView
-void ArrowArrayViewInit(struct ArrowArrayView* array_view, enum ArrowType storage_type);
+void ArrowArrayViewInitFromType(struct ArrowArrayView* array_view,
+ enum ArrowType storage_type);
/// \brief Move an ArrowArrayView
///
@@ -2425,7 +2476,7 @@ static inline ArrowErrorCode ArrowArrayFinishElement(struct ArrowArray* array) {
static inline void ArrowArrayViewMove(struct ArrowArrayView* src,
struct ArrowArrayView* dst) {
memcpy(dst, src, sizeof(struct ArrowArrayView));
- ArrowArrayViewInit(src, NANOARROW_TYPE_UNINITIALIZED);
+ ArrowArrayViewInitFromType(src, NANOARROW_TYPE_UNINITIALIZED);
}
static inline int8_t ArrowArrayViewIsNull(struct ArrowArrayView* array_view, int64_t i) {