From cc39bf3cb4b9f47045cd1c5f7d4dbad3cc71fbb7 Mon Sep 17 00:00:00 2001 From: Edd Robinson Date: Fri, 31 Jul 2020 11:41:57 +0100 Subject: [PATCH] refactor: address PR feedback --- delorean_parquet/src/writer.rs | 12 ++++-------- delorean_table/src/packers.rs | 15 +++++---------- 2 files changed, 9 insertions(+), 18 deletions(-) diff --git a/delorean_parquet/src/writer.rs b/delorean_parquet/src/writer.rs index bf8509ce0f..27d71d3090 100644 --- a/delorean_parquet/src/writer.rs +++ b/delorean_parquet/src/writer.rs @@ -198,9 +198,8 @@ where match col_writer { BoolColumnWriter(ref mut w) => { let p = packer.bool_packer(); - let rep_levels = vec![0; p.num_rows()]; let n = w - .write_batch(&p.some_values(), Some(&p.def_levels()), Some(&rep_levels)) + .write_batch(&p.some_values(), Some(&p.def_levels()), None) .context(ParquetLibraryError { message: String::from("Can't write_batch with bool values"), })?; @@ -209,9 +208,8 @@ where Int32ColumnWriter(_) => unreachable!("ParquetWriter does not support INT32 data"), Int64ColumnWriter(ref mut w) => { let p = packer.i64_packer(); - let rep_levels = vec![0; p.num_rows()]; let n = w - .write_batch(&p.some_values(), Some(&p.def_levels()), Some(&rep_levels)) + .write_batch(&p.some_values(), Some(&p.def_levels()), None) .context(ParquetLibraryError { message: String::from("Can't write_batch with int64 values"), })?; @@ -223,9 +221,8 @@ where } DoubleColumnWriter(ref mut w) => { let p = packer.f64_packer(); - let rep_levels = vec![0; p.num_rows()]; let n = w - .write_batch(&p.some_values(), Some(&p.def_levels()), Some(&rep_levels)) + .write_batch(&p.some_values(), Some(&p.def_levels()), None) .context(ParquetLibraryError { message: String::from("Can't write_batch with f64 values"), })?; @@ -233,9 +230,8 @@ where } ByteArrayColumnWriter(ref mut w) => { let p = packer.str_packer(); - let rep_levels = vec![0; p.num_rows()]; let n = w - .write_batch(&p.some_values(), Some(&p.def_levels()), Some(&rep_levels)) + .write_batch(&p.some_values(), Some(&p.def_levels()), None) .context(ParquetLibraryError { message: String::from("Can't write_batch with byte array values"), })?; diff --git a/delorean_table/src/packers.rs b/delorean_table/src/packers.rs index 58a06134e9..9e5f7aa654 100644 --- a/delorean_table/src/packers.rs +++ b/delorean_table/src/packers.rs @@ -232,9 +232,7 @@ where self.values.len() } - /// Get the value of logical row at `index`. This may be different - /// than the index in self.values.len() when NULLs are present - /// because there are no values in self.values stored for NULL + /// Get the value of logical row at `index`. pub fn get(&self, index: usize) -> Option<&T> { self.values[index].as_ref() } @@ -253,13 +251,10 @@ where /// returns a binary vector indicating which indexes have null values. pub fn def_levels(&self) -> Vec { - let mut levels = vec![1; self.values.len()]; - for (i, v) in self.values.iter().enumerate() { - if v.is_none() { - levels[i] = 0; - } - } - levels + self.values + .iter() + .map(|v| if v.is_some() { 1 } else { 0 }) + .collect::>() } /// returns all of the non-null values in the Packer