jayzhan211 commented on code in PR #11273:
URL: https://github.com/apache/datafusion/pull/11273#discussion_r1667833085
##########
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.
Right, they are not possible to move into the planner. Another thing we can
improve on is, forgetting about `create_struct_expr` and use
`create_named_struct_expr` and `named_struct`. But, we can change this in next
PR
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]