use super::{CatalogTable, RelationKind, SchemaCatalog};
use std::collections::BTreeSet;
impl SchemaCatalog {
pub fn logical_tables(&self) -> impl Iterator<Item = &CatalogTable> {
self.tables().filter(|table| is_logical(table))
}
pub fn logical_partition_tables<'a>(
&'a self,
relation: &str,
) -> impl Iterator<Item = &'a CatalogTable> + 'a {
let mut seen = BTreeSet::new();
std::iter::successors(self.relation(relation), move |table| {
self.relation(table.partition_of.as_deref()?)
})
.map_while(move |table| seen.insert(table.name.as_str()).then_some(table))
.filter(|table| is_logical(table))
}
}
fn is_logical(table: &CatalogTable) -> bool {
table.partition_of.is_none() || table.relation_kind == RelationKind::PartitionedTable
}