From 3c24b6e10ee2af4a001d1e66a35cc40a42355b1a Mon Sep 17 00:00:00 2001 From: Edd Robinson Date: Thu, 18 Jun 2020 19:48:09 +0100 Subject: [PATCH] refactor: small API change --- delorean_tsm/src/mapper.rs | 50 ++++++++------------------------------ 1 file changed, 10 insertions(+), 40 deletions(-) diff --git a/delorean_tsm/src/mapper.rs b/delorean_tsm/src/mapper.rs index 54c4a053ca..6f2d2c5870 100644 --- a/delorean_tsm/src/mapper.rs +++ b/delorean_tsm/src/mapper.rs @@ -101,7 +101,7 @@ impl Iterator for TSMMeasurementMapper { // FieldKeyBlocks is a mapping between a set of field keys and all of the blocks // for those keys. -type FieldKeyBlocks = BTreeMap>; +pub type FieldKeyBlocks = BTreeMap>; #[derive(Clone, Debug)] pub struct MeasurementTable { @@ -138,8 +138,14 @@ impl MeasurementTable { } } + pub fn tag_set_fields_blocks( + &mut self, + ) -> &mut BTreeMap, FieldKeyBlocks> { + &mut self.tag_set_fields_blocks + } + pub fn tag_columns(&self) -> Vec<&String> { - Vec::from_iter(self.tag_columns.iter()) + self.tag_columns.iter().collect() } pub fn field_columns(&self) -> &BTreeMap { @@ -170,42 +176,6 @@ impl MeasurementTable { } } -// impl Iterator for MeasurementTable { -// type Item = Result; - -// fn next(&mut self) -> Option { -// let next = self.tag_set_fields_blocks.iter_mut().next(); -// match next { -// Some((key, field_blocks)) => { -// // FIXME - remove this cloning. -// let tag_keys: Vec = self.tag_columns.iter().cloned().collect(); -// let field_keys: Vec = self.field_columns.iter().cloned().collect(); - -// // FIXME: get matching right. -// let res = map_field_columns(self.block_decoder, field_blocks); -// match res { -// Ok((time_column, field_data_columns)) => { -// let table = TableData::new( -// tag_keys, -// field_keys, -// time_column, -// key.clone(), -// field_data_columns, -// ); -// // TODO(edd): this is awful. Need something like the -// // experimental pop_first function. -// self.tag_set_fields_blocks.remove(key); - -// Some(Ok(table)) -// } -// Err(e) => return Some(Err(e)), -// } -// } -// None => None, -// } -// } -// } - impl Display for MeasurementTable { // This trait requires `fmt` with this exact signature. fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { @@ -348,7 +318,7 @@ impl ValuePair { // A BlockDecoder is capable of decoding a block definition into block data // (timestamps and value vectors). -trait BlockDecoder { +pub trait BlockDecoder { fn block_data(&mut self, block: &Block) -> Result; } @@ -408,7 +378,7 @@ where // for a field we can decode and pull the next block for the field and continue // to build the output. // -fn map_field_columns( +pub fn map_field_columns( mut decoder: impl BlockDecoder, field_blocks: &mut FieldKeyBlocks, ) -> Result<(Vec, BTreeMap), TSMError> {