Feature Request / Improvement
Problem
VariantTestUtil.createArray pre-computes the data section size by summing sizeInBytes() for each element before allocating the output buffer:
// api/src/test/java/org/apache/iceberg/variants/VariantTestUtil.java:273
for (VariantValue value : values) {
// TODO: produce size for every variant without serializing
dataSize += value.sizeInBytes();
}
This works for pre-serialized values (SerializedPrimitive, SerializedShortString, etc.) where sizeInBytes() is just buffer().remaining(). It breaks down for nested or non-buffer-backed values — e.g. a SerializedArray passed as an element may not reflect the size needed when embedded in a parent array without already being fully serialized.
The same pattern exists in createObject (line 220) without a TODO, but would benefit from the same fix.
Proposed behavior
Provide a way to compute the serialized byte size of any VariantValue without building the full parent buffer first. Options to consider:
- Add a
sizeInBytes() implementation (or helper) that recursively computes size from type/metadata for all variant physical types
- Add a
VariantTestUtil.sizeInBytes(VariantValue) helper that handles nested arrays/objects correctly
- Refactor
createArray / createObject to use it and remove the TODO
createArray should then allocate the correct buffer size for mixed and nested element types without redundant serialization work.
Scope
- Module:
api (test utility — VariantTestUtil.java)
- May touch:
VariantValue / serialized variant classes if a shared size API is added
- Tests:
TestSerializedArray, TestSerializedObject, and any tests using VariantTestUtil.createArray with nested values
- No production API changes unless maintainers prefer a public
sizeInBytes improvement in core variant types
Notes
- Test-only improvement unless core variant sizing is generalized.
createObject uses the same sizeInBytes() loop — consider fixing both together.
- Related tests already cover nested arrays (
TestSerializedArray.testArrayOfMixedTypes).
Query engine
None
Willingness to contribute
Feature Request / Improvement
Problem
VariantTestUtil.createArraypre-computes the data section size by summingsizeInBytes()for each element before allocating the output buffer:This works for pre-serialized values (
SerializedPrimitive,SerializedShortString, etc.) wheresizeInBytes()is justbuffer().remaining(). It breaks down for nested or non-buffer-backed values — e.g. aSerializedArraypassed as an element may not reflect the size needed when embedded in a parent array without already being fully serialized.The same pattern exists in
createObject(line 220) without a TODO, but would benefit from the same fix.Proposed behavior
Provide a way to compute the serialized byte size of any
VariantValuewithout building the full parent buffer first. Options to consider:sizeInBytes()implementation (or helper) that recursively computes size from type/metadata for all variant physical typesVariantTestUtil.sizeInBytes(VariantValue)helper that handles nested arrays/objects correctlycreateArray/createObjectto use it and remove the TODOcreateArrayshould then allocate the correct buffer size for mixed and nested element types without redundant serialization work.Scope
api(test utility —VariantTestUtil.java)VariantValue/ serialized variant classes if a shared size API is addedTestSerializedArray,TestSerializedObject, and any tests usingVariantTestUtil.createArraywith nested valuessizeInBytesimprovement in core variant typesNotes
createObjectuses the samesizeInBytes()loop — consider fixing both together.TestSerializedArray.testArrayOfMixedTypes).Query engine
None
Willingness to contribute