pub struct Decoder { /* private fields */ }
Expand description
JSON values to Arrow record batch decoder.
A Decoder
decodes arbitrary streams of serde_json::Value
s and
converts them to RecordBatch
es. To decode JSON formatted files,
see Reader
.
Examples
use arrow::json::reader::{Decoder, DecoderOptions, ValueIter, infer_json_schema};
use std::fs::File;
use std::io::{BufReader, Seek, SeekFrom};
use std::sync::Arc;
let mut reader =
BufReader::new(File::open("test/data/mixed_arrays.json").unwrap());
let inferred_schema = infer_json_schema(&mut reader, None).unwrap();
let options = DecoderOptions::new()
.with_batch_size(1024);
let decoder = Decoder::new(Arc::new(inferred_schema), options);
// seek back to start so that the original file is usable again
reader.seek(SeekFrom::Start(0)).unwrap();
let mut value_reader = ValueIter::new(&mut reader, None);
let batch = decoder.next_batch(&mut value_reader).unwrap().unwrap();
assert_eq!(4, batch.num_rows());
assert_eq!(4, batch.num_columns());
Implementations
sourceimpl Decoder
impl Decoder
sourcepub fn new(schema: SchemaRef, options: DecoderOptions) -> Self
pub fn new(schema: SchemaRef, options: DecoderOptions) -> Self
Create a new JSON decoder from some value that implements an
iterator over serde_json::Value
s (aka implements the
Iterator<Item=Result<Value>>
trait).
sourcepub fn schema(&self) -> SchemaRef
pub fn schema(&self) -> SchemaRef
Returns the schema of the reader, useful for getting the schema without reading record batches
sourcepub fn next_batch<I>(&self, value_iter: &mut I) -> Result<Option<RecordBatch>> where
I: Iterator<Item = Result<Value>>,
pub fn next_batch<I>(&self, value_iter: &mut I) -> Result<Option<RecordBatch>> where
I: Iterator<Item = Result<Value>>,
Read the next batch of serde_json::Value
records from the
interator into a RecordBatch
.
Returns None
if the input iterator is exhausted.
Trait Implementations
Auto Trait Implementations
impl RefUnwindSafe for Decoder
impl Send for Decoder
impl Sync for Decoder
impl Unpin for Decoder
impl UnwindSafe for Decoder
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more