fn rewrite_expr(expr: Expr, input: &Projection) -> Result<Transformed<Expr>>Expand description
Rewrites a projection expression using the projection before it (i.e. its input)
This is a subroutine to the merge_consecutive_projections function.
§Parameters
expr- A reference to the expression to rewrite.input- A reference to the input of the projection expression (itself a projection).
§Returns
A Result object with the following semantics:
Ok(Some(Expr)): Rewrite was successful. Contains the rewritten result.Ok(None): Signals thatexprcan not be rewritten.Err(error): An error occurred during the function call.
§Notes
This rewrite also removes any unnecessary layers of aliasing. “Unnecessary” is defined as not contributing new information, such as metadata.
Without trimming, we can end up with unnecessary indirections inside expressions during projection merges.
Consider:
Projection(a1 + b1 as sum1)
--Projection(a as a1, b as b1)
----Source(a, b)After merge, we want to produce:
Projection(a + b as sum1)
--Source(a, b)Without trimming, we would end up with:
Projection((a as a1 + b as b1) as sum1)
--Source(a, b)