mod case;
mod normalize;
mod ordering;
mod truth_admission;
use crate::db::query::plan::expr::canonicalize::{
case::canonicalize_normalized_bool_case_in_bool_context, truth_admission::TruthWrapperScope,
};
use crate::db::{
QueryError,
query::{plan::expr::Expr, preparation::PreparationWork},
};
pub(in crate::db) use normalize::is_normalized_bool_expr;
#[cfg(feature = "sql")]
pub(in crate::db) use normalize::simplify_bool_expr_constants;
#[cfg(feature = "sql")]
pub(in crate::db) use truth_admission::scalar_where_truth_condition_is_admitted;
pub(in crate::db) use truth_admission::truth_condition_binary_compare_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) fn into_expr(self) -> Expr {
self.expr
}
}
pub(in crate::db) fn normalize_bool_expr_artifact(
expr: Expr,
work: &PreparationWork<'_>,
) -> Result<CanonicalExpr, QueryError> {
let expr = normalize::normalize_bool_expr_impl(expr, work)?;
debug_assert!(is_normalized_bool_expr(&expr));
Ok(CanonicalExpr::new(expr))
}
pub(in crate::db) fn normalize_bool_expr(
expr: Expr,
work: &PreparationWork<'_>,
) -> Result<Expr, QueryError> {
normalize_bool_expr_artifact(expr, work).map(CanonicalExpr::into_expr)
}
pub(in crate::db) fn canonicalize_scalar_where_bool_expr_artifact(
expr: Expr,
work: &PreparationWork<'_>,
) -> Result<CanonicalExpr, QueryError> {
let expr = normalize_bool_expr(expr, work)?;
debug_assert!(is_normalized_bool_expr(&expr));
let expr = canonicalize_normalized_bool_case_in_bool_context(
expr,
true,
Some(TruthWrapperScope::ScalarWhere),
work,
)?;
let expr = normalize_bool_expr(expr, work)?;
debug_assert!(is_normalized_bool_expr(&expr));
Ok(CanonicalExpr::new(expr))
}
pub(in crate::db) fn canonicalize_scalar_where_bool_expr(
expr: Expr,
work: &PreparationWork<'_>,
) -> Result<Expr, QueryError> {
canonicalize_scalar_where_bool_expr_artifact(expr, work).map(CanonicalExpr::into_expr)
}
pub(in crate::db) fn canonicalize_grouped_having_bool_expr_artifact(
expr: Expr,
work: &PreparationWork<'_>,
) -> Result<CanonicalExpr, QueryError> {
let expr = normalize_bool_expr(expr, work)?;
debug_assert!(is_normalized_bool_expr(&expr));
let expr = canonicalize_normalized_bool_case_in_bool_context(
expr,
false,
Some(TruthWrapperScope::GroupedHaving),
work,
)?;
let expr = normalize_bool_expr(expr, work)?;
debug_assert!(is_normalized_bool_expr(&expr));
Ok(CanonicalExpr::new(expr))
}
pub(in crate::db) fn canonicalize_grouped_having_bool_expr(
expr: Expr,
work: &PreparationWork<'_>,
) -> Result<Expr, QueryError> {
canonicalize_grouped_having_bool_expr_artifact(expr, work).map(CanonicalExpr::into_expr)
}