Recursively walk an expression tree, collecting the unique set of columns referenced in the expression
(expr: &Expr, accum: &mut HashSet<Column>)
| 274 | /// Recursively walk an expression tree, collecting the unique set of columns |
| 275 | /// referenced in the expression |
| 276 | pub fn expr_to_columns(expr: &Expr, accum: &mut HashSet<Column>) -> Result<()> { |
| 277 | expr.apply(|expr| { |
| 278 | match expr { |
| 279 | Expr::Column(qc) => { |
| 280 | accum.insert(qc.clone()); |
| 281 | } |
| 282 | // Use explicit pattern match instead of a default |
| 283 | // implementation, so that in the future if someone adds |
| 284 | // new Expr types, they will check here as well |
| 285 | // TODO: remove the next line after `Expr::Wildcard` is removed |
| 286 | #[expect(deprecated)] |
| 287 | Expr::Unnest(_) |
| 288 | | Expr::ScalarVariable(_, _) |
| 289 | | Expr::Alias(_) |
| 290 | | Expr::Literal(_, _) |
| 291 | | Expr::BinaryExpr { .. } |
| 292 | | Expr::Like { .. } |
| 293 | | Expr::SimilarTo { .. } |
| 294 | | Expr::Not(_) |
| 295 | | Expr::IsNotNull(_) |
| 296 | | Expr::IsNull(_) |
| 297 | | Expr::IsTrue(_) |
| 298 | | Expr::IsFalse(_) |
| 299 | | Expr::IsUnknown(_) |
| 300 | | Expr::IsNotTrue(_) |
| 301 | | Expr::IsNotFalse(_) |
| 302 | | Expr::IsNotUnknown(_) |
| 303 | | Expr::Negative(_) |
| 304 | | Expr::Between { .. } |
| 305 | | Expr::Case { .. } |
| 306 | | Expr::Cast { .. } |
| 307 | | Expr::TryCast { .. } |
| 308 | | Expr::ScalarFunction(..) |
| 309 | | Expr::WindowFunction { .. } |
| 310 | | Expr::AggregateFunction { .. } |
| 311 | | Expr::GroupingSet(_) |
| 312 | | Expr::InList { .. } |
| 313 | | Expr::Exists { .. } |
| 314 | | Expr::InSubquery(_) |
| 315 | | Expr::SetComparison(_) |
| 316 | | Expr::ScalarSubquery(_) |
| 317 | | Expr::Wildcard { .. } |
| 318 | | Expr::Placeholder(_) |
| 319 | | Expr::OuterReferenceColumn { .. } |
| 320 | | Expr::HigherOrderFunction(_) |
| 321 | | Expr::Lambda(_) |
| 322 | | Expr::LambdaVariable(_) => {} |
| 323 | } |
| 324 | Ok(TreeNodeRecursion::Continue) |
| 325 | }) |
| 326 | .map(|_| ()) |
| 327 | } |
| 328 | |
| 329 | /// Find excluded columns in the schema, if any |
| 330 | /// SELECT * EXCLUDE(col1, col2), would return `vec![col1, col2]` |
searching dependent graphs…