GH-45947 : [C++][Parquet] Variant encoding#50122
Open
qzyu999 wants to merge 2 commits into
Open
Conversation
|
Thanks for opening a pull request! If this is not a minor PR. Could you open an issue for this pull request on GitHub? https://github.com/apache/arrow/issues/new/choose Opening GitHub issues ahead of time contributes to the Openness of the Apache Arrow project. Then could you also rename the pull request title in the following format? or See also: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Note: This PR depends on #45946 (Variant decoding) and is branched from it. Please review/merge #45946 first. After it merges, this PR will be retargeted to
main.Rationale for this change
This is part of the GH-45937 umbrella (Add variant support to C++ Parquet). It adds the encoding (writing) side of the Variant binary format, building on the decoder from GH-45946. The encoder is required for GH-45948 (variant shredding) and for any Parquet writer that needs to produce Variant columns.
As with the decoder, the implementation targets feature parity with the arrow-go
parquet/variant.Builder, adapted to idiomatic C++ patterns. Divergences are deliberate and documented.What changes are included in this PR?
Adds
VariantBuilderclass invariant_internal.h/variant_builder.ccfor encoding Variant binary values per the Variant Encoding Spec.Builder API:
Null(),Bool(),Int()(auto-sizes),Int8/16/32/64(),Float(),Double(),Date(),TimestampMicros/NTZ(),TimestampNanos/NTZ(),TimeNTZ(),Decimal4/8/16(),String()(auto short-string for ≤63 bytes),Binary(),UUID()Offset()/NextElement()/FinishArray()for arrays,NextField()/FinishObject()for objectsFinish()— produces encoded metadata + value buffers with sorted-flag detectionReset()— clears buffer for builder reuse; dictionary preserved acrossFinish()callsVariantMetadatafor shared-dictionary workflowsKey design points:
noexceptmovable)FinishObject()sorts fields in-place by key — spec requires field IDs in lexicographic key orderStatus::Invalid) — spec says "An object may not contain duplicate keys"; configurable tolerance deferred to GH-45937: [C++][Parquet] Variant shredding #45948 with TODOFinishArray()validates offsets are non-negativeFinish()validates total dictionary size fits in 4-byte offsetsmetadataMaxSizeLimit); C++ only enforces the spec's ~4GB 4-byte offset maximumTODOs for GH-45948 (shredding):
Are these changes tested?
Yes. 238 total tests pass with
BUILD_WARNING_LEVEL=CHECKIN(73 encoder + 165 decoder):Int8/16/32/64without auto-sizing (4 tests)is_largeflag: 300-element array + 300-field object (2 tests)Finish()calls (2 tests)Are there any user-facing changes?
No breaking changes. This extends the public API added in GH-45946 with the
VariantBuilderclass in the samearrow::extension::variantnamespace.AI Disclosure: AI coding assistants were used during development for scaffolding, test generation, and review iteration. All code has been reviewed, debugged, and verified by the author who owns and understands the changes.