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
2 changes: 1 addition & 1 deletion crates/executor/tests/physical_dag.rs
Original file line number Diff line number Diff line change
Expand Up @@ -786,7 +786,7 @@ fn planner_semijoin_sort_limit_contract_at_both_phases() {
node.output_state.timing = phase;
}
for edge in &mut dag.edges {
edge.data_state().timing = phase;
edge.data_state_mut().timing = phase;
}
let store = with_table(
Default::default(),
Expand Down
3 changes: 2 additions & 1 deletion crates/frontend-promql/tests/count_planning.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
//! Query text through summary selection: counts use observations, never value weights.
use crate::planner_support::selected_dag;
use crate::support;
use asap_types::ir::physical_export::PhysicalASAPOperatorPayload;
use asap_types::ir::properties::AccuracyTarget;
Expand All @@ -8,7 +9,7 @@ use asap_types::ir::schema::{
};
use asap_types::ir::{ASAPOp, Operator, OperatorNode};
use std::rc::Rc;
use support::{logical_candidates, lower_promql, physical_asap_dag, selected_dag};
use support::{logical_candidates, lower_promql, physical_asap_dag};

/// Whether `node` reads a Hydra state (one sketch shared by every group).
fn reads_hydra(node: &Rc<OperatorNode>) -> bool {
Expand Down
1 change: 1 addition & 0 deletions crates/frontend-promql/tests/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
//! its own copy of every dependency, which outgrew CI's disk.
//! One file: `cargo test -p asap-frontend-promql --test promql <file>::`.

mod planner_support;
mod support;

mod count_planning;
Expand Down
44 changes: 44 additions & 0 deletions crates/frontend-promql/tests/planner_support.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
//! Planner-facade helpers for this crate's tests. Kept out of `support.rs`,
//! which the private corpus also compiles without depending on asap-planner.
use std::rc::Rc;

use asap_types::ir::properties::AccuracyTarget;
use asap_types::ir::OperatorNode;

use crate::support::declared_data;

/// Every planning stage's output for the single query `root` at `accuracy`,
/// with the built-in models.
pub fn run_stage1_to_stage3(
root: Rc<OperatorNode>,
accuracy: AccuracyTarget,
) -> asap_planner::PlanningRun {
let data = declared_data(&root);
asap_planner::run_planning(
vec![asap_types::ir::QueryRoot::Operator(root)],
&[asap_types::workload::QueryWorkloadEntry {
query: Default::default(),
requirements: asap_types::workload::QueryRequirements {
accuracy,
max_latency_ms: None,
},
predictability: Default::default(),
recurrence: Default::default(),
range_evaluation: None,
}],
&data,
asap_planner::PlanningModels::builtin(),
asap_planner::PlanSearchSettings::default(),
)
.expect("Pass 1 accepts the query")
}

/// The logical DAG the planner pipeline selects for the single query `root`
/// at `accuracy`.
pub fn selected_dag(root: Rc<OperatorNode>, accuracy: AccuracyTarget) -> Rc<OperatorNode> {
let run = run_stage1_to_stage3(root, accuracy);
match run.selected_plan.as_deref().expect("a plan is selected") {
[asap_types::ir::QueryRoot::Operator(node)] => Rc::clone(node),
other => panic!("one operator root: {other:?}"),
}
}
38 changes: 0 additions & 38 deletions crates/frontend-promql/tests/support.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,44 +139,6 @@ pub fn declared_data(root: &Rc<OperatorNode>) -> DataWorkload {
}
}

/// Every planning stage's output for the single query `root` at `accuracy`,
/// with the built-in models.
#[allow(dead_code)]
pub fn run_stage1_to_stage3(
root: Rc<OperatorNode>,
accuracy: AccuracyTarget,
) -> asap_planner::PlanningRun {
let data = declared_data(&root);
asap_planner::run_planning(
vec![asap_types::ir::QueryRoot::Operator(root)],
&[asap_types::workload::QueryWorkloadEntry {
query: Default::default(),
requirements: asap_types::workload::QueryRequirements {
accuracy,
max_latency_ms: None,
},
predictability: Default::default(),
recurrence: Default::default(),
range_evaluation: None,
}],
&data,
asap_planner::PlanningModels::builtin(),
asap_planner::PlanSearchSettings::default(),
)
.expect("Pass 1 accepts the query")
}

/// The logical DAG the planner pipeline selects for the single query `root`
/// at `accuracy`.
#[allow(dead_code)]
pub fn selected_dag(root: Rc<OperatorNode>, accuracy: AccuracyTarget) -> Rc<OperatorNode> {
let run = run_stage1_to_stage3(root, accuracy);
match run.selected_plan.as_deref().expect("a plan is selected") {
[asap_types::ir::QueryRoot::Operator(node)] => Rc::clone(node),
other => panic!("one operator root: {other:?}"),
}
}

/// Local computation candidates for frontend binding tests. Other computations
/// keep their default choices; a timed MILP archive is not a candidate catalog.
#[allow(dead_code)]
Expand Down
3 changes: 2 additions & 1 deletion crates/frontend-promql/tests/univmon_candidates.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
use std::rc::Rc;

use crate::planner_support::run_stage1_to_stage3;
use crate::support;
use asap_accuracy::test_support::{local_guarantee, satisfies};
use asap_logical_asap_optimization::pass2::cse::share_common_sub_dags;
use asap_types::ir::properties::AccuracyMetric;
use asap_types::ir::properties::AccuracyTarget;
use asap_types::ir::schema::{FieldDataType, SketchAlgorithm, SketchStatistic, SummaryInputExpr};
use asap_types::ir::{ASAPOp, Operator, OperatorNode};
use support::{logical_candidates, lower_promql, physical_asap_dag, run_stage1_to_stage3};
use support::{logical_candidates, lower_promql, physical_asap_dag};

/// The summary evaluation over a UnivMon state that `root` reads, if any.
fn univmon_estimate(root: &Rc<OperatorNode>) -> Option<Rc<OperatorNode>> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -539,7 +539,7 @@ pub enum PerComputationCandidateError {
AssignedPhysicalAnnotation,
#[error("logical candidate input already contains ASAP operators")]
ContainsAsap,
/// `root` (the root id's `Debug` form) and `measure` locate the target;
/// `root` (the query's index in the workload) and `measure` locate the target;
/// [`computation_candidates_for_intent`] alone leaves them `None`.
#[error(
"approximate accuracy of root {}, measure {} requires epsilon and delta in (0, 1)",
Expand Down
4 changes: 3 additions & 1 deletion crates/logical-asap-optimization/src/pass2/memo/groups.rs
Original file line number Diff line number Diff line change
Expand Up @@ -532,10 +532,12 @@ mod tests {
)),
)];
let initial = DagOfLogicalMemoGroups::from_roots(&roots);
// An inventory is tied to its roots by structure: the same query
// text lowered again is the same DAG, so the other roots must differ.
let other_roots = vec![(
0,
QueryRoot::Operator(lower_promql(
"quantile_over_time(0.95, m[5m])",
"quantile_over_time(0.5, n[1m])",
AccuracyTarget::max_error(0.01),
)),
)];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,7 @@ fn assigned_physical_annotation_asap_input_and_invalid_accuracy_are_rejected() {
);
let error = generate_per_computation_candidates(
&asap_logical_asap_optimization::pass2::memo::DagOfLogicalMemoGroups::from_roots(&[(
"q",
0,
QueryRoot::Operator(invalid),
)]),
)
Expand All @@ -364,14 +364,11 @@ fn assigned_physical_annotation_asap_input_and_invalid_accuracy_are_rejected() {
PerComputationCandidateError::InvalidAccuracy {
root: Some(root),
measure: Some(1)
} if root == "\"q\""
} if root == "0"
),
"{error:?}"
);
assert!(
error.to_string().contains("root \"q\", measure 1 "),
"{error}"
);
assert!(error.to_string().contains("root 0, measure 1 "), "{error}");
}

/// TopK keeps both declared heap substrates without choosing an implementation.
Expand Down Expand Up @@ -704,7 +701,8 @@ fn having_on_one_consumer_of_a_shared_aggregate_stays_above() {
.having_filters
.iter()
.all(|entry| entry.placement == HavingPlacement::BelowAggregate));
assert_eq!(targets[0].having_filters.len(), 2);
// The two equal `Filter`s are one memo group, so one HAVING entry.
assert_eq!(targets[0].having_filters.len(), 1);
}

/// A scalar reference to a grouped aggregate (`Filter(scan, EXISTS G)` as a
Expand Down Expand Up @@ -1461,7 +1459,9 @@ fn grouped_avg_composition_preserves_the_whole_schema() {
assert_eq!(out.schema, root.schema);
}

// Filtered and unfiltered consumers of a shared group keep their own HAVING placement.
// Structurally equal aggregates are one memo group with one target, and its
// HAVING placement is decided over every consumer of the group: an unfiltered
// consumer keeps the key-only HAVING above the output for the filtered ones.
#[test]
fn memo_cached_rules_preserve_occurrence_specific_having() {
use asap_logical_asap_optimization::pass2::memo::DagOfLogicalMemoGroups;
Expand All @@ -1478,9 +1478,10 @@ fn memo_cached_rules_preserve_occurrence_specific_having() {
];
let memo = DagOfLogicalMemoGroups::from_roots(&roots);
let cached = generate_per_computation_candidates(&memo).unwrap();
assert_eq!(cached.targets.len(), 2);
assert_ne!(
cached.targets[0].having_filters[0].placement,
cached.targets[1].having_filters[0].placement
);
assert_eq!(cached.targets.len(), 1);
// Roots 0 and 2 apply the same `Filter`, one memo group: one entry.
let [entry] = &cached.targets[0].having_filters[..] else {
panic!("one HAVING entry: {:?}", cached.targets[0].having_filters);
};
assert_eq!(entry.placement, HavingPlacement::AboveOutput);
}
Loading