Skip to content

Commit dd00701

Browse files
authored
Merge pull request #291 from ProjectASAP/feat/concat-discriminator-unique-keys-228
feat(query-expr): add opt-in Concat discriminator key
2 parents b10c8d7 + 5a31247 commit dd00701

20 files changed

Lines changed: 814 additions & 49 deletions

File tree

‎crates/asap-aware-mapping/src/explanation.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -438,7 +438,7 @@ fn visit_children(
438438
| SQLWindowFunc { child, .. }
439439
| Sort { child, .. }
440440
| Limit { child, .. } => visit(child, format!("{label} > child"), locations),
441-
Concat { children } => {
441+
Concat { children, .. } => {
442442
for (i, c) in children.iter().enumerate() {
443443
visit_children(c, &format!("{label} > concat[{i}]"), locations);
444444
}

‎crates/asap-aware-mapping/src/query_physical_lowering.rs‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -693,7 +693,7 @@ pub fn lower_query_physical_dag(
693693
}
694694
self.lower_unary(query, occurrence, PhysicalOperator::PassThrough, child)
695695
}
696-
QueryExpr::Concat { children } => {
696+
QueryExpr::Concat { children, .. } => {
697697
let child_ids = children
698698
.iter()
699699
.map(|child| self.lower(child))
@@ -1979,6 +1979,7 @@ mod tests {
19791979

19801980
let concat = Rc::new(QueryExpr::Concat {
19811981
children: vec![scan("a"), scan("b")],
1982+
discriminator_unique_key: None,
19821983
});
19831984
let dag = lower_query_physical_dag(&concat, &scope, &scripted(&provided)).unwrap();
19841985
assert_eq!(dag.nodes.last().unwrap().operator, PhysicalOperator::Concat);

‎crates/asap-aware-mapping/src/replacement.rs‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3597,6 +3597,7 @@ fn direct_child_counts(node: &QueryExpr) -> Vec<(*const QueryExpr, usize)> {
35973597
}
35983598
Concat {
35993599
children: concat_children,
3600+
..
36003601
} => {
36013602
for c in concat_children {
36023603
collect(c, children);
@@ -4183,7 +4184,7 @@ fn walk_children(
41834184
| SQLWindowFunc { child, .. }
41844185
| Sort { child, .. }
41854186
| Limit { child, .. } => walk(child, order, nodes, counts),
4186-
Concat { children } => {
4187+
Concat { children, .. } => {
41874188
for c in children {
41884189
walk_children(c, order, nodes, counts);
41894190
}
@@ -5124,7 +5125,7 @@ mod tests {
51245125
| SQLWindowFunc { child, .. }
51255126
| Sort { child, .. }
51265127
| Limit { child, .. } => walk(child, counts),
5127-
Concat { children } => {
5128+
Concat { children, .. } => {
51285129
for c in children {
51295130
walk_children(c, counts);
51305131
}

‎crates/asap-aware-mapping/src/summary_maintenance_cost/model.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ pub(super) fn query_source_selections(
8787
| PromqlSeriesSample { child, .. }
8888
| Sort { child, .. }
8989
| Limit { child, .. } => query_source_selections(child, out)?,
90-
Concat { children } => {
90+
Concat { children, .. } => {
9191
for child in children {
9292
query_source_selections(child, out)?;
9393
}

‎crates/devtools/src/bin/variant_coverage.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ fn walk(e: &QueryExpr, seen: &mut BTreeSet<&'static str>) {
8888
seen.insert("Dedup");
8989
walk(child, seen);
9090
}
91-
QueryExpr::Concat { children } => {
91+
QueryExpr::Concat { children, .. } => {
9292
seen.insert("Concat");
9393
children.iter().for_each(|c| walk(c, seen));
9494
}

‎crates/frontend-promql/src/promql.rs‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -742,7 +742,13 @@ fn walk_histogram_quantiles(call: &Call) -> Result<Unresolved> {
742742
})
743743
})
744744
.collect::<Result<Vec<_>>>()?;
745-
Ok(Unresolved::Concat { children: branches })
745+
// No discriminator asserted here today (issue #228): the φ value each
746+
// branch carries via `PromqlRelabel` *is* structurally a distinct
747+
// per-branch discriminator, but nothing downstream currently needs the
748+
// resulting compound unique key — see
749+
// `docs/design_docs/concat-unique-keys-decision.md`. `Unresolved::concat`
750+
// keeps `output_schema`'s default (drop `unique_keys` entirely).
751+
Ok(Unresolved::concat(branches))
746752
}
747753

748754
/// Prometheus's `labels.FormatOpenMetricsFloat` — how `histogram_quantiles`

‎crates/frontend-promql/tests/observability/awesome_prometheus_alerts.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ fn intents(e: &QueryExpr) -> Vec<AggIntent> {
8383
go(lhs, out);
8484
go(rhs, out);
8585
}
86-
QueryExpr::Concat { children } => children.iter().for_each(|c| go(c, out)),
86+
QueryExpr::Concat { children, .. } => children.iter().for_each(|c| go(c, out)),
8787
QueryExpr::PromqlVectorFromScalar(inner) | QueryExpr::PromqlScalarFromVector(inner) => {
8888
go(inner, out)
8989
}

‎crates/frontend-promql/tests/promql_conformance.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ fn collect(e: &QueryExpr, out: &mut Vec<AggIntent>) {
9292
collect(left, out);
9393
collect(right, out);
9494
}
95-
QueryExpr::Concat { children } => children.iter().for_each(|c| collect(c, out)),
95+
QueryExpr::Concat { children, .. } => children.iter().for_each(|c| collect(c, out)),
9696
QueryExpr::PromqlVectorFromScalar(inner) | QueryExpr::PromqlScalarFromVector(inner) => {
9797
collect(inner, out)
9898
}

‎crates/frontend-promql/tests/promql_lowering.rs‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -920,7 +920,7 @@ fn topk_over_bare_selector_ranks_raw_samples() {
920920

921921
/// The `(label value, intent)` of each `histogram_quantiles` branch.
922922
fn quantile_branches(q: &QueryExpr) -> Vec<(String, AggIntent)> {
923-
let QueryExpr::Concat { children } = q else {
923+
let QueryExpr::Concat { children, .. } = q else {
924924
panic!("expected a Concat at the root, got {q:?}");
925925
};
926926
children
@@ -978,7 +978,7 @@ fn histogram_quantiles_branches_are_union_compatible() {
978978
// `Concat` derives its schema from the first child, so every branch must
979979
// agree on column names — the φ lives in the label, not the column name.
980980
let q = lower(r#"histogram_quantiles(testhistogram3, "q", 0.5, 0.9)"#);
981-
let QueryExpr::Concat { children } = &q else {
981+
let QueryExpr::Concat { children, .. } = &q else {
982982
panic!("expected Concat");
983983
};
984984
let shapes: Vec<Vec<String>> = children
@@ -1004,7 +1004,7 @@ fn histogram_quantiles_branches_are_union_compatible() {
10041004
#[test]
10051005
fn histogram_quantiles_uses_the_given_label_name() {
10061006
let q = lower(r#"histogram_quantiles(h, "phi", 0.5)"#);
1007-
let QueryExpr::Concat { children } = &q else {
1007+
let QueryExpr::Concat { children, .. } = &q else {
10081008
panic!("expected Concat");
10091009
};
10101010
let QueryExpr::PromqlRelabel { dst, .. } = &children[0] else {

‎crates/frontend-sql/src/sql/mod.rs‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -865,7 +865,14 @@ impl<'a> SqlLowerer<'a> {
865865
})
866866
.collect::<Result<Vec<_>, LoweringError>>()?;
867867

868-
Ok(Unresolved::Concat { children: branches })
868+
// No discriminator asserted here today (issue #228): DataFusion's own
869+
// `__grouping_id` would be the natural one, but this front end
870+
// already discards it (see above — `GROUPING()` itself is rejected),
871+
// so there is no distinct-per-branch column available to name yet.
872+
// `Unresolved::concat` keeps `output_schema`'s default (drop
873+
// `unique_keys` entirely). See
874+
// `docs/design_docs/concat-unique-keys-decision.md`.
875+
Ok(Unresolved::concat(branches))
869876
}
870877

871878
fn lower_sort(&self, sort: &logical_expr::Sort) -> Result<Unresolved, LoweringError> {

0 commit comments

Comments
 (0)