Skip to content

GH-45937: [C++][Parquet] support to read, write and validate variant - #50252

Open
HuaHuaY wants to merge 13 commits into
apache:mainfrom
HuaHuaY:variant
Open

GH-45937: [C++][Parquet] support to read, write and validate variant#50252
HuaHuaY wants to merge 13 commits into
apache:mainfrom
HuaHuaY:variant

Conversation

@HuaHuaY

@HuaHuaY HuaHuaY commented Jun 25, 2026

Copy link
Copy Markdown
Contributor

Rationale for this change

This PR supports:

  • Mapping between arrow extension variant type and Parquet variant type
  • Reading and writing unshred and shredded variant arrays.
  • Validate whether a variant array follows parquet format.

This PR does not support:

  • Accumulate record batch and inferring typed_value shredded data from the value array

What changes are included in this PR?

  • variant/format_internal.h:
    Define some type-related traits and concepts.

  • variant/builder.h .cc:
    Add builders for encoded Variant values, arrays, nested objects and lists, and residual value arrays. This part shares a similar design with arrow-rs, but differs slightly because C++ lacks enum types that hold values. It employs a single-buffer builder design and also supports nested builder APIs. Some previous discussions: [C++][Parquet] Encoding tools for variant type #46555

  • variant/decoding.h .cc:
    Add zero-copy views with shallow parsing and recursive validation.

  • variant/shred.h .cc:
    Convert an unshredded VariantArray into a requested primitive, object, or list typed_value layout while retaining incompatible values in residual value.

  • variant/unshred.h .cc:
    Reconstruct encoded Variant values from shredded storage.

  • variant/validate.h .cc:
    Validate nested Variant arrays using strict writer rules or read-compatible rules. To avoid too much materialization of bitmaps, this module employs a two-pass design: first constructing the plan and finding variant, then executing it.

  • variant/slot_internal.h .cc:
    Compile shredded storage layouts and process primitive, object, and list slots for validation and unshredding. This is a common module used by unshred and validate.

Some code use template <bool strict> because some schemas are read-compatible but do not support writing. For details, please see apache/parquet-format#591

Are these changes tested?

Yes.

Are there any user-facing changes?

ArrowReaderProperties adds set_variant_validation_enabled(). ArrowWriterProperties::Builder adds set_variant_validation_enabled(). Validation is enabled by default.

Comment thread cpp/src/parquet/properties.h
Comment thread cpp/src/arrow/extension/CMakeLists.txt Outdated
return field->type()->storage_id() == Type::BINARY ||
field->type()->storage_id() == Type::LARGE_BINARY;

bool IsSupportedPrimitiveTypedValue(const std::shared_ptr<DataType>& type) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems that some Arrow primitive types are missing from here: https://arrow.apache.org/docs/format/CanonicalExtensions.html#primitive-type-mappings

@HuaHuaY HuaHuaY Jul 27, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This issue is still under discussion; those interested, please head over to #50622

Comment thread cpp/src/parquet/variant/validate.h Outdated
Comment thread cpp/src/arrow/extension/variant/encoding.h Outdated
Comment thread cpp/src/arrow/extension/variant/encoding.h Outdated
@github-actions github-actions Bot added awaiting committer review Awaiting committer review and removed awaiting review Awaiting review labels Jun 26, 2026
Comment thread cpp/src/parquet/variant/decoding.h
Comment thread cpp/src/parquet/variant/encoding.h Outdated
Comment thread cpp/src/arrow/extension/variant/encoding.h Outdated
Comment thread cpp/src/parquet/variant/encoding.cc Outdated
@HuaHuaY
HuaHuaY force-pushed the variant branch 2 times, most recently from c5c54dc to a16f004 Compare July 2, 2026 12:20
@HuaHuaY
HuaHuaY force-pushed the variant branch 3 times, most recently from 9086570 to 63e8a1a Compare July 21, 2026 12:17
@HuaHuaY HuaHuaY changed the title GH-45937: [C++][Parquet] support to encode, write and validate variant GH-45937: [C++][Parquet] support to read, write and validate variant Jul 21, 2026
@HuaHuaY
HuaHuaY force-pushed the variant branch 8 times, most recently from de57207 to c343ded Compare July 22, 2026 13:27
@HuaHuaY
HuaHuaY marked this pull request as ready for review July 27, 2026 10:07
@HuaHuaY
HuaHuaY requested a review from pitrou as a code owner July 27, 2026 10:07

if(MSVC)
set_source_files_properties(variant/builder.cc variant/slot_internal.cc
PROPERTIES COMPILE_OPTIONS /Zc:preprocessor)

@HuaHuaY HuaHuaY Jul 27, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kou @raulcd We use C++20 to develop this repo now and MSVC has a new preprocesser to handle C++20 grammar like __VA_OPT__. Should we add this flag globally? We can try to add the flag in a new PR.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably? I would try it on a different PR, as suggested, and investigate whether we can drop:

# Disable C5105 (macro expansion producing 'defined' has undefined
# behavior) warning because there are codes that produce this
# warning in Windows Kits. e.g.:
#
# #define _CRT_INTERNAL_NONSTDC_NAMES \
# ( \
# ( defined _CRT_DECLARE_NONSTDC_NAMES && _CRT_DECLARE_NONSTDC_NAMES) || \
# (!defined _CRT_DECLARE_NONSTDC_NAMES && !__STDC__ ) \
# )
#
# See also:
# * C5105: https://docs.microsoft.com/en-US/cpp/error-messages/compiler-warnings/c5105
# * Related reports:
# * https://developercommunity.visualstudio.com/content/problem/387684/c5105-with-stdioh-and-experimentalpreprocessor.html
# * https://developercommunity.visualstudio.com/content/problem/1249671/stdc17-generates-warning-compiling-windowsh.html
set(CXX_COMMON_FLAGS "${CXX_COMMON_FLAGS} /wd5105")

@HuaHuaY

HuaHuaY commented Jul 27, 2026

Copy link
Copy Markdown
Contributor Author

@pitrou @emkornfield Can you help to review the API design? I’ve tried to keep the code concise, but this is still a huge PR. I’d like to focus on the overall API design for now, and then I’ll break this PR down into several smaller ones. I include brief introductions to each module in the PR description.

@github-actions github-actions Bot added awaiting changes Awaiting changes and removed awaiting committer review Awaiting committer review labels Jul 27, 2026
@github-actions github-actions Bot added awaiting change review Awaiting change review and removed awaiting changes Awaiting changes labels Jul 27, 2026
@emkornfield

Copy link
Copy Markdown
Contributor

@pitrou @emkornfield Can you help to review the API design?

@HuaHuaY thanks for the PR. Which files contain the API design we should focus on?

@HuaHuaY

HuaHuaY commented Jul 28, 2026

Copy link
Copy Markdown
Contributor Author

Which files contain the API design we should focus on?

I'm sorry what I said earlier wasn't clear enough. I would like your help reviewing whether the implementation approach is appropriate and whether the provided interfaces are easy to use. As for specific code details, we can review those later in smaller, separate PRs.

You can start by reviewing these header files, and I consider them to be the parts directly used by the user:

  • cpp/src/parquet/variant/format.h
  • cpp/src/arrow/extension/parquet_variant.h
  • cpp/src/parquet/variant/builder.h
  • cpp/src/parquet/variant/shred.h and cpp/src/parquet/variant/unshred.h

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants