Skip to content

[DISCUSS] Remove panics #7806

@hntd187

Description

@hntd187

Is your feature request related to a problem or challenge? Please describe what you are trying to do.

I would like to remove (or at least provide a non-panicking) interface for arrow-rs to have. I spoke with @alamb while at Databricks Data and AI Conference and he mentioned making an issue before I got deep into the weeds implementing something.

Describe the solution you'd like
There are a couple ways to go about this.

  1. Remove the panics. This would be multiple API breaking changes across the board, so this is not nice from a compatibility standpoint. Ideally, I don't think this is the right way to go here.
  2. Add try_* methods instead. For example:
pub fn as_generic_list_array<S: OffsetSizeTrait>(arr: &dyn Array) -> &GenericListArray<S> {
    arr.as_any()
        .downcast_ref::<GenericListArray<S>>()
        .expect("Unable to downcast to list array")
}

Becomes

pub fn try_as_generic_list_array<S: OffsetSizeTrait>(arr: &dyn Array) -> Option<&GenericListArray<S>> {
    arr.as_any().downcast_ref::<GenericListArray<S>>()
}

pub fn as_generic_list_array<S: OffsetSizeTrait>(arr: &dyn Array) -> &GenericListArray<S> {
    try_as_generic_list_array(arr).expect("Unable to downcast to list array")
}

This mechanism is employed in multiple places already, if this approach is preferred this would unify that approach to be consistent across all of the code base.

I'm basically looking for a preference to get started upon. I can introduce new Error types as necessary for result types, but I think #2 for options is a good place to start.

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