debugmiller opened a new pull request, #9021:
URL: https://github.com/apache/arrow-rs/pull/9021
# Which issue does this PR close?
Closes #8987
# What changes are included in this PR?
This incorporates feedback from the discussion on #8998 and includes #7442
with some small adjustments.
With this change you can now register a custom decoder on arrow-json reader.
As a motivating example, this PR also provides the
`VariantArrayDecoderFactory` which allows for Variant annotated Fields to be
deserialized into Variant columns.
For example
```rust
let variant_array = VariantArrayBuilder::new(0).build();
let struct_field = Schema::new(vec![
Field::new("id", DataType::Int32, false),
// call VariantArray::field to get the correct Field
variant_array.field("var"),
]);
let builder = ReaderBuilder::new(Arc::new(struct_field.clone()));
let result = builder
.with_struct_mode(StructMode::ObjectOnly)
.with_decoder_factory(Arc::new(VariantArrayDecoderFactory))
.build(Cursor::new(b"{\"id\": 1, \"var\": [\"mixed data\", 1]}"));
```
This includes #7442 with only two minor changes:
- removed the default implementation of `make_default_decoder` in the
`DecoderFactory` trait, which seemed redundant
- adds `field` as a parameter to `make_decoder` which is necessary to
extract the extension information, although it is somewhat redundant.
@scovich I incorporated your review feedback from #8998, except where noted
inline in the code.
# Are these changes tested?
Unit test was added. Open to feedback on whether that test is adequate or
more is expected.
# Are there any user-facing changes?
Yes, users can now register custom decoders with arrow-json Reader, and use
`VariantArrayDecoderFactory` to deserialize json into Variant columns.
--
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]