Skip to content

[Variant] Remove potential panics when probing VariantArray #8609

Description

@friendlymatthew

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

Consider the following:

 fn foo() {
    let mut b = VariantArrayBuilder::new(1);
    b.append_null();
    let v = b.build();

    v.value(0); // will panic
}

Probing a VariantArray when that element is null will result in a panic:

thread 'cast_to_variant::tests::foo' panicked at /Users/matthewkim/.cargo/git/checkouts/arrow-rs-583cca34693b79b8/760b7b6/parquet-variant/src/variant.rs:318:14:
Invalid variant metadata: InvalidArgumentError("Received empty bytes")

This seems like an odd pattern, as it's not clear exactly what a user should do when iterating or probing through a VariantArray

Describe the solution you'd like
We could have VariantArray::value(i: usize) return an Option<Variant<'a>>. This way, it's clear when it's None, that element is considered null. Note, this is different from Some(Variant::Null))

Additional context

This feature is motivated by datafusion-variant, a higher-level library that integrates with Datafusion through a series of udfs

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementAny new improvement worthy of a entry in the changelogparquet-variantparquet-variant* crates

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions