docteurklein commented on issue #1475:
URL:
https://github.com/apache/datafusion-sqlparser-rs/issues/1475#issuecomment-2613924635
here is an example to change ASC to DESC in some order by:
```rust
struct VisitOrderBy {
reorder: Vec<String>,
}
impl VisitorMut for VisitOrderBy {
type Break = ();
fn post_visit_query(&mut self, expr: &mut Query) ->
ControlFlow<Self::Break> {
if let Query { order_by: Some(o), ..} = expr {
o.exprs.iter_mut().for_each(|e| {
if let Expr::Identifier(Ident {value: v, ..}) =
e.expr.to_owned() {
if self.reorder.contains(&v) {
e.asc = e.asc.map(|a| !a);
}
}
});
}
ControlFlow::Continue(())
}
}
let mut statements = Parser::parse_sql(&GenericDialect{},
&query.sql).unwrap();
statements.visit(&mut VisitOrderBy {reorder: query.reorder.clone()});
```
dunno if that helps!
--
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]