Skip to content

fix: preserve target extension metadata in INSERT - #24971

Open
osipovartem wants to merge 4 commits into
apache:mainfrom
Embucket:upstream-insert-target-field
Open

fix: preserve target extension metadata in INSERT#24971
osipovartem wants to merge 4 commits into
apache:mainfrom
Embucket:upstream-insert-target-field

Conversation

@osipovartem

Copy link
Copy Markdown
Contributor

Which issue does this PR close?

Rationale for this change

INSERT currently aligns source expressions with target columns by storage DataType only. If both fields use the same storage type but the target is an Arrow extension type, the cast is skipped and the DML projection loses the target extension metadata. A table sink can then receive a schema that does not describe the target logical type.

What changes are included in this PR?

After storage-type coercion, compare the resulting field metadata with the target table field. When they differ, use the existing field-aware Cast representation to enforce the target metadata. Existing casts are replaced rather than nested.

The regression uses an unannotated FixedSizeBinary(16) source and an arrow.uuid target so the behavior is independent of any particular downstream consumer. Existing parameterized UUID INSERT snapshots are updated to show the target field-aware cast.

What is the testing strategy for this PR?

  • Added plan_insert_preserves_target_extension_metadata.
  • Ran all 575 datafusion-sql integration tests.
  • Ran cargo clippy -p datafusion-sql --all-targets --all-features -- -D warnings.
  • Ran cargo fmt --all -- --check.

Are there any user-facing changes?

Yes. SQL INSERT plans now preserve target Arrow field metadata, including extension metadata. There are no public API changes.

@codecov-commenter

codecov-commenter commented Sep 6, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 92.30769% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 81.67%. Comparing base (262936e) to head (b5ae6ff).

Files with missing lines Patch % Lines
datafusion/sql/src/statement.rs 92.30% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #24971      +/-   ##
==========================================
- Coverage   81.67%   81.67%   -0.01%     
==========================================
  Files        1126     1126              
  Lines      414842   414855      +13     
  Branches   414842   414855      +13     
==========================================
- Hits       338841   338838       -3     
- Misses      56070    56080      +10     
- Partials    19931    19937       +6     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@ryux1 ryux1 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.

Reviewed both paths of the field-aware coercion. When storage types already match, the added Cast::new_from_field supplies the target extension metadata; when cast_to already produced a cast, replacing that cast preserves its child and conversion while avoiding a redundant nested cast. The metadata-only and storage-type-conversion tests exercise those branches, and the final alias still enforces the target column name. This looks good to me.

@osipovartem
osipovartem force-pushed the upstream-insert-target-field branch from 602d867 to 2599861 Compare September 6, 2026 16:38
@osipovartem
osipovartem requested a review from ryux1 September 6, 2026 17:46

@ryux1 ryux1 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.

Thanks, Artem. I re-reviewed b5ae6ff: limiting the field-aware cast to actual extension types keeps the fix scoped and avoids promising propagation of arbitrary field metadata. I also ablated the new guard and confirmed the ordinary-metadata regression test fails without it, then restored the change and ran the focused INSERT tests successfully. The remaining hosted jobs are still pending, but the updated code and coverage look good to me.

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

Labels

sql SQL Planner

Projects

None yet

Development

Successfully merging this pull request may close these issues.

INSERT can drop target Arrow extension metadata

3 participants