Repository navigation
refactor: separate extension validation - #12271
Conversation
|
@sdf-jkl This PR is ready for review now. And CC @Rich-T-kid in case you're interested |
sdf-jkl
left a comment
There was a problem hiding this comment.
Thanks @Phoenix500526 everything looks good with a suggestion below
71100ec to
059ff1f
Compare
sdf-jkl
left a comment
There was a problem hiding this comment.
Thanks @Phoenix500526, one more thing
| ) -> Result<&'a DataType, ArrowError> { | ||
| match data_type { | ||
| DataType::FixedSizeList(field, list_size) if !field.is_nullable() => { | ||
| metadata.validate()?; |
There was a problem hiding this comment.
Could we also add some tests that would pin the metadata check down for both tensor types?
There was a problem hiding this comment.
Good call. Added
There was a problem hiding this comment.
I think one case per test could've been enough. We're only pinning the metadata check itself.
The ext type specific checks are already tested in their impls:
- https://github.com/apache/arrow-rs/blob/b325878f30/arrow-schema/src/extension/canonical/fixed_shape_tensor.rs#L605-L617
- https://github.com/apache/arrow-rs/blob/b325878f30/arrow-schema/src/extension/canonical/variable_shape_tensor.rs#L621-L634
There was a problem hiding this comment.
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
059ff1f to
5e2cf4b
Compare
sdf-jkl
left a comment
There was a problem hiding this comment.
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()?; |
There was a problem hiding this comment.
I think one case per test could've been enough. We're only pinning the metadata check itself.
The ext type specific checks are already tested in their impls:
- https://github.com/apache/arrow-rs/blob/b325878f30/arrow-schema/src/extension/canonical/fixed_shape_tensor.rs#L605-L617
- https://github.com/apache/arrow-rs/blob/b325878f30/arrow-schema/src/extension/canonical/variable_shape_tensor.rs#L621-L634
One invalid metadata case per tensor guards the validation call. Existing tests already cover the individual metadata constraints. Refs apache#9708
Which issue does this PR close?
ExtensionType::validatewithinExtensionType::try_new#9708Rationale 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?
try_newandvalidateforFixedShapeTensor,VariableShapeTensor,Json, andWkbType.supports_data_type.The helpers allow constructors and validators to share checks while retaining the existing by-value
validatesignature. 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_typeassertions 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::validateimplementation remains available for downstream implementations.AI usage disclosure
Codex helped implement and review the refactor and test assertions, and run local validation.