jayzhan211 commented on code in PR #11577: URL: https://github.com/apache/datafusion/pull/11577#discussion_r1774868527
########## datafusion/sql/src/utils.rs: ########## @@ -309,6 +315,269 @@ pub(crate) fn transform_bottom_unnests( .collect::<Vec<_>>()) } +/* +This is only usedful when used with transform down up +A full example of how the transformation works: + */ +struct RecursiveUnnestRewriter<'a> { + input_schema: &'a DFSchemaRef, + root_expr: &'a Expr, + // useful to detect which child expr is a part of/ not a part of unnest operation + top_most_unnest: Option<Unnest>, + consecutive_unnest: Vec<Option<Unnest>>, + inner_projection_exprs: &'a mut Vec<Expr>, + columns_unnestings: &'a mut Vec<(Column, ColumnUnnestType)>, + transformed_root_exprs: Option<Vec<Expr>>, +} +impl<'a> RecursiveUnnestRewriter<'a> { + /// This struct stores the history of expr + /// during its tree-traversal with a notation of + /// \[None,**Unnest(exprA)**,**Unnest(exprB)**,None,None\] + /// then this function will returns \[**Unnest(exprA)**,**Unnest(exprB)**\] + /// + /// The first item will be the inner most expr + fn get_latest_consecutive_unnest(&self) -> Vec<Unnest> { + self.consecutive_unnest + .iter() + .rev() + .skip_while(|item| item.is_none()) + .take_while(|item| item.is_some()) + .to_owned() + .cloned() + .map(|item| item.unwrap()) + .collect() + } + + fn transform( + &mut self, + level: usize, + alias_name: String, + expr_in_unnest: &Expr, + struct_allowed: bool, + ) -> Result<Vec<Expr>> { + let inner_expr_name = expr_in_unnest.schema_name().to_string(); + + // Full context, we are trying to plan the execution as InnerProjection->Unnest->OuterProjection + // inside unnest execution, each column inside the inner projection + // will be transformed into new columns. Thus we need to keep track of these placeholding column names + // let placeholder_name = unnest_expr.display_name()?; Review Comment: seems like leftover -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: github-unsubscr...@datafusion.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: github-unsubscr...@datafusion.apache.org For additional commands, e-mail: github-h...@datafusion.apache.org