MCPcopy Create free account
hub / github.com/apache/datafusion / expr_to_columns

Function expr_to_columns

datafusion/expr/src/utils.rs:276–327  ·  view source on GitHub ↗

Recursively walk an expression tree, collecting the unique set of columns referenced in the expression

(expr: &Expr, accum: &mut HashSet<Column>)

Source from the content-addressed store, hash-verified

274/// Recursively walk an expression tree, collecting the unique set of columns
275/// referenced in the expression
276pub 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]`

Callers 9

test_collect_exprFunction · 0.85
join_with_expr_keysMethod · 0.85
plan_selectionMethod · 0.85
delete_to_planMethod · 0.85
update_to_planMethod · 0.85
join_keys_may_be_nullFunction · 0.85
build_joinFunction · 0.85
rewriteMethod · 0.85

Calls 4

mapMethod · 0.45
applyMethod · 0.45
insertMethod · 0.45
cloneMethod · 0.45

Tested by 1

test_collect_exprFunction · 0.68

Used in the wild real call sites across dependent graphs

searching dependent graphs…