gruuya commented on code in PR #10690: URL: https://github.com/apache/datafusion/pull/10690#discussion_r1617278601
########## 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: > Do you think it's better to remove `SelectBuilder::sort_by` or keep it? If you're asking me I think it's fine to keep it (though other projects wouldn't be using it as well since `SelectBuilder` is `pub(super)`, so it wouldn't hurt to remove it either). -- 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