[Arrow] Add API to check if Field has a valid ExtensionType#9677
Conversation
|
@alamb @scovich I was looking at #8474 and the doc update in #8475. The current recommendation in #8475 is good: if field.extension_type_name() == Some(MyExtensionType::NAME) {
if let Ok(extension_type) = field.try_extension_type::<MyExtensionType>() {
// ...
}
}Checking the name first avoids the two name-related error paths in For a full validity check, though, we currently still have to go through
Both may return I think a clean follow-up would be a dedicated |
|
I could add |
|
It was easy to do right away here. Now instead of building the For these types (
|
scovich
left a comment
There was a problem hiding this comment.
Generally LGTM, but one design question.
| /// The default implementation delegates to [`Self::try_new`]. Extension | ||
| /// types may override this to validate without constructing `Self`. | ||
| fn validate(data_type: &DataType, metadata: Self::Metadata) -> Result<(), ArrowError> { | ||
| Self::try_new(data_type, metadata).map(|_| ()) |
There was a problem hiding this comment.
I fear we have an API clash here:
supports_data_typereceives&self, in order to allow configurable extension types based on their metadatavalidatereceives metadata but can only use it by instantiating Self (which requires the very allocation we wanted to avoid).
Ideally, supports_data_type should be implemented in terms of validate instead... but I guess that would be a breaking change?
The next best would be to chase down every extension type that actually has metadata, and implement the two methods in the correct direction.
Does any impl in the arrow crate actually use this provided method? Or is it just a safety net for third party impl to avoid a breaking change?
There was a problem hiding this comment.
It's just a safety net now. No extension type is using the default validate impl
There was a problem hiding this comment.
How about as a follow on we remove the default impl (and we merge it for the next major breaking API release)-- that will force any implementations to implement and avoid the potential slowdown
There was a problem hiding this comment.
| /// The default implementation delegates to [`Self::try_new`]. Extension | ||
| /// types may override this to validate without constructing `Self`. | ||
| fn validate(data_type: &DataType, metadata: Self::Metadata) -> Result<(), ArrowError> { | ||
| Self::try_new(data_type, metadata).map(|_| ()) |
…he#9677) # Which issue does this PR close? <!-- We generally require a GitHub issue to be filed for all bug fixes and enhancements and this helps us generate change logs for our releases. You can link an issue to this PR using the GitHub syntax. --> - Closes apache#8474. # Rationale for this change Check issue <!-- Why are you proposing this change? If this is already explained clearly in the issue then this section is not needed. Explaining clearly why changes are proposed helps reviewers understand your changes and offer better suggestions for fixes. --> # What changes are included in this PR? - Added a `has_valid_extension_type` API to `Field` - Added a unit test to save behavior <!-- There is no need to duplicate the description in the issue here but it is sometimes worth providing a summary of the individual changes in this PR. --> # Are these changes tested? - yes, unit test <!-- We typically require tests for all PRs in order to: 1. Prevent the code from being accidentally broken by subsequent changes 2. Serve as another way to document the expected behavior of the code If tests are not included in your PR, please explain why (for example, are they covered by existing tests)? --> # Are there any user-facing changes? <!-- If there are user-facing changes then we may require documentation to be updated before approving the PR. If there are any breaking changes to public APIs, please call them out. -->
Which issue does this PR close?
Fieldhas an extension type #8474.Rationale for this change
Check issue
What changes are included in this PR?
has_valid_extension_typeAPI toFieldAre these changes tested?
Are there any user-facing changes?