Skip to content

Commit da634a2

Browse files
committed
implement unnest
1 parent a17bbb8 commit da634a2

File tree

1 file changed

+22
-4
lines changed

1 file changed

+22
-4
lines changed

datafusion/expr/src/logical_plan/mutate.rs

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ use super::plan::*;
1919
use crate::expr::{Exists, InSubquery};
2020
use crate::Expr;
2121
use datafusion_common::tree_node::Transformed;
22-
use datafusion_common::Result;
23-
use datafusion_common::{DFSchema, DFSchemaRef};
22+
use datafusion_common::{internal_err, Result};
23+
use datafusion_common::{Column, DFSchema, DFSchemaRef};
2424
use std::cell::OnceCell;
2525
use std::sync::Arc;
2626

@@ -106,8 +106,26 @@ impl LogicalPlan {
106106
rewrite_expr_iter_mut(filters.iter_mut(), f)
107107
}
108108
LogicalPlan::Unnest(Unnest { column, .. }) => {
109-
//f(&Expr::Column(column.clone()))
110-
todo!();
109+
// Unnest doesn't have an Expr to visit, so need to make one
110+
// pick a literal here that is clear it didn't come from
111+
// user query and is easy to grep and find in the source code
112+
// it would be really nice to avoid this and instead have unnest have Expr
113+
114+
let mut swap_column = Column::new_unqualified("TEMP_unnest_column");
115+
std::mem::swap(column, &mut swap_column);
116+
117+
let mut expr = Expr::Column(swap_column);
118+
let result = f(&mut expr)?;
119+
// put the column back
120+
let Expr::Column(mut swap_column) = expr else {
121+
return internal_err!(
122+
"Rewrite of Unnest expr must return Column, returned {:?}",
123+
expr
124+
);
125+
};
126+
// put the rewritten column back
127+
std::mem::swap(column, &mut swap_column);
128+
Ok(result)
111129
}
112130
LogicalPlan::Distinct(Distinct::On(DistinctOn {
113131
on_expr,

0 commit comments

Comments
 (0)