mod case;
mod normalize;
mod truth_admission;
use crate::db::query::plan::expr::Expr;
use crate::db::query::plan::expr::canonicalize::{
case::canonicalize_normalized_bool_case_in_bool_context, truth_admission::TruthWrapperScope,
};
pub(in crate::db) use normalize::{is_normalized_bool_expr, simplify_bool_expr_constants};
pub(in crate::db) use truth_admission::{
scalar_where_truth_condition_is_admitted, truth_condition_binary_compare_op,
truth_condition_compare_binary_op,
};
#[derive(Clone, Debug, Eq, PartialEq)]
pub(in crate::db) struct CanonicalExpr {
expr: Expr,
}
impl CanonicalExpr {
const fn new(expr: Expr) -> Self {
Self { expr }
}
pub(in crate::db::query::plan::expr) fn from_normalized_bool_expr(expr: &Expr) -> Option<Self> {
is_normalized_bool_expr(expr).then(|| Self::new(expr.clone()))
}
pub(in crate::db) const fn as_expr(&self) -> &Expr {
&self.expr
}
pub(in crate::db) fn into_expr(self) -> Expr {
self.expr
}
}
#[must_use]
pub(in crate::db) fn normalize_bool_expr_artifact(expr: Expr) -> CanonicalExpr {
let expr = normalize::normalize_bool_expr_impl(expr);
debug_assert!(is_normalized_bool_expr(&expr));
CanonicalExpr::new(expr)
}
#[must_use]
pub(in crate::db) fn normalize_bool_expr(expr: Expr) -> Expr {
normalize_bool_expr_artifact(expr).into_expr()
}
#[must_use]
pub(in crate::db) fn canonicalize_scalar_where_bool_expr_artifact(expr: Expr) -> CanonicalExpr {
let expr = normalize_bool_expr(expr);
debug_assert!(is_normalized_bool_expr(&expr));
let expr = canonicalize_normalized_bool_case_in_bool_context(
expr,
true,
Some(TruthWrapperScope::ScalarWhere),
);
let expr = normalize_bool_expr(expr);
debug_assert!(is_normalized_bool_expr(&expr));
CanonicalExpr::new(expr)
}
#[must_use]
pub(in crate::db) fn canonicalize_scalar_where_bool_expr(expr: Expr) -> Expr {
canonicalize_scalar_where_bool_expr_artifact(expr).into_expr()
}
#[must_use]
pub(in crate::db) fn canonicalize_grouped_having_bool_expr_artifact(expr: Expr) -> CanonicalExpr {
let expr = normalize_bool_expr(expr);
debug_assert!(is_normalized_bool_expr(&expr));
let expr = canonicalize_normalized_bool_case_in_bool_context(
expr,
false,
Some(TruthWrapperScope::GroupedHaving),
);
let expr = normalize_bool_expr(expr);
debug_assert!(is_normalized_bool_expr(&expr));
CanonicalExpr::new(expr)
}
#[must_use]
pub(in crate::db) fn canonicalize_grouped_having_bool_expr(expr: Expr) -> Expr {
canonicalize_grouped_having_bool_expr_artifact(expr).into_expr()
}