yyy1000 commented on code in PR #10690: URL: https://github.com/apache/datafusion/pull/10690#discussion_r1617253512
########## 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: Cool. Yeah, by running test I found sort_expr will be added to distinct_on plan, but it will not be added to sort.🤔 Do you think it's better to remove `SelectBuilder::sort_by` or keep it? -- 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