This is an automated email from the ASF dual-hosted git repository.
alamb pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/arrow-rs.git
The following commit(s) were added to refs/heads/main by this push:
new 6bb5e2bb3f [Variant] Add nested object and array interoperability
tests (#10637)
6bb5e2bb3f is described below
commit 6bb5e2bb3feabf85a4ee9daeb6511a56a7719c8f
Author: cakeni <[email protected]>
AuthorDate: Thu Aug 20 06:16:42 2026 +0800
[Variant] Add nested object and array interoperability tests (#10637)
# Which issue does this PR close?
- Closes #10617.
# Rationale for this change
The Variant interoperability suite covers primitive objects and arrays
but does not exercise the nested object and array fixtures. This leaves
nested `VariantBuilder` encoding without equivalent fixture-based
coverage.
# What changes are included in this PR?
- Build the `object_nested` fixture with nested object builders and
compare it with the decoded interoperability fixture.
- Build the `array_nested` fixture with nested object/list builders,
including null values, and compare it with the decoded fixture.
# Are these changes tested?
Yes. Both new tests pass against `apache/parquet-testing` commit
`73545118`:
- `cargo test -p parquet-variant --test variant_interop
variant_object_nested_builder`
- `cargo test -p parquet-variant --test variant_interop
variant_array_nested_builder`
# Are there any user-facing changes?
No. This PR adds test coverage only.
## AI assistance
OpenAI Codex assisted with inspecting the existing test coverage and
drafting the additional interoperability tests. I reviewed the final
test cases.
Co-authored-by: Jeffrey Vo <[email protected]>
---
parquet-variant/tests/variant_interop.rs | 66 +++++++++++++++++++++++++++++++-
1 file changed, 65 insertions(+), 1 deletion(-)
diff --git a/parquet-variant/tests/variant_interop.rs
b/parquet-variant/tests/variant_interop.rs
index 83f83c96c3..229ea44937 100644
--- a/parquet-variant/tests/variant_interop.rs
+++ b/parquet-variant/tests/variant_interop.rs
@@ -347,7 +347,71 @@ fn variant_object_builder() {
assert_eq!(actual, expected);
}
-// TODO: Add tests for object_nested and array_nested
+#[test]
+fn variant_object_nested_builder() {
+ let mut builder = VariantBuilder::new();
+
+ let mut obj = builder.new_object();
+ obj.insert("id", 1i8);
+
+ let mut observation = obj.new_object("observation");
+ observation.insert("location", "In the Volcano");
+ observation.insert("time", "12:34:56");
+ let mut value = observation.new_object("value");
+ value.insert("humidity", 456i16);
+ value.insert("temperature", 123i8);
+ value.finish();
+ observation.finish();
+
+ let mut species = obj.new_object("species");
+ species.insert("name", "lava monster");
+ species.insert("population", 6789i16);
+ species.finish();
+ obj.finish();
+
+ let (built_metadata, built_value) = builder.finish();
+ let actual = Variant::try_new(&built_metadata, &built_value).unwrap();
+ let case = Case::load("object_nested");
+ let expected = case.variant();
+
+ assert_eq!(actual, expected);
+}
+
+#[test]
+fn variant_array_nested_builder() {
+ let mut builder = VariantBuilder::new();
+
+ let mut array = builder.new_list();
+ let mut first = array.new_object();
+ first.insert("id", 1i8);
+ let mut thing = first.new_object("thing");
+ let mut names = thing.new_list("names");
+ names.append_value("Contrarian");
+ names.append_value("Spider");
+ names.finish();
+ thing.finish();
+ first.finish();
+
+ array.append_value(());
+
+ let mut third = array.new_object();
+ third.insert("id", 2i8);
+ let mut names = third.new_list("names");
+ names.append_value("Apple");
+ names.append_value("Ray");
+ names.append_value(());
+ names.finish();
+ third.insert("type", "if");
+ third.finish();
+ array.finish();
+
+ let (built_metadata, built_value) = builder.finish();
+ let actual = Variant::try_new(&built_metadata, &built_value).unwrap();
+ let case = Case::load("array_nested");
+ let expected = case.variant();
+
+ assert_eq!(actual, expected);
+}
//
// Validation Fuzzing Tests