use crate::db::{
query::{
builder::AggregateExpr,
plan::{AggregateKind, expr::Expr},
},
sql::lowering::SqlLoweringError,
};
pub(in crate::db::sql::lowering::aggregate) const fn reject_distinct_filter_pairing(
distinct: bool,
filter_expr: Option<&Expr>,
) -> Result<(), SqlLoweringError> {
if distinct && filter_expr.is_some() {
return Err(SqlLoweringError::unsupported_select_projection());
}
Ok(())
}
#[must_use]
pub(in crate::db::sql::lowering::aggregate) const fn apply_distinct_marker(
aggregate: AggregateExpr,
distinct: bool,
) -> AggregateExpr {
if distinct {
aggregate.distinct()
} else {
aggregate
}
}
pub(in crate::db::sql::lowering::aggregate) const fn preserve_distinct_for_strategy(
kind: AggregateKind,
distinct: bool,
) -> bool {
matches!(
kind,
AggregateKind::Count | AggregateKind::Sum | AggregateKind::Avg
) && distinct
}