Skip to content

branch-4.1: [feature](paimon) Support Variant V2 writes - #66321

Merged
yiguolei merged 14 commits into
apache:branch-4.1from
suxiaogang223:codex/paimon-variant-write
Aug 10, 2026
Merged

branch-4.1: [feature](paimon) Support Variant V2 writes#66321
yiguolei merged 14 commits into
apache:branch-4.1from
suxiaogang223:codex/paimon-variant-write

Conversation

@suxiaogang223

Copy link
Copy Markdown
Member

What problem does this PR solve?

Issue Number: Part of #65086

Problem Summary:

The Paimon JNI writer already supports primitive and complex Doris columns, but a Doris Variant V2 value could not be written losslessly because the generic Arrow path exposed Variant as JSON text. That loses the native Variant value and metadata representation and does not support Variant nested in ARRAY, MAP, or STRUCT.

This PR adds a Paimon-specific Variant V2 write protocol:

  • maps Paimon VARIANT targets, including nested VARIANT nodes, to Doris compute Variant V2 during analysis;
  • requires enable_variant_v2=true and rejects legacy Variant V1 inputs during analysis with an actionable error;
  • transports Variant V2 through Arrow as struct<value: binary, metadata: binary> while preserving SQL NULL separately from a Variant null value;
  • recursively applies the binary representation inside ARRAY, MAP, and STRUCT;
  • converts the Arrow pair to Paimon GenericVariant in the Java JNI backend and uses Paimon SDK accessors to validate compatibility with the bundled Paimon version;
  • keeps the existing JSON Arrow representation as the default for non-Paimon consumers.

Supported write scenarios

  • INSERT INTO ... VALUES and INSERT INTO ... SELECT, including UNION inputs and reordered/omitted columns.
  • INSERT OVERWRITE and static partition writes.
  • Append-only and primary-key tables, fixed and dynamic bucket modes, and schema evolution involving VARIANT columns.
  • Top-level VARIANT and VARIANT nested in ARRAY, MAP, STRUCT, and deeper combinations.
  • Scalar/object/array values, SQL NULL, Variant null, typed primitives, long strings, and residual object fields.
  • Paimon Parquet Variant shredding. Regression coverage verifies the physical typed_value layout and values, Paimon unshredding, type-mismatch fallback to residual bytes, and reading a table containing both unshredded and shredded files.

Current limitations

  • Variant writes are V2-only. When enable_variant_v2=false, or when a legacy Variant V1 expression is supplied to a Paimon VARIANT target, analysis fails intentionally.
  • The write path uses the Java Paimon JNI backend.
  • Doris-side querying of Paimon Variant V2 is outside this PR. End-to-end logical readback is therefore verified with the Spark/Paimon reader; raw Parquet shredding is independently verified through Doris's S3 TVF.
  • The added Paimon integration coverage uses Parquet, which is also the format used to validate Variant shredding.

Release note

Support writing Variant V2 values, including nested Variant values, from Doris into Apache Paimon tables through the Java JNI writer. Set enable_variant_v2=true before writing a Paimon table containing VARIANT.

Check List (For Author)

  • Test

    • Regression test
    • Unit Test
    • Manual test
      • Debug FE and BE incremental builds.
      • ./run-regression-test.sh --run -s test_paimon_write_variant_shredding
      • ./run-regression-test.sh --run -s test_paimon_write_variant_table_modes
  • Behavior changed:

    • No.
    • Yes. Paimon VARIANT targets now accept Variant V2 writes when enabled and reject disabled/V1 writes during analysis.
  • Does this need documentation?

    • No.
    • Yes. User-facing documentation can follow separately.

Check List (For Reviewer who merge this PR)

  • Confirm the release note
  • Confirm test cases
  • Confirm document
  • Add branch pick label

@hello-stephen

Copy link
Copy Markdown
Contributor

Thank you for your contribution to Apache Doris.
Don't know what should be done next? See How to process your PR.

Please clearly describe your PR:

  1. What problem was fixed (it's best to include specific error reporting information). How it was fixed.
  2. Which behaviors were modified. What was the previous behavior, what is it now, why was it modified, and what possible impacts might there be.
  3. What features were added. Why was this function added?
  4. Which code was refactored and why was this part of the code refactored?
  5. Which functions were optimized and what is the difference before and after the optimization?

@suxiaogang223
suxiaogang223 marked this pull request as ready for review July 31, 2026 08:00
@suxiaogang223

Copy link
Copy Markdown
MemberAuthor

run buildall

@suxiaogang223

Copy link
Copy Markdown
MemberAuthor

/review

@github-actionsgithub-actionsBot 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.

Request changes: three P1 defects and one P2 repository-contract issue.

Correctness and analysis:

  • Heterogeneous multi-row VALUES are coerced to one common primitive type before the Variant sink cast, silently changing per-row Variant types.
  • The Paimon analyzer accepts Variant V2 source shapes and scalar types that the BE kernel cannot execute, including legacy leaves hidden by shape changes and FE-admitted unsupported sources.
  • The new BE Arrow test constructs an explicitly unsupported typed TIMEV2 Variant and deterministically aborts before serialization.

Transport and compatibility:

  • I traced encoded, typed, const, nullable, sliced, and nested Variant values through the C++ Arrow builders, IPC ownership, Java conversion, and Paimon compatibility walk. Aside from the failing test input above, byte ownership, null/child alignment, and the private Doris-produced compatibility boundary did not reveal another defect.
  • The table-wide enable_variant_v2 gate matches the PR's documented opt-in policy.

Repository guidance:

  • All four touched checkLegalityBeforeTypeCoercion overrides still bypass the required getArgument/getArguments accessors.

Tests and validation:

  • This was a static-only review as required by the runner instructions; no local builds or tests were run. The added coverage is broad, but it lacks regressions for the accepted analysis/coercion cases and contains the deterministic test-construction failure called out inline.

User focus and completion:

  • No additional user-provided review focus was supplied, so the complete 29-file PR diff was reviewed.
  • Review completed after three bounded convergence rounds, final changed-file and unresolved-candidate sweeps, and a live head/duplicate check.

Comment threadbe/test/core/data_type_serde/data_type_variant_v2_serde_output_test.cpp Outdated
@hello-stephen

Copy link
Copy Markdown
Contributor

FE UT Coverage Report

Increment line coverage 49.09% (54/110) 🎉
Increment coverage report
Complete coverage report

@hello-stephen

Copy link
Copy Markdown
Contributor

FE Regression Coverage Report

Increment line coverage 32.73% (36/110) 🎉
Increment coverage report
Complete coverage report

Comment threadregression-test/suites/paimon_write/test_paimon_write_variant_dml.groovy Outdated
Comment threadregression-test/suites/paimon_write/test_paimon_write_variant.groovy Outdated
@suxiaogang223
suxiaogang223force-pushed the codex/paimon-variant-write branch from 6d244a3 to fa39ea6CompareAugust 3, 2026 10:57
@suxiaogang223

Copy link
Copy Markdown
MemberAuthor

run buildall

@hello-stephen

Copy link
Copy Markdown
Contributor

BE UT Coverage Report

Increment line coverage 80.95% (51/63) 🎉

Increment coverage report
Complete coverage report

CategoryCoverage
Function Coverage58.04% (24314/41891)
Line Coverage42.14% (242705/575975)
Region Coverage38.21% (191652/501528)
Branch Coverage39.53% (87220/220663)

@suxiaogang223

Copy link
Copy Markdown
MemberAuthor

/review

@github-actionsgithub-actionsBot 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.

Static review of the full 49-file change at c5bacf78662f73a05ac5ddf2df92eb92f3da6f85 found six blocking issues: the new BinaryBuilder transport can overflow on a batch of individually valid Variants; the Paimon 1.4.2 bump breaks mixed-version serialized table/split payloads; the Docker fixture still lacks the newly mounted 1.4.2 jars; the Java-UDF assembly leaves an orphan standard-JDK chronology provider descriptor; FE admits non-empty ARRAY although the BE encoder rejects it; and the dynamic-bucket regression cannot detect key/payload permutation.

I also traced the required legality-check accessors, nested Variant/null/ownership paths, Paimon wrapper precedence, overwrite binding/commit lifecycle, SDK artifacts, and the remaining regression surface. Those paths did not yield additional non-duplicate findings. There was no additional user-provided review focus, so the whole PR was reviewed. The repository code-review skill was absent from this checkout; the authoritative review bundle and required AGENTS policy were followed directly. This was a static-only review; no builds or tests were run.

Comment threadbe/src/core/data_type_serde/data_type_variant_v2_serde.cpp
Comment threaddocker/thirdparties/docker-compose/iceberg/iceberg.yaml.tpl
Comment threadfe/pom.xml
@suxiaogang223

Copy link
Copy Markdown
MemberAuthor

run buildall

@hello-stephen

Copy link
Copy Markdown
Contributor

BE Regression && UT Coverage Report

Increment line coverage 81.69% (116/142) 🎉

Increment coverage report
Complete coverage report

CategoryCoverage
Function Coverage73.62% (30318/41184)
Line Coverage57.49% (332462/578256)
Region Coverage54.36% (276552/508788)
Branch Coverage55.33% (123754/223673)

@suxiaogang223

Copy link
Copy Markdown
MemberAuthor

run external

@suxiaogang223
suxiaogang223force-pushed the codex/paimon-variant-write branch from 1fed9fc to 3cfafb2CompareAugust 5, 2026 03:02
@suxiaogang223

Copy link
Copy Markdown
MemberAuthor

run buildall

@suxiaogang223
suxiaogang223force-pushed the codex/paimon-variant-write branch from 553c6f7 to 9a32163CompareAugust 7, 2026 06:29
@suxiaogang223
suxiaogang223force-pushed the codex/paimon-variant-write branch from 9a32163 to ea5fa27CompareAugust 7, 2026 07:07
@suxiaogang223

Copy link
Copy Markdown
MemberAuthor

run buildall

@suxiaogang223

Copy link
Copy Markdown
MemberAuthor

/review

@github-actions

Copy link
Copy Markdown
Contributor

Codex automated review failed and did not complete.

Error: All Codex review accounts are usage-limited; earliest retry is 2026-08-08T03:32:00Z.
Workflow run: https://github.com/apache/doris/actions/runs/31160789496

Please trigger /review again after that time.

@suxiaogang223suxiaogang223 changed the title [feature](paimon) Support Variant V2 writesbranch-4.1: [feature](paimon) Support Variant V2 writesAug 7, 2026
Comment threadbe/src/core/data_type_serde/data_type_variant_v2_serde.cpp
Comment threadbe/src/core/data_type_serde/data_type_variant_v2_serde.cpp
@hello-stephen

Copy link
Copy Markdown
Contributor

FE UT Coverage Report

Increment line coverage 53.41% (94/176) 🎉
Increment coverage report
Complete coverage report

@hello-stephen

Copy link
Copy Markdown
Contributor

FE Regression Coverage Report

Increment line coverage 74.43% (131/176) 🎉
Increment coverage report
Complete coverage report

@suxiaogang223

Copy link
Copy Markdown
MemberAuthor

run buildall

1 similar comment
@suxiaogang223

Copy link
Copy Markdown
MemberAuthor

run buildall

@Gabriel39

Copy link
Copy Markdown
Contributor

/review

@github-actions

Copy link
Copy Markdown
Contributor

Codex automated review failed and did not complete.

Error: Review step was failure (possibly timeout or cancelled)
Workflow run: https://github.com/apache/doris/actions/runs/31318357740

Please inspect the workflow logs and rerun the review after the underlying issue is resolved.

github-actions[bot]
github-actionsBot previously requested changes Aug 9, 2026

@github-actionsgithub-actionsBot 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.

Review result

Requesting changes for four distinct pre-sink Variant V2 type-loss mechanisms, grouped into two inline comments at their shared changed-line anchors:

  1. Container unification can scalarize a V2 leaf both inside a heterogeneous Array/CreateMap and later when indexed-Any array functions combine independently homogeneous arrays.
  2. Result coercion can scalarize V2 before Paimon validation through heterogeneous set/conditional/selector expressions, while one-argument LEAD/LAG can select a trivial scalar signature and turn object/array roots into NULL.

I did not duplicate the current-head threads covering the non-Parquet Variant format fence, aggregate Arrow/IPC sizing, repeated shared-metadata validation/copying, mixed Paimon serialization versions, or the ServiceLoader descriptor. The final static sweep also confirmed the changed legality hooks use getArgument(s), recursive no-op layout checks retain exact container/field structure, writer and committer share the configured overwrite binding, fallback order matches the adjacent factory precedence, and the changed tests reach their intended existing fixes.

This review is capped and incomplete rather than converged: the third and final permitted round produced two new valuable findings, and the review contract permits no fourth round. All four substantiated mechanisms are reported here, but I cannot claim a clean convergence round for this head.

No additional user-provided focus was specified. No builds or tests were run, as required by the review contract; this was a full static review of the authoritative bundle at 027e11f67c1296d78118a87d5a31be3bd6b9935a.

Gabriel39
Gabriel39 previously approved these changes Aug 10, 2026
@github-actions

Copy link
Copy Markdown
Contributor

PR approved by at least one committer and no changes requested.

@github-actionsgithub-actionsBot added the approved Indicates a PR has been approved by one committer. label Aug 10, 2026
@yiguolei

Copy link
Copy Markdown
Contributor

skip buildall

@github-actionsgithub-actionsBot removed the approved Indicates a PR has been approved by one committer. label Aug 10, 2026
@yiguolei

Copy link
Copy Markdown
Contributor

skip buildall

@yiguolei
yiguolei merged commit 4c2c191 into apache:branch-4.1Aug 10, 2026
36 of 39 checks passed
suxiaogang223 added a commit to suxiaogang223/doris that referenced this pull request Sep 3, 2026
### What problem does this PR solve?
Issue Number: closeapache#65086
Related PR: apache#66321
Problem Summary: Forward-port Variant V2 serialization for Paimon Arrow batches, including encoded value/type byte pairs, outer-null preservation, supported nested constructors, and array-to-Variant conversion behavior.
### Release note
Support writing Variant V2 values to Paimon tables.
### Check List (For Author)
- Test: Unit Test
- Added serialization and cast coverage; BE format/check and FE checkstyle passed. Final compilation and test execution are deferred until all forward-port picks are complete.
- Behavior changed: Yes, Variant V2 values can be serialized for Paimon writes.
- Does this need documentation: No
suxiaogang223 added a commit to suxiaogang223/doris that referenced this pull request Sep 3, 2026
### What problem does this PR solve?
Issue Number: closeapache#65086
Related PR: apache#66321
Problem Summary: The Variant V2 forward-port referenced a branch-specific arguments field while validating ARRAY children. Master exposes legality-check inputs through getArguments(), so FE compilation failed. Use the master expression API while preserving validation of every array argument.
### Release note
None
### Check List (For Author)
- Test: Manual test
- FE compilation identified the issue; final incremental build follows this commit
- Behavior changed: No
- Does this need documentation: No
Sign up for freeto 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.

4 participants

@suxiaogang223@hello-stephen@Gabriel39@yiguolei