use crate::catalog::CatalogType;
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum Filter {
And(Vec<Filter>),
Or(Vec<Filter>),
Leaf(Comparison),
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum Comparison {
Compare {
column: String,
op: CompareOp,
value: String,
},
Set {
column: String,
op: SetOp,
values: Vec<String>,
},
NullCheck { column: String, is_null: bool },
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum CompareOp {
Eq,
NotEq,
Gt,
Gte,
Lt,
Lte,
Like,
StartsWith,
EndsWith,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum SetOp {
In,
NotIn,
}
impl CompareOp {
pub fn supported_by(&self, data_type: &CatalogType) -> bool {
match self {
Self::Eq | Self::NotEq => data_type.supports_equality(),
Self::Gt | Self::Gte | Self::Lt | Self::Lte => data_type.supports_ordering(),
Self::Like | Self::StartsWith | Self::EndsWith => data_type.supports_text_pattern(),
}
}
pub fn name(&self) -> &'static str {
match self {
Self::Eq => "==",
Self::NotEq => "!=",
Self::Gt => "=gt=",
Self::Gte => "=ge=",
Self::Lt => "=lt=",
Self::Lte => "=le=",
Self::Like => "=like=",
Self::StartsWith => "=starts=",
Self::EndsWith => "=ends=",
}
}
}
impl SetOp {
pub fn supported_by(&self, data_type: &CatalogType) -> bool {
data_type.supports_set()
}
pub fn name(&self) -> &'static str {
match self {
Self::In => "=in=",
Self::NotIn => "=out=",
}
}
}