Returns plan with expressions coerced to types compatible with schema types
(
plan: LogicalPlan,
schema: &DFSchema,
)
| 219 | /// Returns plan with expressions coerced to types compatible with |
| 220 | /// schema types |
| 221 | pub 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 | |
| 246 | fn coerce_exprs_for_schema( |
| 247 | exprs: Vec<Expr>, |
no test coverage detected
searching dependent graphs…