yyy1000 commented on code in PR #10690: URL: https://github.com/apache/datafusion/pull/10690#discussion_r1616570923
########## datafusion/sql/src/unparser/plan.rs: ########## @@ -271,8 +273,39 @@ impl Unparser<'_> { relation, ) } - LogicalPlan::Distinct(_distinct) => { - not_impl_err!("Unsupported operator: {plan:?}") + LogicalPlan::Distinct(distinct) => { + let (select_distinct, input) = match distinct { + Distinct::All(input) => (ast::Distinct::Distinct, input.as_ref()), + Distinct::On(on) => { + let exprs = on + .on_expr + .iter() + .map(|e| self.expr_to_sql(e)) + .collect::<Result<Vec<_>>>()?; + let items = on + .select_expr + .iter() + .map(|e| self.select_item_to_sql(e)) + .collect::<Result<Vec<_>>>()?; + match &on.sort_expr { + Some(sort_expr) => { + if let Some(query_ref) = query { + query_ref + .order_by(self.sort_to_sql(sort_expr.clone())?); + } else { + return internal_err!( + "Sort operator only valid in a statement context." + ); Review Comment: When implementing order by in a distinct on. I found the order by should be added to `query` instead of `select`. So my question is, what's the usage of `sort_by` in `SelectBuilder`? I searched the code but not found an usage. 🤔 -- 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