From 5ce31ef6eda6bbd9a4cfaffdcb2ec0ff945b12af Mon Sep 17 00:00:00 2001 From: Dewey Dunnington Date: Sun, 14 Jun 2026 21:46:06 -0500 Subject: [PATCH] first pass at dictionary --- src/nanoarrow/ipc/decoder.c | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/src/nanoarrow/ipc/decoder.c b/src/nanoarrow/ipc/decoder.c index 7b24bc3a9..d27c0940d 100644 --- a/src/nanoarrow/ipc/decoder.c +++ b/src/nanoarrow/ipc/decoder.c @@ -324,7 +324,11 @@ static ArrowErrorCode ArrowIpcDictionaryReplace(struct ArrowIpcDictionary* dicti ArrowArrayRelease(&dictionary->current_value); } - ArrowArrayMove(value, &dictionary->current_value); + // Convert to a shared array so that clones can reference the same data + // without copying + struct ArrowArray shared; + NANOARROW_RETURN_NOT_OK(ArrowArrayMoveShared(value, &shared)); + ArrowArrayMove(&shared, &dictionary->current_value); return NANOARROW_OK; } @@ -2318,9 +2322,8 @@ static int ArrowIpcDecoderWalkGetArray(struct ArrowArrayView* array_view, } if (array_view->dictionary != NULL) { - // TODO: this currently copies the array for every output. - NANOARROW_RETURN_NOT_OK(ArrowIpcDecoderWalkGetArray( - array_view->dictionary, array->dictionary, out->dictionary, error)); + // Move the pre-cloned shared dictionary to output (avoids copying) + ArrowArrayMove(array->dictionary, out->dictionary); } return NANOARROW_OK; @@ -2359,6 +2362,15 @@ static int ArrowIpcDecoderWalkSetArrayView(struct ArrowIpcDecoder* decoder, // decode. NANOARROW_RETURN_NOT_OK( ArrowArrayViewSetArray(array_view->dictionary, dictionary, error)); + + // Clone the shared dictionary for output (avoids copying dictionary data) + if (array->dictionary != NULL) { + if (array->dictionary->release != NULL) { + ArrowArrayRelease(array->dictionary); + } + NANOARROW_RETURN_NOT_OK( + ArrowArrayCloneShared((struct ArrowArray*)dictionary, array->dictionary)); + } } ns(FieldNode_struct_t) field =