Skip to content

[Variant] If ObjectBuilder::finalize is not called, the resulting Variant object is malformed. #7863

@alamb

Description

@alamb

Describe the bug

If ObjectBuilder::finalize is not called, the resulting Variant object is malformed.

To Reproduce

Here is an example that would work with finalize on drop, but not with this PR as is

#[test]
    fn test_object_list_no_finish() {
        let mut builder = VariantBuilder::new();

        let mut list_builder = builder.new_list();

        {
            let mut object_builder = list_builder.new_object();
            object_builder.insert("id", 1);
            object_builder.finish().unwrap();
        }

        {
            let mut object_builder = list_builder.new_object();
            object_builder.insert("id", 2);
            // NOTE object_builder.finish() is not called here
        }

        list_builder.finish();

        let (metadata, value) = builder.finish();

        let variant = Variant::try_new(&metadata, &value).unwrap();
        let list = variant.as_list().unwrap();
}

If object_builder.finish() is not called, then this line fails:

        let list = variant.as_list().unwrap();

The error is like this (which is pretty unintuitive to me):

called `Result::unwrap()` on an `Err` value: InvalidArgumentError("Received empty bytes")
thread 'builder::tests::test_object_list_no_finish' panicked at parquet-variant/src/builder.rs:1154:59:
called `Result::unwrap()` on an `Err` value: InvalidArgumentError("Received empty bytes")
stack backtrace:
   0: __rustc::rust_begin_unwind
             at /rustc/6b00bc3880198600130e1cf62b8f8a93494488cc/library/std/src/panicking.rs:697:5
   1: core::panicking::panic_fmt
             at /rustc/6b00bc3880198600130e1cf62b8f8a93494488cc/library/core/src/panicking.rs:75:14
   2: core::result::unwrap_failed
             at /rustc/6b00bc3880198600130e1cf62b8f8a93494488cc/library/core/src/result.rs:1732:5
   3: core::result::Result<T,E>::unwrap
             at /Users/andrewlamb/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/src/rust/library/core/src/result.rs:1137:23
   4: parquet_variant::builder::tests::test_object_list_no_finish
             at ./src/builder.rs:1154:23
   5: parquet_variant::builder::tests::test_object_list_no_finish::{{closure}}
             at ./src/builder.rs:1133:36
   6: core::ops::function::FnOnce::call_once
             at /Users/andrewlamb/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/src/rust/library/core/src/ops/function.rs:250:5
   7: core::ops::function::FnOnce::call_once
             at /rustc/6b00bc3880198600130e1cf62b8f8a93494488cc/library/core/src/ops/function.rs:250:5
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.


**Expected behavior**
<!--
A clear and concise description of what you expected to happen.
-->

**Additional context**
<!--
Add any other context about the problem here.
-->

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugparquetChanges to the parquet crate

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions