Skip to content

[Arrow] Consider faster way to check if a Field has an extension type #8474

@alamb

Description

@alamb

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:

There is no good API to quickly tell if a Field has an extension type. The current way is like

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 #8408 I came up with this to avoid the problem, but it is not obvious and somewhat redundant:

    // 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 this PR are enough

Describe alternatives you've considered

Additional context

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementAny new improvement worthy of a entry in the changelog

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions