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
4 changes: 2 additions & 2 deletions crates/devtools/src/bin/asap_planner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,8 @@ use asap_types::ir::flat::{flatten, FlatDag, FlatNode};
use asap_types::ir::QueryRoot;
use asap_types::plan::physical_asap_dag::PhysicalASAPDAG;
use asap_types::stages::PhysicalASAPMemoCandidates;
use asap_types::stages::{queries_rooted_at, MemoGroup, MemoGroupId};
use asap_types::stages::{Memo, OriginOfCandidateForMemoGroup};
use asap_types::stages::{MemoGroup, MemoGroupId};
use asap_types::workload::{
DataArrival, DataWorkload, PlanningWorkload, QueryLanguage, QueryRecurrence,
QueryWorkloadEntry, RepeatedDemand,
Expand Down Expand Up @@ -757,7 +757,7 @@ fn memo_groups_json(table: &mut MemoNodes, memo: &Memo, previous: Option<&Memo>)
"children": group.expression.children().into_iter().map(|g| g.0).collect::<Vec<_>>(),
"parents": ids(group.parent_groups()),
"queries": group.reached_by_queries(),
"roots_of": queries_rooted_at(&memo.queries, MemoGroupId(id as u32)),
"roots_of": memo.queries_rooted_at(MemoGroupId(id as u32)),
"node": node,
"candidate_count": candidates.len(),
"candidate_count_by_origin": by_origin,
Expand Down
2 changes: 1 addition & 1 deletion crates/devtools/src/planning_stages_text.rs
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ fn write_memo(out: &mut String, memo: &Memo, previous: Option<&Memo>, with_candi
todo!("#1207 PR 9: print each candidate's expression, logical properties and input requirements")
}
let roots: Vec<String> = memo
.queries
.queries()
.iter()
.map(|query| match &query.root {
QueryRoot::Operator(group) => format!("G{}", group.0),
Expand Down
1 change: 1 addition & 0 deletions crates/executor/tests/current_timestamp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ fn scan_plan(predicates: Vec<Predicate<usize>>) -> PhysicalASAPDAG {
guarantee: None,
retention_ms: None,
selected_physical_candidate: None,
view_coverage: None,
}],
edges: vec![],
roots: vec![0],
Expand Down
1 change: 1 addition & 0 deletions crates/executor/tests/hydra_cms_execution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ fn node(id: usize, payload: Payload, output: Schema) -> PhysicalASAPDAGNode {
guarantee: None,
retention_ms: None,
selected_physical_candidate: None,
view_coverage: None,
}
}

Expand Down
1 change: 1 addition & 0 deletions crates/executor/tests/keyed_summary_row_weight.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ fn query_time_count_heap_binds_a_constant_row_weight() {
guarantee: None,
retention_ms: None,
selected_physical_candidate: None,
view_coverage: None,
};
let build = compile_node(&node, std::slice::from_ref(&input)).unwrap();
let wire = serde_json::to_value(&build).unwrap();
Expand Down
5 changes: 5 additions & 0 deletions crates/executor/tests/physical_dag.rs
Original file line number Diff line number Diff line change
Expand Up @@ -537,6 +537,7 @@ fn bind_physical_asap_dag_before_execution() {
guarantee: None,
retention_ms: None,
selected_physical_candidate: None,
view_coverage: None,
};
let mut dag = PhysicalASAPDAG {
nodes: vec![
Expand Down Expand Up @@ -699,6 +700,7 @@ fn planner_semijoin_sort_limit_contract_at_both_phases() {
guarantee: None,
retention_ms: None,
selected_physical_candidate: None,
view_coverage: None,
};
let edge = |producer, consumer, role, schema: &asap_executor::values::SchemaRef| {
PhysicalASAPDAGEdge::new(
Expand Down Expand Up @@ -1120,6 +1122,7 @@ fn grouped_temporal_schema_compiles_and_executes_topk() {
guarantee: None,
retention_ms: None,
selected_physical_candidate: None,
view_coverage: None,
};
let edge = |producer, consumer| {
PhysicalASAPDAGEdge::new(
Expand Down Expand Up @@ -1222,6 +1225,7 @@ fn certified_pruning_rejects_missing_authoritative_values_after_recovery() {
right: 1,
}),
selected_physical_candidate: None,
view_coverage: None,
};
let join = if certified {
Operator::certified_semi_join(schema.clone(), schema.clone(), vec![(0, 0)]).unwrap()
Expand Down Expand Up @@ -1329,6 +1333,7 @@ fn compiled_ingestion_binary_preserves_alignment_and_rejects_missing_updates() {
rhs: 1,
}),
selected_physical_candidate: None,
view_coverage: None,
};
let binary = compile_node(&node, &[input.clone(), input.clone()]).unwrap();
for (right, expected) in [
Expand Down
3 changes: 3 additions & 0 deletions crates/executor/tests/physical_semantics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,7 @@ fn global_extrema_bind_with_planner_derived_schema() {
guarantee: None,
retention_ms: None,
selected_physical_candidate: None,
view_coverage: None,
};
let operator = compile_node(&node, std::slice::from_ref(&input))
.expect("global extremum should bind to its Planner schema");
Expand Down Expand Up @@ -935,6 +936,7 @@ fn planner_node(
guarantee: None,
retention_ms: None,
selected_physical_candidate: None,
view_coverage: None,
}
}

Expand Down Expand Up @@ -1168,6 +1170,7 @@ fn exact_aggregate_node(
guarantee: None,
retention_ms: None,
selected_physical_candidate: None,
view_coverage: None,
}
}

Expand Down
1 change: 1 addition & 0 deletions crates/executor/tests/plan_properties.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ fn sorted_scan(schema: &Schema, identity: &Source) -> PhysicalASAPDAG {
guarantee: None,
retention_ms: None,
selected_physical_candidate: None,
view_coverage: None,
};
PhysicalASAPDAG {
nodes: vec![
Expand Down
4 changes: 4 additions & 0 deletions crates/executor/tests/precompute_population.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ fn view_over_samples(family: FieldDataType, scan: usize) -> [PhysicalASAPDAGNode
guarantee: None,
retention_ms: None,
selected_physical_candidate: None,
view_coverage: None,
};
[
PhysicalASAPDAGNode {
Expand Down Expand Up @@ -141,6 +142,7 @@ fn try_state_dag(
guarantee: None,
retention_ms: None,
selected_physical_candidate: None,
view_coverage: None,
});
}
let read_id = nodes.len();
Expand All @@ -156,6 +158,7 @@ fn try_state_dag(
guarantee: None,
retention_ms: None,
selected_physical_candidate: None,
view_coverage: None,
});
if let Some(target) = target {
nodes.push(PhysicalASAPDAGNode {
Expand All @@ -176,6 +179,7 @@ fn try_state_dag(
guarantee: None,
retention_ms: None,
selected_physical_candidate: None,
view_coverage: None,
});
}
let root = nodes.last().unwrap().id;
Expand Down
2 changes: 2 additions & 0 deletions crates/executor/tests/promql_binary.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ fn program_for_bool(operator: BinaryOperator, return_bool: bool) -> Operator {
guarantee: None,
retention_ms: None,
selected_physical_candidate: None,
view_coverage: None,
};
compile_node(&node, &[schema.clone(), schema]).unwrap()
}
Expand Down Expand Up @@ -428,6 +429,7 @@ fn stored_series_evaluations_support_filters_and_sets() {
guarantee: None,
retention_ms: None,
selected_physical_candidate: None,
view_coverage: None,
})
.collect::<Vec<_>>();
let edges = [
Expand Down
3 changes: 3 additions & 0 deletions crates/executor/tests/raw_scan.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ fn plan(
guarantee: None,
retention_ms: None,
selected_physical_candidate: None,
view_coverage: None,
};
let edge = |producer, consumer| {
PhysicalASAPDAGEdge::new(
Expand Down Expand Up @@ -513,6 +514,7 @@ fn windowed_plan(shift_ms: Option<i64>) -> PhysicalASAPDAG {
guarantee: None,
retention_ms: None,
selected_physical_candidate: None,
view_coverage: None,
};
let edge = |producer, consumer| {
PhysicalASAPDAGEdge::new(
Expand Down Expand Up @@ -848,6 +850,7 @@ fn windowed_count_plan(shift_ms: Option<i64>) -> PhysicalASAPDAG {
guarantee: None,
retention_ms: None,
selected_physical_candidate: None,
view_coverage: None,
}
};
dag.nodes.push(node(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,7 @@ fn merge_over_a_stored_tumbling_window(
guarantee: None,
retention_ms: None,
selected_physical_candidate: None,
view_coverage: None,
};
let nodes = vec![
node(
Expand Down
4 changes: 4 additions & 0 deletions crates/executor/tests/summary_projection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ fn raw_node(id: usize, payload: NonASAPOp<usize>) -> PhysicalASAPDAGNode {
guarantee: None,
retention_ms: None,
selected_physical_candidate: None,
view_coverage: None,
}
}

Expand Down Expand Up @@ -130,6 +131,7 @@ fn summary_projection_survives_recovery() {
guarantee: None,
retention_ms: None,
selected_physical_candidate: None,
view_coverage: None,
},
raw_node(2, scan()),
raw_node(
Expand Down Expand Up @@ -160,6 +162,7 @@ fn summary_projection_survives_recovery() {
guarantee: None,
retention_ms: None,
selected_physical_candidate: None,
view_coverage: None,
},
],
edges: vec![
Expand Down Expand Up @@ -269,6 +272,7 @@ fn summary_merge_without_inputs_is_rejected() {
guarantee: None,
retention_ms: None,
selected_physical_candidate: None,
view_coverage: None,
}],
edges: vec![],
roots: vec![0],
Expand Down
1 change: 1 addition & 0 deletions crates/executor/tests/univmon_execution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ fn planner_unit_frequency_update_binds_as_a_value_frequency_build() -> Result<()
guarantee: None,
retention_ms: None,
selected_physical_candidate: None,
view_coverage: None,
};
let build = compile_node(&node, std::slice::from_ref(&input))?;
let batch = Batch::try_new(
Expand Down
2 changes: 1 addition & 1 deletion crates/frontend-common/src/canonicalize.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//! Post-lowering canonicalization of the operator DAG.
//!
//! Rewrites equivalent spellings of a query into one shape, so that common
//! sub-DAG sharing (Stage 0 hash-consing, `cse` in `asap_stage0_memo`) can match
//! sub-DAG sharing (hash-consing, `Memo::find_or_add_group`) can match
//! them by structural equality, whichever front end produced them.
//!
//! ## Heavy-hitter promotion
Expand Down
20 changes: 15 additions & 5 deletions crates/frontend-common/src/resolve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -487,11 +487,21 @@ fn resolve_expr_in(
S::Not(e) => ScalarExpr::Not(bx(e)?),
S::IsNull(e) => ScalarExpr::IsNull(bx(e)?),
S::IsNotNull(e) => ScalarExpr::IsNotNull(bx(e)?),
S::Cast { expr, to, try_cast } => ScalarExpr::Cast {
expr: bx(expr)?,
to: to.clone(),
try_cast: *try_cast,
},
// A cast to the type its operand already has is the operand: SQL's
// `ts >= '2026-11-01'` casts the Timestamp column `ts` to DataFusion's
// nanosecond timestamp, which is the same IR type.
S::Cast { expr, to, try_cast } => {
let operand = bx(expr)?;
if matches!(operand.scalar_type(schema), Ok((dtype, _)) if dtype == *to) {
*operand
} else {
ScalarExpr::Cast {
expr: operand,
to: to.clone(),
try_cast: *try_cast,
}
}
}
S::InList {
expr,
list,
Expand Down
47 changes: 45 additions & 2 deletions crates/frontend-promql/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,11 +117,12 @@ mod tests {
use std::rc::Rc;
use std::time::Duration;

use asap_types::ir::operator::arguments::{AtModifier, TimeShift};
use asap_types::ir::operator::Source;
use asap_types::ir::{NonASAPOp, OperatorNode, TimeRangeKind};
use asap_types::ir::{NonASAPOp, OperatorNode, QueryRoot, TimeRangeKind};
use asap_types::workload::{
BatchEntry, DataArrival, DataWorkload, PlanningWorkload, Query, QueryRequirements,
QueryWorkload, SourceFacts, WorkloadError,
QueryWorkload, RangeEvaluation, SourceFacts, WorkloadError,
};

use super::*;
Expand Down Expand Up @@ -366,4 +367,46 @@ mod tests {
)
.is_empty());
}

/// `@ end()` and `@ start()` are lifted above the selector they anchor,
/// which is lowered without them (its offset stays): the selector of
/// `sum_over_time(data[5m] @ start() offset 1m)` is
/// `TimeShift(@ start())` over the selector of
/// `sum_over_time(data[5m] offset 1m)`, so the two share it. Instant and
/// range-evaluated queries lower alike.
#[test]
fn at_start_and_at_end_are_lifted_above_the_selector_they_anchor() {
let lowered = |query: &str| {
let roots = lower_promql_query_workload(&workload(query)).unwrap();
let [QueryRoot::Operator(root)] = &roots[..] else {
panic!("one operator root");
};
Rc::clone(root.children()[0])
};
let pinned = lowered("sum_over_time(data[5m] @ start() offset 1m)");
let NonASAPOp::TimeShift { shift, child } = pinned.expect_non_asap() else {
panic!("expected the lifted TimeShift, got {pinned:?}");
};
assert_eq!(
*shift,
TimeShift {
offset_ms: 0,
at: Some(AtModifier::Start),
}
);
assert_eq!(*child, lowered("sum_over_time(data[5m] offset 1m)"));

let mut range_query = workload("sum_over_time(data[5m] @ start() offset 1m)");
if let Some(batch) = range_query.query_workload.query_batch.as_mut() {
batch[0].range_evaluation = Some(RangeEvaluation {
step_ms: 60_000,
span_ms: 3_600_000,
});
}
assert_eq!(
lower_promql_query_workload(&range_query).unwrap(),
lower_promql_query_workload(&workload("sum_over_time(data[5m] @ start() offset 1m)"))
.unwrap()
);
}
}
Loading
Loading