| 427 | } |
| 428 | |
| 429 | fn transform( |
| 430 | &mut self, |
| 431 | level: usize, |
| 432 | alias_name: String, |
| 433 | expr_in_unnest: &Expr, |
| 434 | struct_allowed: bool, |
| 435 | ) -> Result<Vec<Expr>> { |
| 436 | let inner_expr_name = expr_in_unnest.schema_name().to_string(); |
| 437 | |
| 438 | // Full context, we are trying to plan the execution as InnerProjection->Unnest->OuterProjection |
| 439 | // inside unnest execution, each column inside the inner projection |
| 440 | // will be transformed into new columns. Thus we need to keep track of these placeholding column names |
| 441 | let placeholder_name = format!("{UNNEST_PLACEHOLDER}({inner_expr_name})"); |
| 442 | let post_unnest_name = |
| 443 | format!("{UNNEST_PLACEHOLDER}({inner_expr_name},depth={level})"); |
| 444 | // This is due to the fact that unnest transformation should keep the original |
| 445 | // column name as is, to comply with group by and order by |
| 446 | let placeholder_column = Column::from_name(placeholder_name.clone()); |
| 447 | let field = expr_in_unnest.to_field(self.input_schema)?.1; |
| 448 | let data_type = field.data_type(); |
| 449 | |
| 450 | match data_type { |
| 451 | DataType::Struct(inner_fields) => { |
| 452 | assert_or_internal_err!( |
| 453 | struct_allowed, |
| 454 | "unnest on struct can only be applied at the root level of select expression" |
| 455 | ); |
| 456 | push_projection_dedupl( |
| 457 | self.inner_projection_exprs, |
| 458 | expr_in_unnest.clone().alias(placeholder_name.clone()), |
| 459 | ); |
| 460 | self.columns_unnestings |
| 461 | .insert(Column::from_name(placeholder_name.clone()), None); |
| 462 | Ok(get_struct_unnested_columns(&placeholder_name, inner_fields) |
| 463 | .into_iter() |
| 464 | .map(Expr::Column) |
| 465 | .collect()) |
| 466 | } |
| 467 | DataType::List(_) |
| 468 | | DataType::FixedSizeList(_, _) |
| 469 | | DataType::LargeList(_) |
| 470 | | DataType::ListView(_) |
| 471 | | DataType::LargeListView(_) => { |
| 472 | push_projection_dedupl( |
| 473 | self.inner_projection_exprs, |
| 474 | expr_in_unnest.clone().alias(placeholder_name.clone()), |
| 475 | ); |
| 476 | |
| 477 | let post_unnest_expr = col(post_unnest_name.clone()).alias(alias_name); |
| 478 | let list_unnesting = self |
| 479 | .columns_unnestings |
| 480 | .entry(placeholder_column) |
| 481 | .or_insert(Some(vec![])); |
| 482 | let unnesting = ColumnUnnestList { |
| 483 | output_column: Column::from_name(post_unnest_name), |
| 484 | depth: level, |
| 485 | }; |
| 486 | let list_unnestings = list_unnesting.as_mut().unwrap(); |