refactor: baseline Rc

pull/24376/head
Edd Robinson 2021-01-26 20:41:14 +00:00
parent f3bd8bd0e3
commit 9d3c623a14
1 changed files with 18 additions and 15 deletions

View File

@ -1,6 +1,10 @@
use std::collections::{BTreeMap, BTreeSet};
use std::fmt::Display; use std::fmt::Display;
use std::slice::Iter; use std::slice::Iter;
use std::{
collections::{BTreeMap, BTreeSet},
rc::Rc,
sync::RwLock,
};
use data_types::selection::Selection; use data_types::selection::Selection;
@ -30,7 +34,7 @@ pub struct Table {
// Metadata about the table's segments // Metadata about the table's segments
meta: MetaData, meta: MetaData,
row_groups: Vec<RowGroup>, row_groups: RwLock<Vec<Rc<RowGroup>>>,
} }
impl Table { impl Table {
@ -39,14 +43,14 @@ impl Table {
Self { Self {
name: name.into(), name: name.into(),
meta: MetaData::new(rg.metadata()), meta: MetaData::new(rg.metadata()),
row_groups: vec![rg], row_groups: RwLock::new(vec![Rc::new(rg)]),
} }
} }
/// Add a new row group to this table. /// Add a new row group to this table.
pub fn add_row_group(&mut self, rg: RowGroup) { pub fn add_row_group(&mut self, rg: RowGroup) {
self.meta.update(rg.metadata()); self.meta.update(rg.metadata());
self.row_groups.push(rg); self.row_groups.write().unwrap().push(Rc::new(rg));
} }
/// Remove the row group at `position` from table. /// Remove the row group at `position` from table.
@ -54,11 +58,6 @@ impl Table {
todo!(); todo!();
} }
/// Iterate over all row groups for the table.
pub fn iter(&mut self) -> Iter<'_, RowGroup> {
self.row_groups.iter()
}
/// The name of the table (equivalent to measurement or table name). /// The name of the table (equivalent to measurement or table name).
pub fn name(&self) -> &str { pub fn name(&self) -> &str {
&self.name &self.name
@ -66,12 +65,12 @@ impl Table {
/// Determines if this table contains no row groups. /// Determines if this table contains no row groups.
pub fn is_empty(&self) -> bool { pub fn is_empty(&self) -> bool {
self.row_groups.is_empty() self.row_groups.read().unwrap().is_empty()
} }
/// The total number of row groups within this table. /// The total number of row groups within this table.
pub fn len(&self) -> usize { pub fn len(&self) -> usize {
self.row_groups.len() self.row_groups.read().unwrap().len()
} }
/// The total size of the table in bytes. /// The total size of the table in bytes.
@ -90,10 +89,10 @@ impl Table {
} }
// Identify set of row groups that might satisfy the predicate. // Identify set of row groups that might satisfy the predicate.
fn filter_row_groups(&self, predicate: &Predicate) -> Vec<&RowGroup> { fn filter_row_groups(&self, predicate: &Predicate) -> Vec<&Rc<RowGroup>> {
let mut rgs = Vec::with_capacity(self.row_groups.len()); let mut rgs = Vec::with_capacity(self.len());
'rowgroup: for rg in &self.row_groups { 'rowgroup: for rg in self.row_groups.read().unwrap().iter() {
// check all expressions in predicate // check all expressions in predicate
if !rg.could_satisfy_conjunctive_binary_expressions(predicate.iter()) { if !rg.could_satisfy_conjunctive_binary_expressions(predicate.iter()) {
continue 'rowgroup; continue 'rowgroup;
@ -172,7 +171,7 @@ impl Table {
ReadAggregateResults { ReadAggregateResults {
schema, schema,
predicate, predicate,
row_groups, // TODO
..Default::default() ..Default::default()
} }
} }
@ -418,6 +417,8 @@ impl Table {
// true. If none of the row groups could match then return false. // true. If none of the row groups could match then return false.
let exprs = predicate.expressions(); let exprs = predicate.expressions();
self.row_groups self.row_groups
.read()
.unwrap()
.iter() .iter()
.any(|row_group| row_group.could_satisfy_conjunctive_binary_expressions(exprs)) .any(|row_group| row_group.could_satisfy_conjunctive_binary_expressions(exprs))
} }
@ -437,6 +438,8 @@ impl Table {
// apply the predicate to all row groups. Each row group will do its own // apply the predicate to all row groups. Each row group will do its own
// column pruning based on its column ranges. // column pruning based on its column ranges.
self.row_groups self.row_groups
.read()
.unwrap()
.iter() .iter()
.any(|row_group| row_group.satisfies_predicate(predicate)) .any(|row_group| row_group.satisfies_predicate(predicate))
} }