Skip to content

[Variant] Make it harder to forget to finish a pending parent i n ObjectBuilder #7798

@alamb

Description

@alamb

Right now all code paths in ObjectBuilder and ListBuilder need to remember to call check_pending and we already have a bug related to this in #7786

It would be nice if we could get the Rust compiler to ensure this was done rather than relying on remembering to do it.

One idea is with an RAII like struct

I wonder if there is some sort of RAAI mechanism we can use to ensure that the pending field is completed automatically when the child ListBuilder or ObjectBuilder is dropped

That way the compiler can ensure this type of bug is not possible

Something like

/// If this is a builder for a nested object or list, on `Drop` this object will finish the
/// in progress field for the parent
enum PendingParent {
...
}

impl Drop for PendingParent {
 List(...),
Object {
  field_name: &str,
  offset: usize
 }
}

Then we could create a field on the builder like this

struct ObjectBuilder {
...
  pending: Option<PendingParent>,
}

I think the biggest challenge would be sorting out the type lifetimes

Originally posted by @alamb in #7786 (comment)

Metadata

Metadata

Assignees

No one assigned

    Labels

    parquetChanges to the parquet crate

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions