MCPcopy Create free account
hub / github.com/clockworklabs/SpacetimeDB / expand_leaf

Function expand_leaf

crates/expr/src/rls.rs:448–472  ·  view source on GitHub ↗

Replaces the leaf node determined by `table_id` and `alias` with the subtree `with`. Ensures the expanded tree stays left deep.

(expr: RelExpr, table_id: TableId, alias: &str, with: &RelExpr)

Source from the content-addressed store, hash-verified

446/// Replaces the leaf node determined by `table_id` and `alias` with the subtree `with`.
447/// Ensures the expanded tree stays left deep.
448fn expand_leaf(expr: RelExpr, table_id: TableId, alias: &str, with: &RelExpr) -> RelExpr {
449 let ok = |relvar: &Relvar| relvar.schema.table_id == table_id && relvar.alias.as_ref() == alias;
450 match expr {
451 RelExpr::RelVar(relvar, ..) if ok(&relvar) => with.clone(),
452 RelExpr::RelVar(..) => expr,
453 RelExpr::Select(input, expr) => RelExpr::Select(Box::new(expand_leaf(*input, table_id, alias, with)), expr),
454 RelExpr::LeftDeepJoin(join) if ok(&join.rhs) => extend_lhs(with.clone(), *join.lhs),
455 RelExpr::LeftDeepJoin(LeftDeepJoin { lhs, rhs }) => RelExpr::LeftDeepJoin(LeftDeepJoin {
456 lhs: Box::new(expand_leaf(*lhs, table_id, alias, with)),
457 rhs,
458 }),
459 RelExpr::EqJoin(join, a, b) if ok(&join.rhs) => RelExpr::Select(
460 Box::new(extend_lhs(with.clone(), *join.lhs)),
461 Expr::BinOp(BinOp::Eq, Box::new(Expr::Field(a)), Box::new(Expr::Field(b))),
462 ),
463 RelExpr::EqJoin(LeftDeepJoin { lhs, rhs }, a, b) => RelExpr::EqJoin(
464 LeftDeepJoin {
465 lhs: Box::new(expand_leaf(*lhs, table_id, alias, with)),
466 rhs,
467 },
468 a,
469 b,
470 ),
471 }
472}
473
474#[cfg(test)]
475mod tests {

Callers 1

expand_viewsFunction · 0.85

Calls 6

extend_lhsFunction · 0.85
LeftDeepJoinClass · 0.85
BinOpEnum · 0.85
newFunction · 0.50
as_refMethod · 0.45
cloneMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…