Function datafusion::sql::sqlparser::ast::visit_expressions

source ·
pub fn visit_expressions<V, E, F>(v: &V, f: F) -> ControlFlow<E>
where V: Visit, F: FnMut(&Expr) -> ControlFlow<E>,
Expand description

Invokes the provided closure on all expressions (e.g. 1 + 2) present in v

§Example

let sql = "SELECT a FROM foo where x IN (SELECT y FROM bar)";
let statements = Parser::parse_sql(&GenericDialect{}, sql)
   .unwrap();

// visit all expressions
let mut visited = vec![];
visit_expressions(&statements, |expr| {
  visited.push(format!("EXPR: {}", expr));
  ControlFlow::<()>::Continue(())
});

let expected : Vec<_> = [
  "EXPR: a",
  "EXPR: x IN (SELECT y FROM bar)",
  "EXPR: x",
  "EXPR: y",
]
  .into_iter().map(|s| s.to_string()).collect();

assert_eq!(visited, expected);