MCPcopy Create free account
hub / github.com/apache/datafusion / unproject_unnest_expr

Function unproject_unnest_expr

datafusion/sql/src/unparser/utils.rs:168–189  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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])
168pub(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

Callers 1

Calls 10

newFunction · 0.85
index_of_columnMethod · 0.80
UnnestClass · 0.50
mapMethod · 0.45
transformMethod · 0.45
anyMethod · 0.45
iterMethod · 0.45
as_refMethod · 0.45
getMethod · 0.45
cloneMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…