diff --git a/arrow-json/src/writer/encoder.rs b/arrow-json/src/writer/encoder.rs index f5c09b9da74..1e7b14ef3ae 100644 --- a/arrow-json/src/writer/encoder.rs +++ b/arrow-json/src/writer/encoder.rs @@ -166,7 +166,7 @@ fn make_encoder_impl<'a>( let encoder = StructArrayEncoder{ encoders, - nulls: array.nulls().clone(), + nulls: array.nulls(), explicit_nulls: options.explicit_nulls, }; Box::new(encoder) as _ @@ -332,7 +332,10 @@ struct PrimitiveEncoder { } impl PrimitiveEncoder { - fn new>(array: &PrimitiveArray

, nulls: Option) -> Self { + fn new>( + array: &PrimitiveArray

, + nulls: Option, + ) -> Self { Self { values: array.values().clone(), nulls, @@ -418,7 +421,7 @@ impl<'a, O: OffsetSizeTrait> ListEncoder<'a, O> { options: &EncoderOptions, ) -> Result { let nulls = array.logical_nulls(); - let encoder= make_encoder_impl(array.values().as_ref(), options)?; + let encoder = make_encoder_impl(array.values().as_ref(), options)?; Ok(Self { offsets: array.offsets().clone(), encoder, @@ -537,20 +540,15 @@ impl Encoder for DictionaryEncoder<'_, K> { } } - - /// A newtype wrapper around [`ArrayFormatter`] to keep our usage of it private and not implement `Encoder` for the public type struct JsonArrayFormatter<'a> { formatter: ArrayFormatter<'a>, nulls: Option<&'a NullBuffer>, } -impl <'a> JsonArrayFormatter<'a> { +impl<'a> JsonArrayFormatter<'a> { fn new(formatter: ArrayFormatter<'a>, nulls: Option<&'a NullBuffer>) -> Self { - Self { - formatter, - nulls, - } + Self { formatter, nulls } } } diff --git a/arrow-json/src/writer/mod.rs b/arrow-json/src/writer/mod.rs index 48e6492ec51..fd86b9ca665 100644 --- a/arrow-json/src/writer/mod.rs +++ b/arrow-json/src/writer/mod.rs @@ -1986,7 +1986,9 @@ mod tests { match &self.array[idx] { None => out.extend_from_slice(b"null"), Some(UnionValue::Int32(v)) => out.extend_from_slice(v.to_string().as_bytes()), - Some(UnionValue::String(v)) => out.extend_from_slice(format!("\"{}\"", v).as_bytes()), + Some(UnionValue::String(v)) => { + out.extend_from_slice(format!("\"{}\"", v).as_bytes()) + } } } @@ -2023,35 +2025,28 @@ mod tests { _ => return Ok(None), } } - let (_, type_ids, _, buffers) = array - .as_union() - .clone() - .into_parts(); + let (_, type_ids, _, buffers) = array.as_union().clone().into_parts(); let mut values = Vec::with_capacity(type_ids.len()); for idx in 0..type_ids.len() { let type_id = type_ids[idx]; let field = &fields[type_id as usize]; let value = match field.data_type() { DataType::Null => None, - DataType::Int32 => Some( - UnionValue::Int32( - buffers[type_id as usize] - .as_any() - .downcast_ref::() - .unwrap() - .value(idx), - ) - ), - DataType::Utf8 => Some( - UnionValue::String( - buffers[type_id as usize] - .as_any() - .downcast_ref::() - .unwrap() - .value(idx) - .to_string(), - ) - ), + DataType::Int32 => Some(UnionValue::Int32( + buffers[type_id as usize] + .as_any() + .downcast_ref::() + .unwrap() + .value(idx), + )), + DataType::Utf8 => Some(UnionValue::String( + buffers[type_id as usize] + .as_any() + .downcast_ref::() + .unwrap() + .value(idx) + .to_string(), + )), _ => unreachable!(), }; values.push(value); @@ -2238,8 +2233,7 @@ mod tests { &self, array: &'a dyn Array, _options: &EncoderOptions, - ) -> Result>, ArrowError> - { + ) -> Result>, ArrowError> { match array.data_type() { DataType::Binary => { let array = array.as_any().downcast_ref::().unwrap();