Skip to content
Merged
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
28 changes: 27 additions & 1 deletion crates/integration-tests/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,15 @@ pub mod planning {
pub fn run_stage1_to_stage3(
root: Rc<OperatorNode>,
accuracy: AccuracyTarget,
) -> asap_devtools::planning_stages::PlanningStagesRun {
run_stage1_to_stage3_with(root, accuracy, asap_planner::PlanningModels::builtin())
}

/// [`run_stage1_to_stage3`] with `models`.
fn run_stage1_to_stage3_with(
root: Rc<OperatorNode>,
accuracy: AccuracyTarget,
models: asap_planner::PlanningModels<'_>,
) -> asap_devtools::planning_stages::PlanningStagesRun {
let data = declared_data(&root);
asap_devtools::planning_stages::run_planning_stages_over(
Expand All @@ -204,7 +213,7 @@ pub mod planning {
}],
&data,
None,
asap_planner::PlanningModels::builtin(),
models,
)
.expect("Pass 1 accepts the query")
}
Expand Down Expand Up @@ -297,6 +306,23 @@ pub mod planning {
)
}

/// [`logical_candidates`] with every output accepted whatever its
/// accuracy guarantee (`ignore_accuracy_guarantees`), so Pass 1 keeps
/// the summaries no query can use for `accuracy`
/// (`PruneReason::NoErrorBoundForQueryTarget`). For tests of a
/// rewrite's structure or execution over a summary whose output has no
/// guarantee that meets `accuracy` (e.g. a value filter over an
/// estimate), not of accuracy acceptance.
pub fn logical_candidates_ignoring_guarantees(
root: Rc<OperatorNode>,
accuracy: AccuracyTarget,
) -> Vec<Rc<OperatorNode>> {
let models = asap_planner::PlanningModels::builtin().with_ignore_accuracy_guarantees(true);
require_composed_operator_candidates(
run_stage1_to_stage3_with(root, accuracy, models).logical_candidates(),
)
}

/// Fail on rejected composition rather than silently skipping a candidate.
pub fn require_composed_operator_candidates(
candidates: Vec<asap_devtools::planning_stages::ShownLogicalCandidate>,
Expand Down
14 changes: 9 additions & 5 deletions crates/integration-tests/tests/filtered_aggregates.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use asap_executor::{
values::{Batch, Value},
};
use asap_frontend_sql::{lower_sql, SqlCatalog};
use asap_integration_tests::planning::{logical_candidates, selected_dag};
use asap_integration_tests::planning::{logical_candidates_ignoring_guarantees, selected_dag};
use asap_types::ir::physical_export::PhysicalASAPOperatorPayload;
use asap_types::ir::properties::AccuracyTarget;
use asap_types::ir::schema::{DataType, Field, Schema};
Expand Down Expand Up @@ -194,15 +194,18 @@ async fn measure_filter(sql: &str) -> (Predicate, Schema) {
}

/// The logical candidates for `sql` whose single `SummaryAgg` has a family
/// matching `family`, with that `SummaryAgg`'s filter set by hand.
/// matching `family`, with that `SummaryAgg`'s filter set by hand. Every
/// guarantee is accepted: a grouped quantile's per-value guarantee meets no
/// whole-result target over groups the data does not bound, so Pass 1
/// would prune the sketch these execution tests run.
async fn hand_filtered(
sql: &str,
family: impl Fn(&FieldDataType) -> bool,
filter: &(Predicate, Schema),
) -> Vec<Rc<OperatorNode>> {
let target = AccuracyTarget::max_error(0.01).failure_probability(0.01);
let mut result = vec![];
for root in logical_candidates(lower(sql, target.clone()).await, target) {
for root in logical_candidates_ignoring_guarantees(lower(sql, target.clone()).await, target) {
let builds: Vec<_> = OperatorNode::reachable(&root)
.into_iter()
.filter(|n| matches!(n.asap(), Some(ASAPOp::SummaryAgg { .. })))
Expand Down Expand Up @@ -266,10 +269,11 @@ async fn hand_filtered_kll_compiles_and_executes() {
}
}

/// The KLL candidates of `sql`, unchanged.
/// The KLL candidates of `sql`, unchanged, every guarantee accepted (as
/// [`hand_filtered`]).
async fn kll_candidates(sql: &str) -> Vec<Rc<OperatorNode>> {
let target = AccuracyTarget::max_error(0.01).failure_probability(0.01);
let roots: Vec<_> = logical_candidates(lower(sql, target.clone()).await, target)
let roots: Vec<_> = logical_candidates_ignoring_guarantees(lower(sql, target.clone()).await, target)
.into_iter()
.filter(|root| {
OperatorNode::reachable(root).iter().any(|n| {
Expand Down
13 changes: 9 additions & 4 deletions crates/integration-tests/tests/per_computation_candidates_sql.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,11 +127,16 @@ async fn a_filter_or_group_key_over_an_estimate_has_no_guarantee() {
let root = lower_sql(sql, &catalog, accuracy.clone())
.await
.unwrap_or_else(|e| panic!("lower failed for {sql:?}: {e}"));
// No guarantee meets the target, so Pass 1 prunes the sketch
// unless every output is accepted.
let candidates: Vec<_> =
asap_integration_tests::planning::logical_candidates(root, accuracy.clone())
.into_iter()
.filter(reads_quantile_sketch)
.collect();
asap_integration_tests::planning::logical_candidates_ignoring_guarantees(
root,
accuracy.clone(),
)
.into_iter()
.filter(reads_quantile_sketch)
.collect();
assert!(!candidates.is_empty(), "{sql}");
for candidate in candidates {
assert_eq!(candidate.guarantee, None, "{sql}");
Expand Down
31 changes: 27 additions & 4 deletions crates/integration-tests/tests/promql_to_post_asap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ use asap_integration_tests::fixtures::lower_promql;
use asap_integration_tests::physical_export::{
at_ingestion, at_ingestion_physical_asap_dag, physical_asap_dag,
};
use asap_integration_tests::planning::logical_candidates;
use asap_integration_tests::planning::{
logical_candidates, logical_candidates_ignoring_guarantees,
};
use asap_physical_asap_optimization::PhysicalWorkloadPlan;
use asap_plan_selection::reference_pricer::WholePlanSelection as Selection;
use asap_types::ir::operator::operator_properties::Reduction;
Expand Down Expand Up @@ -64,7 +66,28 @@ fn candidates_using(
accuracy: AccuracyTarget,
algorithm: SketchAlgorithm,
) -> Vec<Rc<OperatorNode>> {
logical_candidates(Rc::clone(root), accuracy)
using(logical_candidates(Rc::clone(root), accuracy), algorithm)
}

/// [`candidates_using`] with every output accepted whatever its guarantee:
/// a heap-backed Top-K's output has no guarantee, so Pass 1 prunes the
/// heap these update and execution tests check unless guarantees are
/// ignored.
fn heap_topk_candidates_using(
root: &Rc<OperatorNode>,
accuracy: AccuracyTarget,
algorithm: SketchAlgorithm,
) -> Vec<Rc<OperatorNode>> {
using(
logical_candidates_ignoring_guarantees(Rc::clone(root), accuracy),
algorithm,
)
}

/// The `candidates` that build a sketch of `algorithm`, each below its
/// `Project`s.
fn using(candidates: Vec<Rc<OperatorNode>>, algorithm: SketchAlgorithm) -> Vec<Rc<OperatorNode>> {
candidates
.into_iter()
.filter(|candidate| uses_sketch(candidate, &algorithm))
.map(|candidate| Rc::clone(below_projects(&candidate)))
Expand Down Expand Up @@ -255,7 +278,7 @@ fn planner_only_e2e_temporal_topk_preserves_query_update_and_evaluation_contract
AccuracyTarget::max_error(0.01).failure_probability(0.01),
)
.expect("lower temporal Top-K");
let candidates = candidates_using(
let candidates = heap_topk_candidates_using(
&pre,
AccuracyTarget::max_error(0.01).failure_probability(0.01),
expected_family,
Expand Down Expand Up @@ -430,7 +453,7 @@ fn planner_heap_topk_reference_execution_matches_ground_truth() {
SketchAlgorithm::CountSketchWithHeap,
]
.into_iter()
.flat_map(|algorithm| candidates_using(&pre, accuracy.clone(), algorithm))
.flat_map(|algorithm| heap_topk_candidates_using(&pre, accuracy.clone(), algorithm))
.collect();
assert!(!candidates.is_empty(), "no heap candidate for {query}");
for plan in candidates {
Expand Down
27 changes: 23 additions & 4 deletions crates/integration-tests/tests/sql_to_post_asap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ use std::rc::Rc;

use asap_frontend_sql::{lower_sql, lower_sql_dialect, SqlCatalog};
use asap_integration_tests::physical_export::physical_asap_dag;
use asap_integration_tests::planning::logical_candidates;
use asap_integration_tests::planning::{
logical_candidates, logical_candidates_ignoring_guarantees,
};
use asap_types::ir::operator::operator_properties::Reduction;
use asap_types::ir::physical_export::{EdgeRole, PhysicalASAPNodeId, PhysicalASAPOperatorPayload};
use asap_types::ir::properties::AccuracyTarget;
Expand All @@ -38,7 +40,24 @@ use asap_types::workload::SqlDialect;
/// a query at `accuracy` that uses an ASAP operator, or the plain exact one
/// when none does: the summary-bound form the pins below inspect.
fn realize(root: &Rc<OperatorNode>, accuracy: AccuracyTarget) -> Rc<OperatorNode> {
let candidates = logical_candidates(Rc::clone(root), accuracy);
first_summary_bound(logical_candidates(Rc::clone(root), accuracy))
}

/// [`realize`] with every output accepted whatever its guarantee: a value
/// filter over an estimate has no guarantee, so Pass 1 prunes the summary
/// these pins inspect unless guarantees are ignored.
fn realize_ignoring_guarantees(
root: &Rc<OperatorNode>,
accuracy: AccuracyTarget,
) -> Rc<OperatorNode> {
first_summary_bound(logical_candidates_ignoring_guarantees(
Rc::clone(root),
accuracy,
))
}

/// The first of `candidates` that uses an ASAP operator, or the first.
fn first_summary_bound(candidates: Vec<Rc<OperatorNode>>) -> Rc<OperatorNode> {
let node = candidates
.iter()
.find(|candidate| candidate.contains_asap())
Expand Down Expand Up @@ -405,7 +424,7 @@ async fn sql_relational_parents_retain_summary_bound_aggregate() {
AccuracyTarget::max_error(0.01),
)
.await;
let root = realize(&pre_asap, AccuracyTarget::max_error(0.01));
let root = realize_ignoring_guarantees(&pre_asap, AccuracyTarget::max_error(0.01));

let mut node = root.as_ref();
let mut saw_project = false;
Expand Down Expand Up @@ -491,7 +510,7 @@ async fn sql_filter_keeps_read_predicate_and_summary_population_selection() {
};
assert_eq!(expected_source_predicates.len(), 1, "fixture source WHERE");

let root = realize(&pre_asap, AccuracyTarget::max_error(0.01));
let root = realize_ignoring_guarantees(&pre_asap, AccuracyTarget::max_error(0.01));

let mut node = root.as_ref();
let mut retained_read_predicate = None;
Expand Down
Loading