You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by "alamb (via GitHub)" <gi...@apache.org> on 2025/09/26 16:01:22 UTC

[I] [Arrow] Consider faster way to check if a `Field` has an extension type [arrow-rs]

alamb opened a new issue, #8474:
URL: https://github.com/apache/arrow-rs/issues/8474

   **Is your feature request related to a problem or challenge? Please describe what you are trying to do.**
   
   As @mbrobbel  pointed out in https://github.com/apache/arrow-rs/pull/8408/files#r2378240955:
   
   There are currently two APIs for seeing if a Field has an extension type:
   
   * [`Field::extension_type`](https://docs.rs/arrow/latest/arrow/datatypes/struct.Field.html#method.extension_type) that panics if the field does not have the extension type
   * [`Field::try_extension_type`](https://docs.rs/arrow/latest/arrow/datatypes/struct.Field.html#method.try_extension_type) that returns an `ArrowError` if the field does not have the extension type
   
   There is no good API to quickly tell if a Field has an extension type. The current way is like
   ```rust
   if field.try_extension_type<TheExtensionType>().is_ok() {
    // field has extension type
   }
   ```
   
   Works, but it requires creating an `ArrowError` if the field is not the requested type, which is slow as it allocates a String
   
   in https://github.com/apache/arrow-rs/pull/8408 I came up with this to avoid the problem, but it is not obvious and somewhat redundant:
   
   ```rust
       // Check the name (= quick and cheap) and only try_extension_type if the name matches
       // to avoid unnecessary String allocations in ArrowError
       if field.extension_type_name()? != VariantType::NAME {
           return None;
       }
       match field.try_extension_type::<VariantType>() {
           Ok(VariantType) => Some(LogicalType::Variant),
           // Given check above, this should not error, but if it does ignore
           Err(_e) => None,
       }
   ```
   
   **Describe the solution you'd like**
   A clearer way to test for extension types.
   
   Maybe the documentation I added in https://github.com/apache/arrow-rs/pull/8408 is sufficient
   
   **Describe alternatives you've considered**
   <!--
   A clear and concise description of any alternative solutions or features you've considered.
   -->
   
   **Additional context**
   <!--
   Add any other context or screenshots about the feature request here.
   -->
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [I] [Arrow] Consider faster way to check if a `Field` has an extension type [arrow-rs]

Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb closed issue #8474: [Arrow] Consider faster way to check if a `Field` has an extension type
URL: https://github.com/apache/arrow-rs/issues/8474


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org