This is an automated email from the ASF dual-hosted git repository.
paleolimbot 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 ea907d2b feat: Support run-end encoded arrays in the IPC reader (#996)
ea907d2b is described below
commit ea907d2bb66e6decf6e0345880dad0d870a83a66
Author: ump45nose <[email protected]>
AuthorDate: Fri Nov 6 23:11:50 2026 +0800
feat: Support run-end encoded arrays in the IPC reader (#996)
Closes #833.
The IPC encoder already writes the `RunEndEncoded` type, but the decoder
stopped at the schema with "RunEndEncoded not yet supported in IPC
reader". The `RunEndEncoded` type table has no parameters and a run-end
encoded array has no buffers of its own (only the `run_ends` and
`values` children), so the reader only needs to map the type to the `+r`
format. The existing child field and buffer handling already treats it
like the other buffer-less layouts, and validation of the run ends is
the existing `ArrowArrayView` logic. The new code also checks that the
field has exactly two children so a malformed schema gets a clear error.
### Testing
- Added `run_end_encoded(int16, utf8)`, `run_end_encoded(int32, int64)`
and `run_end_encoded(int64, float64)` to the type list used by the
decoder roundtrip tests (Arrow C++ schema/array -> IPC -> nanoarrow, and
nanoarrow -> IPC -> nanoarrow).
- Switched `cpp-21.0.0/generated_run_end_encoded.stream` from
`NotSupported` to `OK` in `files_test.cc`, so the arrow-testing file is
read and compared with Arrow C++'s read, and nanoarrow's written stream
is read back by Arrow C++. (The JSON check for that file is still
skipped because the testing JSON reader does not know run-end encoded
yet.)
- Without the decoder change, 6 of the new roundtrip tests and the file
test fail; with it they pass.
- Debug build with `NANOARROW_IPC=ON NANOARROW_BUILD_TESTS=ON
NANOARROW_BUILD_TESTS_WITH_ARROW=ON` against Arrow C++ 26.0.0 and
current apache/arrow-testing: `ctest` 896/896 passed.
- clang-format 16.0.6 (the pre-commit version) applied.
This PR was prepared with AI assistance; I reviewed the changes and ran
the checks above.
---
src/nanoarrow/ipc/decoder.c | 19 +++++++++++++++++--
src/nanoarrow/ipc/decoder_test.cc | 4 ++++
src/nanoarrow/ipc/files_test.cc | 2 +-
3 files changed, 22 insertions(+), 3 deletions(-)
diff --git a/src/nanoarrow/ipc/decoder.c b/src/nanoarrow/ipc/decoder.c
index e0239074..e47a652e 100644
--- a/src/nanoarrow/ipc/decoder.c
+++ b/src/nanoarrow/ipc/decoder.c
@@ -1203,6 +1203,22 @@ static int ArrowIpcDecoderSetTypeUnion(struct
ArrowSchema* schema,
return ArrowIpcDecoderSetTypeSimpleNested(schema, union_types_str, error);
}
+static int ArrowIpcDecoderSetTypeRunEndEncoded(struct ArrowSchema* schema,
+ int64_t n_children,
+ struct ArrowError* error) {
+ // The RunEndEncoded type table has no parameters: the run ends and values
+ // types are carried by its two children (run_ends, then values)
+ if (n_children != 2) {
+ ArrowErrorSet(error,
+ "Expected RunEndEncoded field to have exactly two children
but found "
+ "%" PRId64,
+ n_children);
+ return EINVAL;
+ }
+
+ return ArrowIpcDecoderSetTypeSimpleNested(schema, "+r", error);
+}
+
static int ArrowIpcDecoderSetType(struct ArrowSchema* schema,
ns(Field_table_t) field,
int64_t n_children, struct ArrowError*
error) {
ns(Type_union_type_t) type_type = ns(Field_type_type(field));
@@ -1266,8 +1282,7 @@ static int ArrowIpcDecoderSetType(struct ArrowSchema*
schema, ns(Field_table_t)
case ns(Type_Union):
return ArrowIpcDecoderSetTypeUnion(schema, type, n_children, error);
case ns(Type_RunEndEncoded):
- ArrowErrorSet(error, "RunEndEncoded not yet supported in IPC reader");
- return ENOTSUP;
+ return ArrowIpcDecoderSetTypeRunEndEncoded(schema, n_children, error);
default:
ArrowErrorSet(error, "Unrecognized Field type with value %d", type_type);
return EINVAL;
diff --git a/src/nanoarrow/ipc/decoder_test.cc
b/src/nanoarrow/ipc/decoder_test.cc
index 8f89acc6..17de84d4 100644
--- a/src/nanoarrow/ipc/decoder_test.cc
+++ b/src/nanoarrow/ipc/decoder_test.cc
@@ -2039,6 +2039,10 @@ INSTANTIATE_TEST_SUITE_P(
arrow::dense_union({arrow::field("col1", arrow::int32()),
arrow::field("col2", arrow::utf8())},
{126, 127}),
+ // Run-end encoded
+ arrow::run_end_encoded(arrow::int16(), arrow::utf8()),
+ arrow::run_end_encoded(arrow::int32(), arrow::int64()),
+ arrow::run_end_encoded(arrow::int64(), arrow::float64()),
// Type with nested metadata
arrow::list(arrow::field("some_custom_name", arrow::int32(),
diff --git a/src/nanoarrow/ipc/files_test.cc b/src/nanoarrow/ipc/files_test.cc
index cc15a525..501b9249 100644
--- a/src/nanoarrow/ipc/files_test.cc
+++ b/src/nanoarrow/ipc/files_test.cc
@@ -620,7 +620,7 @@ INSTANTIATE_TEST_SUITE_P(
TestFile::OK("cpp-21.0.0/generated_nested_dictionary.stream"),
TestFile::NotSupported("cpp-21.0.0/generated_list_view.stream"),
TestFile::NotSupported("cpp-21.0.0/generated_binary_view.stream"),
- TestFile::NotSupported("cpp-21.0.0/generated_run_end_encoded.stream")
+ TestFile::OK("cpp-21.0.0/generated_run_end_encoded.stream")
// Comment to keep line from wrapping
));