Wrap a plan in a projection
(
&self,
input: LogicalPlan,
expr: Vec<SelectExpr>,
set_expr_left_schema: Option<DFSchemaRef>,
)
| 951 | |
| 952 | /// Wrap a plan in a projection |
| 953 | pub(crate) fn project( |
| 954 | &self, |
| 955 | input: LogicalPlan, |
| 956 | expr: Vec<SelectExpr>, |
| 957 | set_expr_left_schema: Option<DFSchemaRef>, |
| 958 | ) -> Result<LogicalPlan> { |
| 959 | // convert to Expr for validate_schema_satisfies_exprs |
| 960 | let plain_exprs = expr |
| 961 | .iter() |
| 962 | .filter_map(|e| match e { |
| 963 | SelectExpr::Expression(expr) => Some(expr.to_owned()), |
| 964 | _ => None, |
| 965 | }) |
| 966 | .collect::<Vec<_>>(); |
| 967 | self.validate_schema_satisfies_exprs(input.schema(), &plain_exprs)?; |
| 968 | |
| 969 | // When inside a set expression, pass the left-most schema so |
| 970 | // that expressions get aliased to match, avoiding duplicate |
| 971 | // name errors from expressions like `count(*), count(*)`. |
| 972 | let builder = LogicalPlanBuilder::from(input); |
| 973 | if let Some(left_schema) = set_expr_left_schema { |
| 974 | builder |
| 975 | .project_with_validation_and_schema(expr, &left_schema)? |
| 976 | .build() |
| 977 | } else { |
| 978 | builder.project(expr)?.build() |
| 979 | } |
| 980 | } |
| 981 | |
| 982 | /// Create an aggregate plan. |
| 983 | /// |