Skip to content

Commit

Permalink
Rename FloatIter to FloatDecoder
Browse files Browse the repository at this point in the history
  • Loading branch information
Jefffrey committed Sep 24, 2024
1 parent e3b0be4 commit bb6ccf9
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 11 deletions.
6 changes: 3 additions & 3 deletions src/array_decoder/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ use snafu::{ensure, ResultExt};
use crate::column::{get_present_vec, Column};
use crate::encoding::boolean::BooleanIter;
use crate::encoding::byte::ByteRleReader;
use crate::encoding::float::FloatIter;
use crate::encoding::float::FloatDecoder;
use crate::encoding::{get_rle_reader, PrimitiveValueDecoder};
use crate::error::{
self, ArrowSnafu, MismatchedSchemaSnafu, Result, UnexpectedSnafu, UnsupportedTypeVariantSnafu,
Expand Down Expand Up @@ -404,7 +404,7 @@ pub fn array_decoder_factory(
}
);
let iter = stripe.stream_map().get(column, Kind::Data);
let iter = Box::new(FloatIter::new(iter));
let iter = Box::new(FloatDecoder::new(iter));
let present = get_present_vec(column, stripe)?
.map(|iter| Box::new(iter.into_iter()) as Box<dyn Iterator<Item = bool> + Send>);
Box::new(Float32ArrayDecoder::new(iter, present))
Expand All @@ -418,7 +418,7 @@ pub fn array_decoder_factory(
}
);
let iter = stripe.stream_map().get(column, Kind::Data);
let iter = Box::new(FloatIter::new(iter));
let iter = Box::new(FloatDecoder::new(iter));
let present = get_present_vec(column, stripe)?
.map(|iter| Box::new(iter.into_iter()) as Box<dyn Iterator<Item = bool> + Send>);
Box::new(Float64ArrayDecoder::new(iter, present))
Expand Down
15 changes: 7 additions & 8 deletions src/encoding/float.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,12 @@ impl Float for f64 {
}
}

// TODO: rename to FloatDecoder
pub struct FloatIter<T: Float, R: std::io::Read> {
pub struct FloatDecoder<T: Float, R: std::io::Read> {
reader: R,
phantom: std::marker::PhantomData<T>,
}

impl<T: Float, R: std::io::Read> FloatIter<T, R> {
impl<T: Float, R: std::io::Read> FloatDecoder<T, R> {
pub fn new(reader: R) -> Self {
Self {
reader,
Expand All @@ -73,7 +72,7 @@ impl<T: Float, R: std::io::Read> FloatIter<T, R> {
}
}

impl<T: Float, R: std::io::Read> PrimitiveValueDecoder<T> for FloatIter<T, R> {
impl<T: Float, R: std::io::Read> PrimitiveValueDecoder<T> for FloatDecoder<T, R> {
fn decode(&mut self, out: &mut [T]) -> Result<()> {
let mut buf = vec![0; out.len() * T::BYTE_SIZE];
self.reader.read_exact(&mut buf).context(IoSnafu)?;
Expand All @@ -99,7 +98,7 @@ impl<T: Float, R: std::io::Read> PrimitiveValueDecoder<T> for FloatIter<T, R> {
}

// TODO: remove this, currently only needed as we move from iterator to PrimitiveValueDecoder
impl<T: Float, R: std::io::Read> Iterator for FloatIter<T, R> {
impl<T: Float, R: std::io::Read> Iterator for FloatDecoder<T, R> {
type Item = Result<T>;

fn next(&mut self) -> Option<Self::Item> {
Expand Down Expand Up @@ -172,7 +171,7 @@ mod tests {
let bytes = float_to_bytes(&input);
let bytes = Cursor::new(bytes);

let mut iter = FloatIter::<F, _>::new(bytes);
let mut iter = FloatDecoder::<F, _>::new(bytes);
let mut actual = vec![F::zero(); input.len()];
iter.decode(&mut actual).unwrap();

Expand Down Expand Up @@ -204,7 +203,7 @@ mod tests {
let bytes = float_to_bytes(&[f32::NAN]);
let bytes = Cursor::new(bytes);

let mut iter = FloatIter::<f32, _>::new(bytes);
let mut iter = FloatDecoder::<f32, _>::new(bytes);
let mut actual = vec![0.0; 1];
iter.decode(&mut actual).unwrap();
assert!(actual[0].is_nan());
Expand All @@ -215,7 +214,7 @@ mod tests {
let bytes = float_to_bytes(&[f64::NAN]);
let bytes = Cursor::new(bytes);

let mut iter = FloatIter::<f64, _>::new(bytes);
let mut iter = FloatDecoder::<f64, _>::new(bytes);
let mut actual = vec![0.0; 1];
iter.decode(&mut actual).unwrap();
assert!(actual[0].is_nan());
Expand Down

0 comments on commit bb6ccf9

Please sign in to comment.