use crate::{
db::predicate::{coercion::CoercionSpec, model::CompareOp},
value::Value,
};
#[derive(Clone, Debug, Eq, PartialEq)]
pub(in crate::db) enum ExecutableCompareOperand {
FieldSlot(Option<usize>),
Literal(Value),
}
#[derive(Clone, Debug, Eq, PartialEq)]
pub(in crate::db) struct ExecutableComparePredicate {
pub(in crate::db) left: ExecutableCompareOperand,
pub(in crate::db) op: CompareOp,
pub(in crate::db) right: ExecutableCompareOperand,
pub(in crate::db) coercion: CoercionSpec,
}
impl ExecutableComparePredicate {
#[must_use]
pub(in crate::db) const fn field_literal(
field_slot: Option<usize>,
op: CompareOp,
value: Value,
coercion: CoercionSpec,
) -> Self {
Self {
left: ExecutableCompareOperand::FieldSlot(field_slot),
op,
right: ExecutableCompareOperand::Literal(value),
coercion,
}
}
#[must_use]
pub(in crate::db) const fn field_field(
left_field_slot: Option<usize>,
op: CompareOp,
right_field_slot: Option<usize>,
coercion: CoercionSpec,
) -> Self {
Self {
left: ExecutableCompareOperand::FieldSlot(left_field_slot),
op,
right: ExecutableCompareOperand::FieldSlot(right_field_slot),
coercion,
}
}
#[must_use]
pub(in crate::db) const fn left_field_slot(&self) -> Option<usize> {
match self.left {
ExecutableCompareOperand::FieldSlot(slot) => slot,
ExecutableCompareOperand::Literal(_) => None,
}
}
#[must_use]
pub(in crate::db) const fn right_field_slot(&self) -> Option<usize> {
match self.right {
ExecutableCompareOperand::FieldSlot(slot) => slot,
ExecutableCompareOperand::Literal(_) => None,
}
}
#[must_use]
pub(in crate::db) const fn right_literal(&self) -> Option<&Value> {
match &self.right {
ExecutableCompareOperand::Literal(value) => Some(value),
ExecutableCompareOperand::FieldSlot(_) => None,
}
}
}
#[derive(Clone, Debug, Eq, PartialEq)]
pub(in crate::db) enum ExecutablePredicate {
True,
False,
And(Vec<Self>),
Or(Vec<Self>),
Not(Box<Self>),
Compare(ExecutableComparePredicate),
IsNull {
field_slot: Option<usize>,
},
IsNotNull {
field_slot: Option<usize>,
},
IsMissing {
field_slot: Option<usize>,
},
IsEmpty {
field_slot: Option<usize>,
},
IsNotEmpty {
field_slot: Option<usize>,
},
TextContains {
field_slot: Option<usize>,
value: Value,
},
TextContainsCi {
field_slot: Option<usize>,
value: Value,
},
}