Skip to content

[c] Preserve native VARIANT payloads in Arrow reads - #1518

Open
miomiocat wants to merge 1 commit into
apache:mainfrom
miomiocat:codex/c-native-variant
Open

miomiocat wants to merge 1 commit into
apache:mainfrom
miomiocat:codex/c-native-variant

Conversation

@miomiocat

Copy link
Copy Markdown

Purpose

Closes #1517.

Preserve the bytes and scalar types of valid VARIANT values across the Arrow C interface, and make SQL NULL distinguishable from an encoded variant null.

Brief change log

  • Canonicalize VARIANT columns from the projected Paimon schema, including fields nested inside arrays, maps and rows.
  • Translate legacy empty payload pairs to struct nulls, validate non-null payloads, and reject an incomplete pair. Ordinary binary row fields keep their own semantics.

Tests

Added Arrow C Data round-trip cases, non-JSON scalar types, sliced SQL and variant nulls, incomplete payloads, nested values, ordinary rows and empty batches.

Local verification passed with cargo build --locked -p paimon-c --lib and cargo fmt --all -- --check. Test execution is left to upstream CI.

API and Format

The existing Arrow C read returns a struct with binary value and metadata children and uses the outer validity bitmap for SQL NULL.

Documentation

The C binding guide describes the payload fields and null representation.

Export Paimon value and metadata buffers using struct validity for SQL
NULL. Preserve encoded variant nulls and scalar types in top-level and
nested values, and reject incomplete payloads.

Co-Authored-By: Codex <noreply@openai.com>
AI-Model: gpt-6
AI-Contributed/Feature: 611/611
AI-Contributed/UT: 0/0

@JingsongLi JingsongLi left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I verified the C read end to end on a Parquet table. The base read exposed an empty payload pair and encoded Variant null as two valid structs. This head sets SQL NULL validity for the empty pair and preserves the encoded null. All 113 C tests passed. Two additional nested cases reproduced the gaps below. A fixture from the affected Java writer would also document which legacy output needs this conversion.

.fields()
.iter()
.any(|field| contains_variant(field.data_type())),
_ => false,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

[P2] Normalize VARIANT nested inside MULTISET elements. Paimon's Arrow mapping stores a multiset as a map whose key is the element type. I wrote and read a Parquet table with MULTISET<ROW<v VARIANT>> through the C API. The empty-pair SQL NULL and the encoded Variant null both came back valid inside the key. Recurse through the multiset key, leaving the count unchanged.

.downcast_ref::<ListArray>()
.ok_or_else(|| invalid_array(path, "ListArray", array.data_type()))?;
let values = canonicalize_variants(
input.values(),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

[P2] Limit ARRAY and MAP normalization to entries visible in the current batch. Arrow slices keep their backing child arrays, and merged Data Evolution reads emit slices of source columns. A two-row ListArray with an incomplete Variant only in the second row failed normalization when I passed a slice containing just the valid first row. Use the active offsets and parent validity when traversing children, like Core's nested evolution logic. This also avoids revalidating the full source array for each emitted slice.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Preserve native VARIANT payloads and SQL nulls in C Arrow reads

2 participants