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/e2e/tests/aggregate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

use asap_e2e::fixtures::metric_schema;
use asap_frontend_promql::lower_promql;
use asap_ir::intent_algebra::{AggIntent, QueryExpr, Source};
use asap_ir::intent_algebra::{AggIntent, QueryExpr, Reduction, Source};
use asap_ir::types::AccuracyTarget;

fn lower(q: &str) -> QueryExpr {
Expand All @@ -29,7 +29,7 @@ fn scan(metric: &str, labels: &[&str]) -> QueryExpr {

fn agg(by: Vec<usize>, intent: AggIntent, child: QueryExpr) -> QueryExpr {
QueryExpr::Aggregate {
by: by.into(),
reduction: Reduction::by(by),
aggs: vec![intent],
output_names: vec!["".into()],
having: None,
Expand Down
10 changes: 5 additions & 5 deletions crates/e2e/tests/binary_op.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ use std::time::Duration;
use asap_e2e::fixtures::metric_schema;
use asap_frontend_promql::lower_promql;
use asap_ir::intent_algebra::{
AggIntent, ArithOp, BinaryOpKind, CompareOp, GroupSide, QueryExpr, Source, VectorGrouping,
VectorMatch, VectorMatchKind,
AggIntent, ArithOp, BinaryOpKind, CompareOp, GroupSide, QueryExpr, Reduction, Source,
VectorGrouping, VectorMatch, VectorMatchKind,
};
use asap_ir::types::AccuracyTarget;

Expand All @@ -31,7 +31,7 @@ fn scan(metric: &str, labels: &[&str]) -> QueryExpr {

fn rate_agg(metric: &str) -> QueryExpr {
QueryExpr::Aggregate {
by: vec![].into(),
reduction: Reduction::PerEntity,
aggs: vec![AggIntent::Rate],
output_names: vec!["".into()],
having: None,
Expand All @@ -44,7 +44,7 @@ fn rate_agg(metric: &str) -> QueryExpr {

fn sum_by_job(metric: &str) -> QueryExpr {
QueryExpr::Aggregate {
by: vec![2].into(),
reduction: Reduction::by(vec![2]),
aggs: vec![AggIntent::Sum { col: None }],
output_names: vec!["".into()],
having: None,
Expand Down Expand Up @@ -245,7 +245,7 @@ fn q36_unary_negation_is_multiply_by_minus_one() {
#[test]
fn q36_sum_of_negation_nests() {
let expected = QueryExpr::Aggregate {
by: vec![].into(),
reduction: Reduction::by(vec![]),
aggs: vec![AggIntent::Sum { col: None }],
output_names: vec!["".into()],
having: None,
Expand Down
46 changes: 23 additions & 23 deletions crates/e2e/tests/nested.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use asap_e2e::fixtures::metric_schema;
use asap_frontend_promql::lower_promql;
use asap_ir::intent_algebra::{
AggIntent, ArithOp, AtModifier, BinaryOpKind, CompareOp, GroupKeys, L3Expr, L3Scalar,
Predicate, QueryExpr, Source, TimeShift, VectorMatch, VectorMatchKind,
Predicate, QueryExpr, Reduction, Source, TimeShift, VectorMatch, VectorMatchKind,
};
use asap_ir::types::AccuracyTarget;

Expand All @@ -24,7 +24,17 @@ fn lower(q: &str) -> QueryExpr {

fn agg(by: Vec<usize>, intent: AggIntent, child: QueryExpr) -> QueryExpr {
QueryExpr::Aggregate {
by: by.into(),
reduction: Reduction::by(by),
aggs: vec![intent],
output_names: vec!["".into()],
having: None,
child: Box::new(child),
}
}

fn agg_per_entity(intent: AggIntent, child: QueryExpr) -> QueryExpr {
QueryExpr::Aggregate {
reduction: Reduction::PerEntity,
aggs: vec![intent],
output_names: vec!["".into()],
having: None,
Expand All @@ -43,8 +53,7 @@ fn q22_sum_by_job_over_rate() {
predicates: vec![],
schema: metric_schema(&["job"]),
};
let inner_rate = agg(
vec![],
let inner_rate = agg_per_entity(
AggIntent::Rate,
QueryExpr::TimeRange {
range: Duration::from_secs(300),
Expand Down Expand Up @@ -102,8 +111,7 @@ fn q25_div_over_complex_subtrees() {
let lhs = agg(
vec![2],
AggIntent::Sum { col: None },
agg(
vec![],
agg_per_entity(
AggIntent::Rate,
QueryExpr::TimeRange {
range: Duration::from_secs(300),
Expand All @@ -122,8 +130,7 @@ fn q25_div_over_complex_subtrees() {
let rhs = agg(
vec![2],
AggIntent::Sum { col: None },
agg(
vec![],
agg_per_entity(
AggIntent::Rate,
QueryExpr::TimeRange {
range: Duration::from_secs(300),
Expand Down Expand Up @@ -160,8 +167,7 @@ fn q27_max_over_sum_by_job_over_rate() {
predicates: vec![],
schema: metric_schema(&["job"]),
};
let inner_rate = agg(
vec![],
let inner_rate = agg_per_entity(
AggIntent::Rate,
QueryExpr::TimeRange {
range: Duration::from_secs(300),
Expand Down Expand Up @@ -256,16 +262,15 @@ fn q39_sum_without_instance_over_rate() {
predicates: vec![],
schema: metric_schema(&["instance"]),
};
let inner_rate = agg(
vec![],
let inner_rate = agg_per_entity(
AggIntent::Rate,
QueryExpr::TimeRange {
range: Duration::from_secs(300),
child: Box::new(scan),
},
);
let expected = QueryExpr::Aggregate {
by: GroupKeys::without(vec![2]), // exclude `instance`
reduction: Reduction::Reduce(GroupKeys::without(vec![2])), // exclude `instance`
aggs: vec![AggIntent::Sum { col: None }],
output_names: vec!["".into()],
having: None,
Expand Down Expand Up @@ -298,8 +303,7 @@ fn q40_week_over_week_offset() {
},
None => scan,
};
agg(
vec![],
agg_per_entity(
AggIntent::Rate,
QueryExpr::TimeRange {
range: Duration::from_secs(300),
Expand Down Expand Up @@ -352,8 +356,7 @@ fn q24_sum_by_job_over_rate_over_filtered_scan() {
})],
schema: metric_schema(&["job", "status"]),
};
let inner_rate = agg(
vec![],
let inner_rate = agg_per_entity(
AggIntent::Rate,
QueryExpr::TimeRange {
range: Duration::from_secs(300),
Expand Down Expand Up @@ -382,25 +385,22 @@ fn q27_nested_subquery_prometheus_docs_example() {
predicates: vec![],
schema: metric_schema(&[]),
};
let rate = agg(
vec![],
let rate = agg_per_entity(
AggIntent::Rate,
QueryExpr::TimeRange {
range: Duration::from_secs(5),
child: Box::new(scan),
},
);
let deriv = agg(
vec![],
let deriv = agg_per_entity(
AggIntent::Deriv,
QueryExpr::Subquery {
range: Duration::from_secs(30),
resolution: Some(Duration::from_secs(5)),
child: Box::new(rate),
},
);
let expected = agg(
vec![],
let expected = agg_per_entity(
AggIntent::Max { col: None },
QueryExpr::Subquery {
range: Duration::from_secs(600),
Expand Down
4 changes: 2 additions & 2 deletions crates/e2e/tests/time_range.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use std::time::Duration;

use asap_e2e::fixtures::metric_schema;
use asap_frontend_promql::lower_promql;
use asap_ir::intent_algebra::{AggIntent, QueryExpr, Source};
use asap_ir::intent_algebra::{AggIntent, QueryExpr, Reduction, Source};
use asap_ir::types::AccuracyTarget;

fn lower(q: &str) -> QueryExpr {
Expand All @@ -30,7 +30,7 @@ fn scan(metric: &str) -> QueryExpr {

fn range_agg(range_secs: u64, intent: AggIntent, metric: &str) -> QueryExpr {
QueryExpr::Aggregate {
by: vec![].into(),
reduction: Reduction::PerEntity,
aggs: vec![intent],
output_names: vec!["".into()],
having: None,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
#![allow(non_snake_case)]

use asap_frontend_promql::{lower_promql, PromqlError as LoweringError};
use asap_ir::intent_algebra::{AggIntent, BinaryOpKind, CompareOp, QueryExpr};
use asap_ir::intent_algebra::{AggIntent, BinaryOpKind, CompareOp, QueryExpr, Reduction};
use asap_ir::types::AccuracyTarget;

const CORPUS: &str = include_str!("data/awesome_prometheus_alerts.txt");
Expand Down Expand Up @@ -230,10 +230,17 @@ fn all_targets_missing_core_lowers() {
// Prometheus self-monitoring `sum by (job) (up)` (the corpus query is
// `… == 0`). Cross-series sum grouped positionally on `job`.
let qe = ok("sum by (job) (up)");
let QueryExpr::Aggregate { by, aggs, .. } = &qe else {
let QueryExpr::Aggregate {
reduction, aggs, ..
} = &qe
else {
panic!("expected Aggregate, got {qe:?}");
};
assert_eq!(by, &vec![2], "job grouping → col 2 in [ts, value, job]");
assert_eq!(
reduction,
&Reduction::by(vec![2]),
"job grouping → col 2 in [ts, value, job]"
);
assert!(matches!(aggs.as_slice(), [AggIntent::Sum { .. }]));
}

Expand Down Expand Up @@ -325,9 +332,15 @@ fn without_grouping_lowers_to_the_exclusion_form() {
let QueryExpr::BinaryOp { lhs, .. } = &qe else {
panic!("expected a comparison BinaryOp, got {qe:?}");
};
let QueryExpr::Aggregate { by, aggs, .. } = lhs.as_ref() else {
let QueryExpr::Aggregate {
reduction, aggs, ..
} = lhs.as_ref()
else {
panic!("expected a `min without` Aggregate on the LHS, got {lhs:?}");
};
assert!(by.is_without(), "grouping is the exclusion form");
assert!(
reduction.expect_reduce().is_without(),
"grouping is the exclusion form"
);
assert!(matches!(aggs.as_slice(), [AggIntent::Min { .. }]));
}
Loading
Loading