(
exprs: Vec<Expr>,
src_schema: &DFSchema,
dst_schema: &DFSchema,
)
| 244 | } |
| 245 | |
| 246 | fn coerce_exprs_for_schema( |
| 247 | exprs: Vec<Expr>, |
| 248 | src_schema: &DFSchema, |
| 249 | dst_schema: &DFSchema, |
| 250 | ) -> Result<Vec<Expr>> { |
| 251 | exprs |
| 252 | .into_iter() |
| 253 | .enumerate() |
| 254 | .map(|(idx, expr)| { |
| 255 | let new_type = dst_schema.field(idx).data_type(); |
| 256 | if new_type != &expr.get_type(src_schema)? { |
| 257 | match expr { |
| 258 | Expr::Alias(Alias { expr, name, .. }) => { |
| 259 | Ok(expr.cast_to(new_type, src_schema)?.alias(name)) |
| 260 | } |
| 261 | #[expect(deprecated)] |
| 262 | Expr::Wildcard { .. } => Ok(expr), |
| 263 | _ => { |
| 264 | match expr { |
| 265 | // maintain the original name when casting a column, to avoid the |
| 266 | // tablename being added to it when not explicitly set by the query |
| 267 | // (see: https://github.com/apache/datafusion/issues/18818) |
| 268 | Expr::Column(ref column) => { |
| 269 | let name = column.name().to_owned(); |
| 270 | Ok(expr.cast_to(new_type, src_schema)?.alias(name)) |
| 271 | } |
| 272 | _ => Ok(expr.cast_to(new_type, src_schema)?), |
| 273 | } |
| 274 | } |
| 275 | } |
| 276 | } else { |
| 277 | Ok(expr) |
| 278 | } |
| 279 | }) |
| 280 | .collect::<Result<_>>() |
| 281 | } |
| 282 | |
| 283 | /// Recursively un-alias an expressions |
| 284 | #[inline] |
no test coverage detected
searching dependent graphs…