Recursively identify Column expressions and transform them into the appropriate unnest expression For example, if expr contains the column expr "__unnest_placeholder(make_array(Int64(1),Int64(2),Int64(2),Int64(5),NULL),depth=1)" it will be transformed into an actual unnest expression UNNEST([1, 2, 2, 5, NULL])
(expr: Expr, unnest: &Unnest)
| 166 | /// For example, if expr contains the column expr "__unnest_placeholder(make_array(Int64(1),Int64(2),Int64(2),Int64(5),NULL),depth=1)" |
| 167 | /// it will be transformed into an actual unnest expression UNNEST([1, 2, 2, 5, NULL]) |
| 168 | pub(crate) fn unproject_unnest_expr(expr: Expr, unnest: &Unnest) -> Result<Expr> { |
| 169 | expr.transform(|sub_expr| { |
| 170 | if let Expr::Column(col_ref) = &sub_expr { |
| 171 | // Check if the column is among the columns to run unnest on. |
| 172 | // Currently, only List/Array columns (defined in `list_type_columns`) are supported for unnesting. |
| 173 | if unnest.list_type_columns.iter().any(|e| e.1.output_column.name == col_ref.name) { |
| 174 | if let Ok(idx) = unnest.schema.index_of_column(col_ref) |
| 175 | && let LogicalPlan::Projection(Projection { expr, .. }) = unnest.input.as_ref() |
| 176 | && let Some(unprojected_expr) = expr.get(idx) { |
| 177 | let unnest_expr = Expr::Unnest(expr::Unnest::new(unprojected_expr.clone())); |
| 178 | return Ok(Transformed::yes(unnest_expr)); |
| 179 | } |
| 180 | return internal_err!( |
| 181 | "Tried to unproject unnest expr for column '{}' that was not found in the provided Unnest!", &col_ref.name |
| 182 | ); |
| 183 | } |
| 184 | } |
| 185 | |
| 186 | Ok(Transformed::no(sub_expr)) |
| 187 | |
| 188 | }).map(|e| e.data) |
| 189 | } |
| 190 | |
| 191 | /// Like `unproject_unnest_expr`, but for Snowflake FLATTEN: |
| 192 | /// transforms `__unnest_placeholder(...)` column references into |
no test coverage detected
searching dependent graphs…