alamb opened a new issue, #7863:
URL: https://github.com/apache/arrow-rs/issues/7863
**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
```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.
```
```
**Expected behavior**
<!--
A clear and concise description of what you expected to happen.
-->
**Additional context**
<!--
Add any other context about the problem here.
-->
--
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]