Skip to content

[Variant] Implement VariantObject::field and VariantObject::fields #7665

@alamb

Description

@alamb

Is your feature request related to a problem or challenge? Please describe what you are trying to do.
I was trying to write some tests for the VariantBuilder from @PinkCrow007 in

However, I found that VariantObject::field was not implemented: https://github.com/apache/arrow-rs/blob/71ee9d9aa090a4d733c8404c6edb8d34d767a0c4/parquet-variant/src/variant.rs#L317-L316

So when I wrote code to access a field from an object

assert_eq!(variant_object.field("first_name"), Variant::from("Jiaying")

It panic'd on me

Describe the solution you'd like
Implement the two methods named in this ticket. The code is here:

pub fn fields(&self) -> Result<impl Iterator<Item = (&'m str, Variant<'m, 'v>)>, ArrowError> {
todo!();
#[allow(unreachable_code)] // Just to infer the return type
Ok(vec![].into_iter())
}
pub fn field(&self, _name: &'m str) -> Result<Variant<'m, 'v>, ArrowError> {
todo!()

Describe alternatives you've considered

  1. Implement the code
  2. Update the existing tests here:
    "object_primitive" => {
    assert!(matches!(variant, Variant::Object(_)));
    assert_eq!(metadata.dictionary_size(), 7);
    let dict_val = metadata.get_field_by(0)?;
    assert_eq!(dict_val, "int_field");

To retrieve each field and verify its value

The expected answers are here:

https://github.com/apache/parquet-testing/blob/84d525a8731cec345852fb4ea2e7c581fbf2ef29/variant/data_dictionary.json#L46-L54

Additional context

Metadata

Metadata

Labels

enhancementAny new improvement worthy of a entry in the changeloggood first issueGood for newcomersparquetChanges to the parquet crate

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions