Skip to content

refactor: separate extension validation - #12271

Merged
sdf-jkl merged 4 commits into
apache:mainfrom
Phoenix500526:issue/9708
Nov 28, 2026
Merged

sdf-jkl merged 4 commits into
apache:mainfrom
Phoenix500526:issue/9708

Conversation

@Phoenix500526

Copy link
Copy Markdown
Contributor

Which issue does this PR close?

Rationale for this change

Checking whether a field has a valid fixed-shape tensor, variable-shape tensor, or WKB extension currently constructs an extension descriptor and discards it. JSON validation also creates a default descriptor solely to check the storage type.

What changes are included in this PR?

  • Share private validation helpers between try_new and validate for FixedShapeTensor, VariableShapeTensor, Json, and WkbType.
  • Extract the tensor metadata checks into private methods that borrow metadata. The constructors retain ownership of the original metadata without cloning it for validation.
  • Reuse the JSON and WKB helpers from supports_data_type.

The helpers allow constructors and validators to share checks while retaining the existing by-value validate signature. Removing the trait's default implementation is left for a separate API change.

Are these changes tested?

Existing tests cover construction, invalid metadata and storage types, and metadata round-trips. Added has_valid_extension_type assertions to the existing successful field tests, including all three JSON storage types and both metadata representations. No new test functions were added.

Are there any significant user-facing changes?

No public API signatures or accepted-input rules change. The default ExtensionType::validate implementation remains available for downstream implementations.

AI usage disclosure

Codex helped implement and review the refactor and test assertions, and run local validation.

@boring-cyborg boring-cyborg Bot added arrow-core Core crates related to representing arrow data parquet parquet crate labels Nov 16, 2026
@Phoenix500526
Phoenix500526 marked this pull request as ready for review November 16, 2026 06:50
@Phoenix500526

Copy link
Copy Markdown
Contributor Author

@sdf-jkl This PR is ready for review now. And CC @Rich-T-kid in case you're interested

@Rich-T-kid Rich-T-kid added the development-process Internal changes; PRs with this label are excluded from changelog label Nov 16, 2026

@sdf-jkl sdf-jkl left a comment

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.

Thanks @Phoenix500526 everything looks good with a suggestion below

@Phoenix500526
Phoenix500526 force-pushed the issue/9708 branch 2 times, most recently from 71100ec to 059ff1f Compare November 27, 2026 09:52

@sdf-jkl sdf-jkl left a comment

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.

Thanks @Phoenix500526, one more thing

) -> Result<&'a DataType, ArrowError> {
match data_type {
DataType::FixedSizeList(field, list_size) if !field.is_nullable() => {
metadata.validate()?;

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.

Could we also add some tests that would pin the metadata check down for both tensor types?

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.

Good call. Added

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.

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.

It makes sense. Updated.

Some extension checks construct descriptors only to discard them.
Keep validation independent of construction without changing the
ExtensionType contract.

Refs apache#9708
JSON and WKB checks can share supports_data_type directly.
Document why tensor validation needs a separate borrowed helper.

Refs apache#9708
Guard both extension entry points against invalid metadata that
successfully deserializes, bypassing constructor checks.

Refs apache#9708

@sdf-jkl sdf-jkl left a comment

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.

Thanks @Phoenix500526, a nit.

Otherwise good to go

) -> Result<&'a DataType, ArrowError> {
match data_type {
DataType::FixedSizeList(field, list_size) if !field.is_nullable() => {
metadata.validate()?;

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.

One invalid metadata case per tensor guards the validation call.
Existing tests already cover the individual metadata constraints.

Refs apache#9708
@sdf-jkl
sdf-jkl added this pull request to the merge queue Nov 28, 2026
Merged via the queue into apache:main with commit c7a17b7 Nov 28, 2026
21 of 22 checks passed
@Phoenix500526
Phoenix500526 deleted the issue/9708 branch November 28, 2026 05:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

arrow-core Core crates related to representing arrow data development-process Internal changes; PRs with this label are excluded from changelog parquet parquet crate

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants