Skip to main content

ReaderBuilder

Struct ReaderBuilder 

Source
pub struct ReaderBuilder {
    batch_size: usize,
    coerce_primitive: bool,
    strict_mode: bool,
    ignore_type_conflicts: bool,
    is_field: bool,
    struct_mode: StructMode,
    flatten_top_level_arrays: bool,
    decoder_factory: Option<Arc<dyn DecoderFactory>>,
    schema: SchemaRef,
}
Expand description

A builder for Reader and Decoder

Fields§

§batch_size: usize§coerce_primitive: bool§strict_mode: bool§ignore_type_conflicts: bool§is_field: bool§struct_mode: StructMode§flatten_top_level_arrays: bool§decoder_factory: Option<Arc<dyn DecoderFactory>>§schema: SchemaRef

Implementations§

Source§

impl ReaderBuilder

Source

pub fn new(schema: SchemaRef) -> Self

Create a new ReaderBuilder with the provided [SchemaRef]

This could be obtained using infer_json_schema if not known

Any columns not present in schema will be ignored, unless strict_mode is set to true. In this case, an error is returned when a column is missing from schema.

Source

pub fn new_with_field(field: impl Into<FieldRef>) -> Self

Create a new ReaderBuilder that will parse JSON values of field.data_type()

Unlike ReaderBuilder::new this does not require the root of the JSON data to be an object, i.e. {..}, allowing for parsing of any valid JSON value(s)

// Root of JSON schema is a numeric type
let data = "1\n2\n3\n";
let field = Arc::new(Field::new("int", DataType::Int32, true));
let mut reader = ReaderBuilder::new_with_field(field.clone()).build(data.as_bytes()).unwrap();
let b = reader.next().unwrap().unwrap();
let values = b.column(0).as_primitive::<Int32Type>().values();
assert_eq!(values, &[1, 2, 3]);

// Root of JSON schema is a list type
let data = "[1, 2, 3, 4, 5, 6, 7]\n[1, 2, 3]";
let field = Field::new_list("int", field.clone(), true);
let mut reader = ReaderBuilder::new_with_field(field).build(data.as_bytes()).unwrap();
let b = reader.next().unwrap().unwrap();
let list = b.column(0).as_list::<i32>();

assert_eq!(list.offsets().as_ref(), &[0, 7, 10]);
let list_values = list.values().as_primitive::<Int32Type>();
assert_eq!(list_values.values(), &[1, 2, 3, 4, 5, 6, 7, 1, 2, 3]);
Source

pub fn with_batch_size(self, batch_size: usize) -> Self

Sets the batch size in rows to read

Source

pub fn with_coerce_primitive(self, coerce_primitive: bool) -> Self

Sets if the decoder should coerce primitive values (bool and number) into string when the Schema’s column is Utf8 or LargeUtf8.

Source

pub fn with_strict_mode(self, strict_mode: bool) -> Self

Sets if the decoder should return an error if it encounters a column not present in schema. If struct_mode is ListOnly the value of strict_mode is effectively true. It is required for all fields of the struct to be in the list: without field names, there is no way to determine which field is missing.

Source

pub fn with_struct_mode(self, struct_mode: StructMode) -> Self

Set the StructMode for the reader, which determines whether structs can be decoded from JSON as objects or lists. For more details refer to the enum documentation. Default is to use ObjectOnly.

Source

pub fn with_ignore_type_conflicts(self, ignore_type_conflicts: bool) -> Self

Sets whether the decoder should produce NULL instead of returning an error if it encounters value that can not be parsed into the specified column type.

For example, if the type is declared to be a nullable array of DataType::Int32 but the reader encounters a string value "foo" and the value ignore_type_conflicts is:

  • false (the default): The reader will return an error.

  • true: The reader will fill in NULL value for that array element.

NOTE: An inferred NULL due to a type conflict will still produce parsing errors for non-nullable fields, the same as any other NULL or missing value.

Source

pub fn with_flatten(self, flatten_top_level_arrays: bool) -> Self

Sets whether to flatten top-level arrays.

  • When true, each element of a top-level array will be treated as its own row.
  • When false (the default), the entire top-level array will be treated as one row.

For example, consider this input file:

[{ "a": 1 }, { "a": 2 }, { "b": 3 }]
[{ "a": 4 }, { "a": 5 }, { "b": 6 }]

By default, this would be parsed as two rows, each an array containing three elements. With this option set to true, however, this would be parsed as six rows.

Note that even with this option set to true, top-level objects are still permitted and will be parsed as individual rows in the exact same manner as when this option is set to false. It is even possible to mix top-level arrays with top-level objects.

Source

pub fn with_decoder_factory( self, decoder_factory: Arc<dyn DecoderFactory>, ) -> Self

Set a hook for customizing decoding behavior. See DecoderFactory.

Source

pub fn build<R: BufRead>(self, reader: R) -> Result<Reader<R>, ArrowError>

Create a Reader with the provided BufRead

Source

pub fn build_decoder(self) -> Result<Decoder, ArrowError>

Create a Decoder

Trait Implementations§

Source§

impl Clone for ReaderBuilder

Source§

fn clone(&self) -> ReaderBuilder

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.