paleolimbot commented on code in PR #57:
URL: https://github.com/apache/arrow-nanoarrow/pull/57#discussion_r984853900
##########
src/nanoarrow/schema.c:
##########
@@ -1088,6 +1088,149 @@ ArrowErrorCode ArrowSchemaViewInit(struct
ArrowSchemaView* schema_view,
return NANOARROW_OK;
}
+static int64_t ArrowSchemaFormatInternal(struct ArrowSchemaView* schema_view,
+ enum ArrowType data_type, char* out,
int64_t n) {
+ const char* type_string = ArrowTypeString(data_type);
+ switch (data_type) {
+ case NANOARROW_TYPE_DECIMAL128:
+ case NANOARROW_TYPE_DECIMAL256:
+ return snprintf(out, n, "%s(%d, %d)", type_string,
+ (int)schema_view->decimal_precision,
+ (int)schema_view->decimal_scale);
+ case NANOARROW_TYPE_TIMESTAMP:
+ return snprintf(out, n, "%s('%s', '%.*s')", type_string,
+ ArrowTimeUnitString(schema_view->time_unit),
+ (int)schema_view->timezone.n_bytes,
schema_view->timezone.data);
+ case NANOARROW_TYPE_TIME32:
+ case NANOARROW_TYPE_TIME64:
+ case NANOARROW_TYPE_DURATION:
+ return snprintf(out, n, "%s('%s')", type_string,
+ ArrowTimeUnitString(schema_view->time_unit));
+ case NANOARROW_TYPE_FIXED_SIZE_BINARY:
+ case NANOARROW_TYPE_FIXED_SIZE_LIST:
+ return snprintf(out, n, "%s(%ld)", type_string,
(long)schema_view->fixed_size);
+ case NANOARROW_TYPE_SPARSE_UNION:
+ case NANOARROW_TYPE_DENSE_UNION:
+ return snprintf(out, n, "%s([%.*s])", type_string,
+ (int)schema_view->union_type_ids.n_bytes,
+ schema_view->union_type_ids.data);
+ default:
+ return snprintf(out, n, "%s", type_string);
+ }
+}
+
+int64_t ArrowSchemaFormat(struct ArrowSchema* schema, char* out, int64_t n,
+ char recursive) {
+ if (schema == NULL) {
+ return snprintf(out, n, "[invalid: pointer is null]");
+ }
+
+ if (schema->release == NULL) {
+ return snprintf(out, n, "[invalid: schema is released]");
+ }
+
+ struct ArrowSchemaView schema_view;
+ struct ArrowError error;
+
+ if (ArrowSchemaViewInit(&schema_view, schema, &error) != NANOARROW_OK) {
Review Comment:
For argument's sake, I pushed a version that leans the other direction and
just returns a `char*`. I don't want to make it too hard to do this (but also
don't want to allocate unnecessarily if you think this is going be a problem).
The `char*` version is nice because you can also use it from the debugger
console and use it a bit more easily in other error messages (i.e.,
`ArrowErrorSet("Can't cast array of type %s to %s, formatted1, formatted2)`).
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]