Cast subquery in InSubquery/ScalarSubquery to a given type. 1. **Projection plan**: If the subquery is a projection (i.e. a SELECT statement with specific columns), it casts the first expression in the projection to the target type and creates a new projection with the casted expression. 2. **Non-projection plan**: If the subquery isn't a projection, it adds a projection to the plan with the cast
(subquery: Subquery, cast_to_type: &DataType)
| 760 | /// 2. **Non-projection plan**: If the subquery isn't a projection, it adds a projection to the plan |
| 761 | /// with the casted first column. |
| 762 | pub fn cast_subquery(subquery: Subquery, cast_to_type: &DataType) -> Result<Subquery> { |
| 763 | if subquery.subquery.schema().field(0).data_type() == cast_to_type { |
| 764 | return Ok(subquery); |
| 765 | } |
| 766 | |
| 767 | let plan = subquery.subquery.as_ref(); |
| 768 | let new_plan = match plan { |
| 769 | LogicalPlan::Projection(projection) => { |
| 770 | let cast_expr = projection.expr[0] |
| 771 | .clone() |
| 772 | .cast_to(cast_to_type, projection.input.schema())?; |
| 773 | LogicalPlan::Projection(Projection::try_new( |
| 774 | vec![cast_expr], |
| 775 | Arc::clone(&projection.input), |
| 776 | )?) |
| 777 | } |
| 778 | _ => { |
| 779 | let cast_expr = Expr::Column(Column::from(plan.schema().qualified_field(0))) |
| 780 | .cast_to(cast_to_type, subquery.subquery.schema())?; |
| 781 | LogicalPlan::Projection(Projection::try_new( |
| 782 | vec![cast_expr], |
| 783 | subquery.subquery, |
| 784 | )?) |
| 785 | } |
| 786 | }; |
| 787 | Ok(Subquery { |
| 788 | subquery: Arc::new(new_plan), |
| 789 | outer_ref_columns: subquery.outer_ref_columns, |
| 790 | spans: Spans::new(), |
| 791 | }) |
| 792 | } |
| 793 | |
| 794 | #[cfg(test)] |
| 795 | mod tests { |
no test coverage detected
searching dependent graphs…