Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions crates/asap-aware-mapping/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,6 @@ asap-types = { path = "../types" }
thiserror = "2"
serde = { version = "1", features = ["derive"] }
serde_json = "1"

[dev-dependencies]
asap-frontend-promql = { path = "../frontend-promql" }
56 changes: 56 additions & 0 deletions crates/asap-aware-mapping/src/accuracy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -716,6 +716,43 @@ impl AccuracyModel for DefaultAccuracyModel {
let same_metric = |metric: ErrorMetric| approximate.iter().all(|g| g.metric == metric);

match op {
CompositionOperator::CheckedRelativeDivision => {
if inputs.len() != 2 || local.is_some() || !same_metric(ErrorMetric::RelativeValue)
{
return Err(unsupported(
"checked division requires two exact/relative-value operands".into(),
));
}
let a = inputs[0]
.bound
.evaluate()
.ok_or_else(|| unsupported("unknown numerator bound".into()))?;
let b = inputs[1]
.bound
.evaluate()
.ok_or_else(|| unsupported("unknown denominator bound".into()))?;
if !(0.0..1.0).contains(&b) || a < 0.0 || !a.is_finite() {
return Err(unsupported("invalid relative division bounds".into()));
}
Ok(ResultGuarantee {
metric: ErrorMetric::RelativeValue,
bound: BoundExpr::Constant {
value: (a + b) / (1.0 - b) + 4.0 * f64::EPSILON,
},
failure_probability: ProbabilityExpr::UnionBound {
terms: inputs
.iter()
.map(|g| g.failure_probability.clone())
.collect(),
},
provenance: composed_provenance(
op,
inputs,
&ResultGuarantee::exact("checked floating-point division"),
"checked_relative_division_union_bound",
),
})
}
CompositionOperator::ApproximateAggregate => {
let local = local.ok_or_else(|| {
unsupported("approximate operator has no local guarantee to compose".into())
Expand Down Expand Up @@ -954,6 +991,25 @@ mod tests {
use asap_types::post_asap::{GroupingStrategy, SketchKind};
use asap_types::workload::{DataDistribution, DataWorkload, Evidence, EvidenceSource};

// Rank error cannot certify a numeric ratio; a same-sketch identity is not cancellation evidence.
#[test]
fn checked_division_propagates_value_bounds_and_rejects_rank_bounds() {
let op = CompositionOperator::CheckedRelativeDivision;
let inputs = [rel(0.01), rel(0.01)];
let g = DefaultAccuracyModel
.propagate(&op, &inputs, None, &Default::default())
.unwrap();
assert!((g.bound.evaluate().unwrap() - 0.02 / 0.99).abs() < 1e-14);
let mut rank = inputs[0].clone();
rank.metric = ErrorMetric::Rank;
assert!(DefaultAccuracyModel
.propagate(&op, &[rank.clone(), rank], None, &Default::default())
.is_err());
assert!(DefaultAccuracyModel
.propagate(&op, &[rel(0.01), rel(1.0)], None, &Default::default())
.is_err());
}

fn abs(bound: f64, delta: f64) -> ResultGuarantee {
ResultGuarantee {
metric: ErrorMetric::AbsoluteValue,
Expand Down
23 changes: 22 additions & 1 deletion crates/asap-aware-mapping/src/function_rules.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,11 @@ pub(crate) fn function_rules(intent: &AggIntent) -> Option<FunctionRules> {
CompositionOperator::ExactSum,
Some((ExactKind::Sum, ExactParams::Sum)),
),
AggIntent::Min { .. } | AggIntent::Max { .. } => (
AggIntent::Min { .. } => (
CompositionOperator::ExactExtremum,
Some((ExactKind::Min, ExactParams::Min)),
),
AggIntent::Max { .. } => (
CompositionOperator::ExactExtremum,
Some((ExactKind::MinMax, ExactParams::MinMax)),
),
Expand All @@ -39,3 +43,20 @@ pub(crate) fn function_rules(intent: &AggIntent) -> Option<FunctionRules> {
accumulator,
})
}

#[cfg(test)]
mod tests {
use super::*;
// The maintained extrema state must encode the direction independently of query text.
#[test]
fn minimum_and_maximum_have_distinct_accumulator_contracts() {
assert_ne!(
function_rules(&AggIntent::Min { col: None })
.unwrap()
.accumulator,
function_rules(&AggIntent::Max { col: None })
.unwrap()
.accumulator
);
}
}
2 changes: 2 additions & 0 deletions crates/asap-aware-mapping/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -254,3 +254,5 @@ pub use summary_maintenance_lifecycle::{
WorkloadDemand,
};
pub use topk_reuse::TopKLimitReuseStrategy;

pub mod maintained_population;
Loading
Loading