alamb commented on PR #7843:
URL: https://github.com/apache/arrow-rs/pull/7843#issuecomment-3032501230

   So I personally prefer the automatic finalize on drop behavior -- I can 
understand how that behavior can cause trouble when external resources are 
affected but in this case I think it makes this code much easier to use for 
most cases.
   
   If we don't finalize the object on drop of the builder, for example, the 
resulting Variant object built by the builder seems to be malformed. Here is an 
example
   
   ```rust
   #[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:
   
   ```rust
           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.
   ```


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to