Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions arrow-json/src/reader/list_array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,27 +34,27 @@ pub struct ListArrayDecoder<O> {

impl<O: OffsetSizeTrait> ListArrayDecoder<O> {
pub fn new(
data_type: DataType,
data_type: &DataType,
coerce_primitive: bool,
strict_mode: bool,
is_nullable: bool,
struct_mode: StructMode,
) -> Result<Self, ArrowError> {
let field = match &data_type {
let field = match data_type {
DataType::List(f) if !O::IS_LARGE => f,
DataType::LargeList(f) if O::IS_LARGE => f,
_ => unreachable!(),
};
let decoder = make_decoder(
field.data_type().clone(),
field.data_type(),
coerce_primitive,
strict_mode,
field.is_nullable(),
struct_mode,
)?;

Ok(Self {
data_type,
data_type: data_type.clone(),
decoder,
phantom: Default::default(),
is_nullable,
Expand Down
10 changes: 5 additions & 5 deletions arrow-json/src/reader/map_array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,13 @@ pub struct MapArrayDecoder {

impl MapArrayDecoder {
pub fn new(
data_type: DataType,
data_type: &DataType,
coerce_primitive: bool,
strict_mode: bool,
is_nullable: bool,
struct_mode: StructMode,
) -> Result<Self, ArrowError> {
let fields = match &data_type {
let fields = match data_type {
DataType::Map(_, true) => {
return Err(ArrowError::NotYetImplemented(
"Decoding MapArray with sorted fields".to_string(),
Expand All @@ -57,22 +57,22 @@ impl MapArrayDecoder {
};

let keys = make_decoder(
fields[0].data_type().clone(),
fields[0].data_type(),
coerce_primitive,
strict_mode,
fields[0].is_nullable(),
struct_mode,
)?;
let values = make_decoder(
fields[1].data_type().clone(),
fields[1].data_type(),
coerce_primitive,
strict_mode,
fields[1].is_nullable(),
struct_mode,
)?;

Ok(Self {
data_type,
data_type: data_type.clone(),
keys,
values,
is_nullable,
Expand Down
20 changes: 10 additions & 10 deletions arrow-json/src/reader/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ use crate::StructMode;
use crate::reader::binary_array::{
BinaryArrayDecoder, BinaryViewDecoder, FixedSizeBinaryArrayDecoder,
};
use std::borrow::Cow;
use std::io::BufRead;
use std::sync::Arc;

Expand Down Expand Up @@ -295,16 +296,15 @@ impl ReaderBuilder {

/// Create a [`Decoder`]
pub fn build_decoder(self) -> Result<Decoder, ArrowError> {
let (data_type, nullable) = match self.is_field {
false => (DataType::Struct(self.schema.fields.clone()), false),
true => {
let field = &self.schema.fields[0];
(field.data_type().clone(), field.is_nullable())
}
let (data_type, nullable) = if self.is_field {
let field = &self.schema.fields[0];
(Cow::Borrowed(field.data_type()), field.is_nullable())
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NOTE: This Cow::Borrowed is necessary to preserve pointer stability of field.data_type() that would otherwise have to be cloned.

} else {
(Cow::Owned(DataType::Struct(self.schema.fields.clone())), false)
};

let decoder = make_decoder(
data_type,
data_type.as_ref(),
self.coerce_primitive,
self.strict_mode,
nullable,
Expand Down Expand Up @@ -686,14 +686,14 @@ macro_rules! primitive_decoder {
}

fn make_decoder(
data_type: DataType,
data_type: &DataType,
coerce_primitive: bool,
strict_mode: bool,
is_nullable: bool,
struct_mode: StructMode,
) -> Result<Box<dyn ArrayDecoder>, ArrowError> {
downcast_integer! {
data_type => (primitive_decoder, data_type),
*data_type => (primitive_decoder, data_type),
DataType::Null => Ok(Box::<NullArrayDecoder>::default()),
DataType::Float16 => primitive_decoder!(Float16Type, data_type),
DataType::Float32 => primitive_decoder!(Float32Type, data_type),
Expand Down Expand Up @@ -752,7 +752,7 @@ fn make_decoder(
DataType::FixedSizeBinary(len) => Ok(Box::new(FixedSizeBinaryArrayDecoder::new(len))),
DataType::BinaryView => Ok(Box::new(BinaryViewDecoder::default())),
DataType::Map(_, _) => Ok(Box::new(MapArrayDecoder::new(data_type, coerce_primitive, strict_mode, is_nullable, struct_mode)?)),
d => Err(ArrowError::NotYetImplemented(format!("Support for {d} in JSON reader")))
_ => Err(ArrowError::NotYetImplemented(format!("Support for {data_type} in JSON reader")))
}
}

Expand Down
4 changes: 2 additions & 2 deletions arrow-json/src/reader/primitive_array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,9 @@ pub struct PrimitiveArrayDecoder<P: ArrowPrimitiveType> {
}

impl<P: ArrowPrimitiveType> PrimitiveArrayDecoder<P> {
pub fn new(data_type: DataType) -> Self {
pub fn new(data_type: &DataType) -> Self {
Self {
data_type,
data_type: data_type.clone(),
phantom: Default::default(),
}
}
Expand Down
8 changes: 4 additions & 4 deletions arrow-json/src/reader/struct_array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,14 +80,14 @@ pub struct StructArrayDecoder {

impl StructArrayDecoder {
pub fn new(
data_type: DataType,
data_type: &DataType,
coerce_primitive: bool,
strict_mode: bool,
is_nullable: bool,
struct_mode: StructMode,
) -> Result<Self, ArrowError> {
let (decoders, field_name_to_index) = {
let fields = struct_fields(&data_type);
let fields = struct_fields(data_type);
let decoders = fields
.iter()
.map(|f| {
Expand All @@ -96,7 +96,7 @@ impl StructArrayDecoder {
// it doesn't contain any nulls not masked by its parent
let nullable = f.is_nullable() || is_nullable;
make_decoder(
f.data_type().clone(),
f.data_type(),
coerce_primitive,
strict_mode,
nullable,
Expand All @@ -113,7 +113,7 @@ impl StructArrayDecoder {
};

Ok(Self {
data_type,
data_type: data_type.clone(),
decoders,
strict_mode,
is_nullable,
Expand Down
4 changes: 2 additions & 2 deletions arrow-json/src/reader/timestamp_array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ pub struct TimestampArrayDecoder<P: ArrowTimestampType, Tz: TimeZone> {
}

impl<P: ArrowTimestampType, Tz: TimeZone> TimestampArrayDecoder<P, Tz> {
pub fn new(data_type: DataType, timezone: Tz) -> Self {
pub fn new(data_type: &DataType, timezone: Tz) -> Self {
Self {
data_type,
data_type: data_type.clone(),
timezone,
phantom: Default::default(),
}
Expand Down
Loading