MCPcopy Create free account
hub / github.com/MaterializeInc/materialize / extract_non_errors_from_expr_ref_mut

Method extract_non_errors_from_expr_ref_mut

src/expr/src/linear.rs:324–362  ·  view source on GitHub ↗

Extracts an error-free MapFilterProject at the root of the expression. Differs from [MapFilterProject::extract_non_errors_from_expr] by taking and returning a mutable reference.

(
        expr: &mut MirRelationExpr,
    )

Source from the content-addressed store, hash-verified

322 /// Differs from [MapFilterProject::extract_non_errors_from_expr] by taking and returning a
323 /// mutable reference.
324 pub fn extract_non_errors_from_expr_ref_mut(
325 expr: &mut MirRelationExpr,
326 ) -> (Self, &mut MirRelationExpr) {
327 // This is essentially the same code as `extract_non_errors_from_expr`, except the seemingly
328 // superfluous outer if, which works around a borrow-checker issue:
329 // https://github.com/rust-lang/rust/issues/54663
330 if matches!(
331 expr,
332 MirRelationExpr::Map { input: _, scalars }
333 if scalars.iter().all(|s| !s.is_literal_err())
334 ) || matches!(
335 expr,
336 MirRelationExpr::Filter { input: _, predicates }
337 if predicates.iter().all(|p| !p.is_literal_err())
338 ) || matches!(expr, MirRelationExpr::Project { .. })
339 {
340 match expr {
341 MirRelationExpr::Map { input, scalars }
342 if scalars.iter().all(|s| !s.is_literal_err()) =>
343 {
344 let (mfp, expr) = Self::extract_non_errors_from_expr_ref_mut(input);
345 (mfp.map(scalars.iter().cloned()), expr)
346 }
347 MirRelationExpr::Filter { input, predicates }
348 if predicates.iter().all(|p| !p.is_literal_err()) =>
349 {
350 let (mfp, expr) = Self::extract_non_errors_from_expr_ref_mut(input);
351 (mfp.filter(predicates.iter().cloned()), expr)
352 }
353 MirRelationExpr::Project { input, outputs } => {
354 let (mfp, expr) = Self::extract_non_errors_from_expr_ref_mut(input);
355 (mfp.project(outputs.iter().cloned()), expr)
356 }
357 _ => unreachable!(),
358 }
359 } else {
360 (Self::new(expr.arity()), expr)
361 }
362 }
363
364 /// Removes an error-free MapFilterProject from the root of the expression.
365 ///

Callers

nothing calls this directly

Calls 7

allMethod · 0.80
iterMethod · 0.45
is_literal_errMethod · 0.45
mapMethod · 0.45
filterMethod · 0.45
projectMethod · 0.45
arityMethod · 0.45

Tested by

no test coverage detected