Skip to content

API: Compute variant element sizes in VariantTestUtil - #17934

Open
dkranchii wants to merge 1 commit into
apache:mainfrom
dkranchii:variant-test-util-compute-sizes
Open

API: Compute variant element sizes in VariantTestUtil#17934
dkranchii wants to merge 1 commit into
apache:mainfrom
dkranchii:variant-test-util-compute-sizes

Conversation

@dkranchii

Copy link
Copy Markdown

Summary

  • Resolve the existing TODO in VariantTestUtil.createArray by introducing a shared sizeInBytes(VariantValue) helper that derives serialized byte size from the physical type instead of calling VariantValue.sizeInBytes() directly.
  • Apply the same helper to VariantTestUtil.createObject, so both container builders compute sizes consistently and remain correct for nested or non-buffer-backed values.
  • The helper returns buffer().remaining() for pre-serialized values, computes primitives from their PhysicalType (with special handling for STRING/BINARY), recurses into arrays, and delegates to VariantValue.sizeInBytes() only for non-serialized OBJECT (whose field-id size requires the object's own metadata).

Closes #17510.

Test plan

  • New TestVariantTestUtil covers the helper for serialized primitives, short strings, long strings, flat and nested serialized arrays, and asserts that the computed size equals the number of bytes actually written by writeTo.
  • Existing TestSerializedArray and TestSerializedObject continue to exercise createArray/createObject end-to-end.
  • Local checks:
    • ./gradlew spotlessCheck
    • ./gradlew :iceberg-api:test

AI Disclosure

  • Platform/Tool: Cursor

@github-actions github-actions Bot added the API label Sep 3, 2026
Replace the direct `VariantValue.sizeInBytes()` calls used by
`VariantTestUtil.createArray` and `createObject` with a shared
`sizeInBytes(VariantValue)` helper that derives the serialized byte size
from the physical type (recursing into arrays and returning
`buffer().remaining()` for pre-serialized values). This resolves the
existing TODO in `createArray` and applies the same treatment to
`createObject`, making the test util robust when nested or
non-buffer-backed values are supplied.
@dkranchii
dkranchii force-pushed the variant-test-util-compute-sizes branch from 195bca6 to 6b29651 Compare September 3, 2026 00:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

API: Compute variant sizes without full serialization in VariantTestUtil

1 participant