#![allow(unreachable_pub)]
#![allow(dead_code)]
use crate::expressions::ColumnName;
#[derive(Debug, Clone, Default)]
pub enum DataLayout {
#[default]
None,
Clustered {
columns: Vec<ColumnName>,
},
Partitioned {
columns: Vec<ColumnName>,
},
}
impl DataLayout {
pub fn clustered<I, S>(columns: I) -> Self
where
I: IntoIterator<Item = S>,
S: AsRef<str>,
{
let columns: Vec<ColumnName> = columns
.into_iter()
.map(|s| ColumnName::new([s.as_ref()]))
.collect();
DataLayout::Clustered { columns }
}
pub fn partitioned<I, S>(columns: I) -> Self
where
I: IntoIterator<Item = S>,
S: AsRef<str>,
{
let columns: Vec<ColumnName> = columns
.into_iter()
.map(|s| ColumnName::new([s.as_ref()]))
.collect();
DataLayout::Partitioned { columns }
}
#[cfg(test)]
pub fn is_clustered(&self) -> bool {
matches!(self, DataLayout::Clustered { .. })
}
#[cfg(test)]
pub fn is_partitioned(&self) -> bool {
matches!(self, DataLayout::Partitioned { .. })
}
}
#[cfg(test)]
mod tests {
use super::*;
#[rstest::rstest]
#[case::clustered(DataLayout::clustered(["id"]), true, false)]
#[case::partitioned(DataLayout::partitioned(["id"]), false, true)]
#[case::none(DataLayout::default(), false, false)]
fn test_data_layout_predicates(
#[case] layout: DataLayout,
#[case] expect_clustered: bool,
#[case] expect_partitioned: bool,
) {
assert_eq!(layout.is_clustered(), expect_clustered);
assert_eq!(layout.is_partitioned(), expect_partitioned);
}
#[test]
fn test_clustered_layout_construction() {
let layout = DataLayout::clustered(["col1", "col2"]);
if let DataLayout::Clustered { columns } = layout {
assert_eq!(columns.len(), 2);
} else {
panic!("Expected Clustered variant");
}
}
#[test]
fn test_partitioned_layout_construction() {
let layout = DataLayout::partitioned(["year", "month"]);
if let DataLayout::Partitioned { columns } = layout {
assert_eq!(columns.len(), 2);
} else {
panic!("Expected Partitioned variant");
}
}
}