dharanad commented on code in PR #11273: URL: https://github.com/apache/datafusion/pull/11273#discussion_r1667764545
########## datafusion/sql/src/expr/mod.rs: ########## @@ -629,6 +630,36 @@ impl<'a, S: ContextProvider> SqlToRel<'a, S> { } } + /// Parses a struct(..) expression and plans it creation + fn parse_struct( + &self, + schema: &DFSchema, + planner_context: &mut PlannerContext, + values: Vec<sqlparser::ast::Expr>, + fields: Vec<StructField>, + ) -> Result<Expr> { + if !fields.is_empty() { + return not_impl_err!("Struct fields are not supported yet"); + } + let is_named_struct = values + .iter() + .any(|value| matches!(value, SQLExpr::Named { .. })); + + let mut create_struct_args = if is_named_struct { + self.create_named_struct_expr(values, schema, planner_context)? + } else { + self.create_struct_expr(values, schema, planner_context)? + }; + + for planner in self.planners.iter() { + match planner.plan_struct_literal(create_struct_args, is_named_struct)? { + PlannerResult::Planned(expr) => return Ok(expr), + PlannerResult::Original(args) => create_struct_args = args, + } + } Review Comment: > Can we have one StructPlan that returns `struct` or `named_struct` based on the values? > > ```rust > let mut create_struct_args = if is_named_struct { > self.create_named_struct_expr(values, schema, planner_context)? > } else { > self.create_struct_expr(values, schema, planner_context)? > }; > ``` > > The logic here should be inside planner @jayzhan211 Is this what u suggesting ? If you were suggesting to move `create_struct_expr` & `create_named_struct_expr` to planner. I see an issues over there i.e these functions intnerally call `self.sql_expr_to_logical_expr`. I would rather have it here to keep it simple. Sorry if i understood it wrong. -- 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