MCPcopy Create free account
hub / github.com/apache/datafusion / coerce_plan_expr_for_schema

Function coerce_plan_expr_for_schema

datafusion/expr/src/expr_rewriter/mod.rs:221–244  ·  view source on GitHub ↗

Returns plan with expressions coerced to types compatible with schema types

(
    plan: LogicalPlan,
    schema: &DFSchema,
)

Source from the content-addressed store, hash-verified

219/// Returns plan with expressions coerced to types compatible with
220/// schema types
221pub fn coerce_plan_expr_for_schema(
222 plan: LogicalPlan,
223 schema: &DFSchema,
224) -> Result<LogicalPlan> {
225 match plan {
226 // special case Projection to avoid adding multiple projections
227 LogicalPlan::Projection(Projection { expr, input, .. }) => {
228 let new_exprs = coerce_exprs_for_schema(expr, input.schema(), schema)?;
229 let projection = Projection::try_new(new_exprs, input)?;
230 Ok(LogicalPlan::Projection(projection))
231 }
232 _ => {
233 let exprs: Vec<Expr> = plan.schema().iter().map(Expr::from).collect();
234 let new_exprs = coerce_exprs_for_schema(exprs, plan.schema(), schema)?;
235 let add_project = new_exprs.iter().any(|expr| expr.try_as_col().is_none());
236 if add_project {
237 let projection = Projection::try_new(new_exprs, Arc::new(plan))?;
238 Ok(LogicalPlan::Projection(projection))
239 } else {
240 Ok(plan)
241 }
242 }
243 }
244}
245
246fn coerce_exprs_for_schema(
247 exprs: Vec<Expr>,

Callers 5

to_recursive_queryMethod · 0.85
rewriteMethod · 0.85
coerce_outputFunction · 0.85
coerce_unionMethod · 0.85

Calls 10

coerce_exprs_for_schemaFunction · 0.85
ProjectionClass · 0.85
newFunction · 0.85
collectMethod · 0.80
is_noneMethod · 0.80
try_as_colMethod · 0.80
schemaMethod · 0.45
mapMethod · 0.45
iterMethod · 0.45
anyMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…