Skip to content

Commit 150735f

Browse files
committed
refactor: rename legacy QueryExprError to SchemaDerivationError
1 parent fc328b1 commit 150735f

15 files changed

Lines changed: 111 additions & 98 deletions

File tree

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,7 @@ use std::collections::{HashMap, HashSet, VecDeque};
353353
use asap_types::ir::cse::{share_common_subdags, structural_hash, HashCache};
354354
use asap_types::ir::operator_properties::{BinaryOpKind, JoinKind, Reduction};
355355
use asap_types::ir::timing::validate_default;
356-
use asap_types::ir::QueryExprError;
356+
use asap_types::ir::SchemaDerivationError;
357357
use asap_types::ir::{
358358
ASAPOp, BinaryOperator, NonASAPOp, Operator, OperatorNode, Predicate, ProjectItem, ScalarExpr,
359359
SortKey,
@@ -402,7 +402,7 @@ use crate::topk_reuse::TopKLimitReuseStrategy;
402402
pub enum RealizationError {
403403
/// Schema derivation failed while lifting an edge to `Schema`.
404404
#[error("schema derivation failed during pre-ASAP → post-ASAP binding: {0}")]
405-
Schema(#[from] QueryExprError),
405+
Schema(#[from] SchemaDerivationError),
406406
/// The candidate is accuracy-illegal (issue #172): its composed
407407
/// guarantee has no sound propagation rule, or misses the applicable
408408
/// `AccuracyTarget`. Fail-closed — the candidate is never constructed

‎crates/frontend-common/src/resolve.rs‎

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ use asap_types::ir::{NonASAPOp, OperatorNode, Predicate, ProjectItem, ScalarExpr
2424
use asap_types::pre_asap::column_resolution::resolve_group_keys_promql;
2525
use asap_types::pre_asap::{
2626
aggregate_output_schema, resolve_column_ref, resolve_column_refs, AggIntent, ColumnId,
27-
ColumnRef, GroupKeys, QueryExprError, Reduction, ResolveError, Schema,
27+
ColumnRef, GroupKeys, Reduction, ResolveError, Schema, SchemaDerivationError,
2828
};
2929

3030
use crate::schema_resolver::{collect_referenced_columns, SchemaResolver};
@@ -39,7 +39,7 @@ pub enum ResolveTreeError {
3939
/// Deriving the schema of an already-resolved child failed (needed to
4040
/// resolve positional column references against it).
4141
#[error("schema derivation failed: {0}")]
42-
Schema(#[from] QueryExprError),
42+
Schema(#[from] SchemaDerivationError),
4343
}
4444

4545
use asap_types::ir::canonicalize::canonicalize;
@@ -149,7 +149,7 @@ fn resolve(tree: &UnresolvedOp, fallback: &Schema) -> Result<Rc<OperatorNode>, R
149149
child
150150
} else {
151151
asap_types::pre_asap::schema::with_promql_series_identity(&child)
152-
.map_err(QueryExprError::InvalidScalarSignature)?
152+
.map_err(SchemaDerivationError::InvalidScalarSignature)?
153153
};
154154
let scalar = resolve_expr(scalar, &Schema::default())?;
155155
lower_scalar_vector(child, scalar, op, *scalar_left, *return_bool)
@@ -164,7 +164,7 @@ fn resolve(tree: &UnresolvedOp, fallback: &Schema) -> Result<Rc<OperatorNode>, R
164164
child
165165
} else {
166166
asap_types::pre_asap::schema::with_promql_series_identity(&child)
167-
.map_err(QueryExprError::InvalidScalarSignature)?
167+
.map_err(SchemaDerivationError::InvalidScalarSignature)?
168168
};
169169
let sample = resolve_expr(sample, &child.schema)?;
170170
project_sample(child, sample, *drop_metric_name)
@@ -286,7 +286,10 @@ fn resolve(tree: &UnresolvedOp, fallback: &Schema) -> Result<Rc<OperatorNode>, R
286286
let discriminator_unique_key = discriminator_unique_key
287287
.as_ref()
288288
.map(|key| {
289-
let schema = &children.first().ok_or(QueryExprError::EmptyConcat)?.schema;
289+
let schema = &children
290+
.first()
291+
.ok_or(SchemaDerivationError::EmptyConcat)?
292+
.schema;
290293
Ok::<_, ResolveTreeError>(ConcatDiscriminatorKey::new(
291294
resolve_column_ref(key.discriminator(), schema)?,
292295
resolve_column_refs(key.inner_key(), schema)?,
@@ -743,7 +746,7 @@ fn lower_scalar_vector(
743746
.next_back()
744747
})
745748
.ok_or_else(|| {
746-
QueryExprError::InvalidScalarSignature("vector has no numeric sample".into())
749+
SchemaDerivationError::InvalidScalarSignature("vector has no numeric sample".into())
747750
})?;
748751
let sample = ScalarExpr::Column(value);
749752
let (left, right) = if scalar_left {
@@ -779,7 +782,7 @@ fn lower_scalar_vector(
779782
}
780783
}
781784
BinaryOpKind::Set(_) => {
782-
return Err(QueryExprError::InvalidScalarSignature(
785+
return Err(SchemaDerivationError::InvalidScalarSignature(
783786
"set operators require two vectors".into(),
784787
)
785788
.into())

‎crates/types/src/ir/aggregate_schema.rs‎

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,25 +6,28 @@
66
//! and produces a Float64 sample value. This module derives schemas, not
77
//! aggregate values or summary candidates.
88
use super::operator_properties::*;
9-
use super::QueryExprError;
9+
use super::SchemaDerivationError;
1010
use crate::pre_asap::{AggIntent, ColumnId, ColumnRef, DataType, Field, FieldDataType, Schema};
1111
/// Output schema of a *per-series* window/range reduction (`rate`/`increase`,
1212
/// or an `*_over_time` reducer under a time `Window`). Such a reduction emits
1313
/// one value per series, so every label column of `input` is preserved and only
1414
/// the sample value is replaced — kept named `value` so the PromQL sample-value
1515
/// convention (and any outer `SampleValue` reference) still resolves it by name.
16-
fn per_series_reduction_schema(input: &Schema, agg: &AggIntent) -> Result<Schema, QueryExprError> {
16+
fn per_series_reduction_schema(
17+
input: &Schema,
18+
agg: &AggIntent,
19+
) -> Result<Schema, SchemaDerivationError> {
1720
let vi = if let Some(index) = agg.input_cols().first() {
1821
*index
1922
} else {
2023
crate::pre_asap::column_resolution::resolve_column_ref(&ColumnRef::SampleValue, input)
21-
.map_err(|error| QueryExprError::InvalidSampleColumn(error.to_string()))?
24+
.map_err(|error| SchemaDerivationError::InvalidSampleColumn(error.to_string()))?
2225
};
2326
if !matches!(
2427
input.fields.get(vi).map(|column| &column.dtype),
2528
Some(FieldDataType::Plain(DataType::Float64 | DataType::Int64))
2629
) {
27-
return Err(QueryExprError::InvalidSampleColumn(format!(
30+
return Err(SchemaDerivationError::InvalidSampleColumn(format!(
2831
"column {vi} is not numeric"
2932
)));
3033
}
@@ -65,7 +68,7 @@ pub fn aggregate_output_schema(
6568
reduction: &Reduction,
6669
measures: &[AggIntent],
6770
output_names: &[String],
68-
) -> Result<Schema, QueryExprError> {
71+
) -> Result<Schema, SchemaDerivationError> {
6972
let by = match reduction {
7073
Reduction::PerEntity => {
7174
debug_assert_eq!(
@@ -92,7 +95,7 @@ pub fn aggregate_output_schema(
9295
let c = in_schema
9396
.fields
9497
.get(id)
95-
.ok_or(QueryExprError::InvalidGroupByColumn(
98+
.ok_or(SchemaDerivationError::InvalidGroupByColumn(
9699
id,
97100
in_schema.fields.len(),
98101
))?;
@@ -143,7 +146,7 @@ pub fn aggregate_output_schema(
143146
}
144147
if let Some((arg, _)) = intent
145148
.arg_selector_columns(in_schema)
146-
.map_err(QueryExprError::InvalidScalarSignature)?
149+
.map_err(SchemaDerivationError::InvalidScalarSignature)?
147150
{
148151
out.dtype = in_schema.fields[arg].dtype.clone();
149152
out.nullable = in_schema.fields[arg].nullable;
@@ -185,10 +188,10 @@ fn without_output_schema(
185188
excluded: &[ColumnId],
186189
measures: &[AggIntent],
187190
output_names: &[String],
188-
) -> Result<Schema, QueryExprError> {
191+
) -> Result<Schema, SchemaDerivationError> {
189192
for &id in excluded {
190193
if id >= in_schema.fields.len() {
191-
return Err(QueryExprError::InvalidGroupByColumn(
194+
return Err(SchemaDerivationError::InvalidGroupByColumn(
192195
id,
193196
in_schema.fields.len(),
194197
));
@@ -224,7 +227,7 @@ fn without_output_schema(
224227
let mut out = intent.output_column(in_col);
225228
if let Some((arg, _)) = intent
226229
.arg_selector_columns(in_schema)
227-
.map_err(QueryExprError::InvalidScalarSignature)?
230+
.map_err(SchemaDerivationError::InvalidScalarSignature)?
228231
{
229232
out.dtype = in_schema.fields[arg].dtype.clone();
230233
out.nullable = in_schema.fields[arg].nullable;

‎crates/types/src/ir/asap.rs‎

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use serde::{Deserialize, Serialize};
77

88
use super::node::{OperatorNode, OperatorResultKind};
99
use crate::ir::operator_properties::Reduction;
10-
use crate::ir::QueryExprError;
10+
use crate::ir::SchemaDerivationError;
1111
use crate::post_asap::maintained_population::{MaintainedPopulation, PopulationStatistic};
1212
use crate::post_asap::sketch::{GroupingStrategy, SketchStatistic, SummaryUpdate};
1313
use crate::pre_asap::schema::{ColumnId, DataType, Field, FieldDataType, Schema};
@@ -194,8 +194,8 @@ impl ASAPOp {
194194
)
195195
}
196196

197-
fn unimplemented() -> QueryExprError {
198-
QueryExprError::InvalidScalarSignature(UNIMPLEMENTED_ASAP_OP.into())
197+
fn unimplemented() -> SchemaDerivationError {
198+
SchemaDerivationError::InvalidScalarSignature(UNIMPLEMENTED_ASAP_OP.into())
199199
}
200200

201201
/// The summary state this operator produces, if it produces state.
@@ -210,7 +210,7 @@ impl ASAPOp {
210210
/// planning may retain a more specific schema (evaluation column naming)
211211
/// through [`OperatorNode::with_schema`]; the derived shape agrees with it
212212
/// in field types.
213-
pub fn output_schema(&self) -> Result<Schema, QueryExprError> {
213+
pub fn output_schema(&self) -> Result<Schema, SchemaDerivationError> {
214214
use ASAPOp::*;
215215
Ok(match self {
216216
SummaryAgg {
@@ -230,7 +230,7 @@ impl ASAPOp {
230230
&crate::pre_asap::ColumnRef::SampleValue,
231231
&schema,
232232
)
233-
.map_err(|e| QueryExprError::InvalidScalarSignature(e.to_string()))?,
233+
.map_err(|e| SchemaDerivationError::InvalidScalarSignature(e.to_string()))?,
234234
Reduction::Reduce(_) => schema.fields.len() - 1,
235235
};
236236
schema.fields[index] = Field::new("state", family.clone(), false);
@@ -286,7 +286,7 @@ impl ASAPOp {
286286
&source.schema,
287287
)
288288
.map_err(|e| {
289-
QueryExprError::InvalidScalarSignature(e.to_string())
289+
SchemaDerivationError::InvalidScalarSignature(e.to_string())
290290
})?,
291291
),
292292
_ => None,
@@ -349,7 +349,7 @@ impl ASAPOp {
349349
population,
350350
}) = child.asap()
351351
else {
352-
return Err(QueryExprError::InvalidScalarSignature(
352+
return Err(SchemaDerivationError::InvalidScalarSignature(
353353
"population evaluation requires maintained membership".into(),
354354
));
355355
};
@@ -368,7 +368,7 @@ impl ASAPOp {
368368
.iter()
369369
.map(|name| {
370370
source.schema.column_id(name).ok_or_else(|| {
371-
QueryExprError::InvalidScalarSignature(
371+
SchemaDerivationError::InvalidScalarSignature(
372372
"population grouping column is absent".into(),
373373
)
374374
})
@@ -433,11 +433,11 @@ impl ASAPOp {
433433
}
434434

435435
/// Local input-contract checks.
436-
pub fn validate_inputs(&self) -> Result<(), QueryExprError> {
436+
pub fn validate_inputs(&self) -> Result<(), SchemaDerivationError> {
437437
use ASAPOp::*;
438438
let needs_state = |node: &OperatorNode, what: &str| {
439439
if node.result_kind != OperatorResultKind::State {
440-
Err(QueryExprError::InvalidScalarSignature(format!(
440+
Err(SchemaDerivationError::InvalidScalarSignature(format!(
441441
"{what} requires summary state as input, got {:?}",
442442
node.result_kind
443443
)))
@@ -480,7 +480,7 @@ impl ASAPOp {
480480
_ => false,
481481
};
482482
if !valid {
483-
return Err(QueryExprError::InvalidScalarSignature(
483+
return Err(SchemaDerivationError::InvalidScalarSignature(
484484
"evaluation does not match its summary family".into(),
485485
));
486486
}
@@ -494,7 +494,7 @@ impl ASAPOp {
494494
.iter()
495495
.all(|f| !matches!(f.dtype, FieldDataType::ExactAggregate(..)))
496496
{
497-
return Err(QueryExprError::InvalidScalarSignature(
497+
return Err(SchemaDerivationError::InvalidScalarSignature(
498498
"FinalizeExactAccumulator requires exact accumulator state".into(),
499499
));
500500
}
@@ -504,7 +504,7 @@ impl ASAPOp {
504504
needs_state(child, "EvaluatePopulation")?;
505505
if !matches!(child.asap(), Some(MaintainPopulation { population, .. }) if population.supports(evaluation))
506506
{
507-
return Err(QueryExprError::InvalidScalarSignature(
507+
return Err(SchemaDerivationError::InvalidScalarSignature(
508508
"population evaluation requires compatible maintained membership".into(),
509509
));
510510
}
@@ -518,19 +518,19 @@ impl ASAPOp {
518518
..
519519
} => {
520520
if family.is_plain() || child.result_kind == OperatorResultKind::State {
521-
return Err(QueryExprError::InvalidScalarSignature(
521+
return Err(SchemaDerivationError::InvalidScalarSignature(
522522
"summary aggregation requires values and produces a state family".into(),
523523
));
524524
}
525525
fn check(
526526
expr: &crate::post_asap::SummaryInputExpr,
527527
schema: &Schema,
528-
) -> Result<(), QueryExprError> {
528+
) -> Result<(), SchemaDerivationError> {
529529
use crate::post_asap::SummaryInputExpr;
530530
match expr {
531531
SummaryInputExpr::Column(col) => {
532532
crate::pre_asap::resolve_column_ref(col, schema).map_err(|e| {
533-
QueryExprError::InvalidScalarSignature(e.to_string())
533+
SchemaDerivationError::InvalidScalarSignature(e.to_string())
534534
})?;
535535
}
536536
SummaryInputExpr::Tuple(items) => {
@@ -548,7 +548,7 @@ impl ASAPOp {
548548
}
549549
if let Some(filter) = filter {
550550
if filter.0.scalar_type(&child.schema)?.0 != DataType::Bool {
551-
return Err(QueryExprError::InvalidScalarSignature(
551+
return Err(SchemaDerivationError::InvalidScalarSignature(
552552
"summary filter must be boolean".into(),
553553
));
554554
}
@@ -557,7 +557,7 @@ impl ASAPOp {
557557
}
558558
MaintainPopulation { child, population } => {
559559
if !population.matches_node(child) {
560-
return Err(QueryExprError::InvalidScalarSignature(
560+
return Err(SchemaDerivationError::InvalidScalarSignature(
561561
"population input differs from its membership contract".into(),
562562
));
563563
}

‎crates/types/src/ir/canonicalize.rs‎

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ use super::node::{Operator, OperatorNode};
3434
use super::non_asap::NonASAPOp;
3535
use super::scalar::{ExprSemantics, Predicate, ProjectItem, ScalarExpr, SortKey};
3636
use crate::ir::operator_properties::{JoinKind, Reduction};
37-
use crate::ir::QueryExprError;
37+
use crate::ir::SchemaDerivationError;
3838
use crate::pre_asap::agg_intent::{topk, AggIntent};
3939
use crate::pre_asap::expr_ir::{CompareOpKind, ScalarValue};
4040
use crate::types::AccuracyTarget;
@@ -44,14 +44,14 @@ use crate::types::AccuracyTarget;
4444
/// nodes that change (or whose inputs change) are rebuilt; every untouched
4545
/// sub-DAG keeps its pointer identity, and a shared sub-DAG that is rewritten
4646
/// stays shared.
47-
pub fn canonicalize(root: Rc<OperatorNode>) -> Result<Rc<OperatorNode>, QueryExprError> {
47+
pub fn canonicalize(root: Rc<OperatorNode>) -> Result<Rc<OperatorNode>, SchemaDerivationError> {
4848
canon(&root, &mut HashMap::new())
4949
}
5050

5151
fn canon(
5252
node: &Rc<OperatorNode>,
5353
memo: &mut HashMap<*const OperatorNode, Rc<OperatorNode>>,
54-
) -> Result<Rc<OperatorNode>, QueryExprError> {
54+
) -> Result<Rc<OperatorNode>, SchemaDerivationError> {
5555
if let Some(done) = memo.get(&Rc::as_ptr(node)) {
5656
return Ok(Rc::clone(done));
5757
}
@@ -135,7 +135,7 @@ type Memo = HashMap<*const OperatorNode, Rc<OperatorNode>>;
135135
fn apply_local_rules(
136136
mut current: Rc<OperatorNode>,
137137
memo: &mut Memo,
138-
) -> Result<Rc<OperatorNode>, QueryExprError> {
138+
) -> Result<Rc<OperatorNode>, SchemaDerivationError> {
139139
loop {
140140
let next = if let Some(next) = try_promote_additive_top_ranking(&current)? {
141141
next
@@ -165,7 +165,7 @@ fn operator_children(op: &Operator) -> Vec<&Rc<OperatorNode>> {
165165
/// aggregate. Returns `None` when the shape does not match.
166166
fn try_promote_additive_top_ranking(
167167
node: &OperatorNode,
168-
) -> Result<Option<Rc<OperatorNode>>, QueryExprError> {
168+
) -> Result<Option<Rc<OperatorNode>>, SchemaDerivationError> {
169169
// Limit k, no offset (an OFFSET means "not the top k").
170170
let Some(NonASAPOp::Limit {
171171
n: Some(k),
@@ -310,7 +310,7 @@ fn is_join_conjunct(conjunct: &ScalarExpr) -> bool {
310310
fn try_lower_subquery_conjunct(
311311
node: &OperatorNode,
312312
memo: &mut Memo,
313-
) -> Result<Option<Rc<OperatorNode>>, QueryExprError> {
313+
) -> Result<Option<Rc<OperatorNode>>, SchemaDerivationError> {
314314
let Some(NonASAPOp::Filter {
315315
pred: Predicate(pred),
316316
child,
@@ -382,7 +382,10 @@ fn try_lower_subquery_conjunct(
382382
/// an error when a scalar subquery yields more than one row (the cross join
383383
/// would duplicate the left's rows instead), and yields NULL when it yields
384384
/// none (the cross join yields no rows instead).
385-
fn filter(pred: ScalarExpr, child: Rc<OperatorNode>) -> Result<Rc<OperatorNode>, QueryExprError> {
385+
fn filter(
386+
pred: ScalarExpr,
387+
child: Rc<OperatorNode>,
388+
) -> Result<Rc<OperatorNode>, SchemaDerivationError> {
386389
OperatorNode::non_asap_node(NonASAPOp::Filter {
387390
pred: Predicate(pred),
388391
child,

‎crates/types/src/ir/error.rs‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
//! Typed failures from operator/scalar schema and type derivation.
22
//!
3-
//! [`QueryExprError`] distinguishes invalid scalar signatures, out-of-range
3+
//! [`SchemaDerivationError`] distinguishes invalid scalar signatures, out-of-range
44
//! grouping columns, empty concatenations, and invalid sample columns.
55
//! Structural DAG and execution-timing validation have separate error types.
66
use crate::pre_asap::ColumnId;
77
use thiserror::Error;
88
/// Errors from schema and type derivation over an operator DAG.
99
#[derive(Debug, Error)]
10-
pub enum QueryExprError {
10+
pub enum SchemaDerivationError {
1111
#[error("invalid scalar function signature: {0}")]
1212
InvalidScalarSignature(String),
1313
#[error("by-column id {0} out of range (input has {1} columns)")]

‎crates/types/src/ir/mod.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,4 @@ pub use timing::{
3434
pub mod aggregate_schema;
3535
pub mod error;
3636
pub mod operator_properties;
37-
pub use error::QueryExprError;
37+
pub use error::SchemaDerivationError;

0 commit comments

Comments
 (0)