Skip to content

Commit f7a7155

Browse files
committed
rename
1 parent e0b5e57 commit f7a7155

File tree

7 files changed

+68
-34
lines changed

7 files changed

+68
-34
lines changed

datafusion/expr-common/src/placement.rs

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,22 +29,26 @@ pub enum ExpressionPlacement {
2929
Column,
3030
/// A cheap expression that can be pushed to leaf nodes in the plan.
3131
/// Examples include `get_field` for struct field access.
32-
PlaceAtLeaves,
33-
/// An expensive expression that should stay at the root of the plan.
34-
/// This is the default for most expressions.
35-
PlaceAtRoot,
32+
/// Pushing these expressions down in the plan can reduce data early
33+
/// at low compute cost.
34+
/// See [`ExpressionPlacement::should_push_to_leaves`] for details.
35+
MoveTowardsLeafNodes,
36+
/// An expensive expression that should stay where it is in the plan
37+
/// or possibly be moved closer to the root nodes (this is not implemented yet).
38+
/// Examples include complex scalar functions or UDFs.
39+
MoveTowardsRootNodes,
3640
}
3741

3842
impl ExpressionPlacement {
3943
/// Returns true if the expression can be pushed down to leaf nodes
4044
/// in the query plan.
4145
///
4246
/// This returns true for:
43-
/// - `Column`: Simple column references can be pushed down. They do no compute and do not increase or
47+
/// - [`ExpressionPlacement::Column`]: Simple column references can be pushed down. They do no compute and do not increase or
4448
/// decrease the amount of data being processed.
4549
/// A projection that reduces the number of columns can eliminate unnecessary data early,
4650
/// but this method only considers one expression at a time, not a projection as a whole.
47-
/// - `PlaceAtLeaves`: Cheap expressions can be pushed down to leaves to take advantage of
51+
/// - [`ExpressionPlacement::MoveTowardsLeafNodes`]: Cheap expressions can be pushed down to leaves to take advantage of
4852
/// early computation and potential optimizations at the data source level.
4953
/// For example `struct_col['field']` is cheap to compute (just an Arc clone of the nested array for `'field'`)
5054
/// and thus can reduce data early in the plan at very low compute cost.
@@ -53,7 +57,7 @@ impl ExpressionPlacement {
5357
pub fn should_push_to_leaves(&self) -> bool {
5458
matches!(
5559
self,
56-
ExpressionPlacement::Column | ExpressionPlacement::PlaceAtLeaves
60+
ExpressionPlacement::Column | ExpressionPlacement::MoveTowardsLeafNodes
5761
)
5862
}
5963
}

datafusion/expr/src/expr.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1550,7 +1550,7 @@ impl Expr {
15501550
func.args.iter().map(|arg| arg.placement()).collect();
15511551
func.func.placement(&arg_placements)
15521552
}
1553-
_ => ExpressionPlacement::PlaceAtRoot,
1553+
_ => ExpressionPlacement::MoveTowardsRootNodes,
15541554
}
15551555
}
15561556

datafusion/expr/src/udf.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -978,13 +978,13 @@ pub trait ScalarUDFImpl: Debug + DynEq + DynHash + Send + Sync {
978978
/// This is used by optimizers to make decisions about expression placement,
979979
/// such as whether to push expressions down through projections.
980980
///
981-
/// The default implementation returns [`ExpressionPlacement::PlaceAtRoot`],
981+
/// The default implementation returns [`ExpressionPlacement::MoveTowardsRootNodes`],
982982
/// meaning the expression should stay at the root of the plan.
983983
///
984984
/// Override this method to indicate that the function can be pushed down
985985
/// closer to the data source.
986986
fn placement(&self, _args: &[ExpressionPlacement]) -> ExpressionPlacement {
987-
ExpressionPlacement::PlaceAtRoot
987+
ExpressionPlacement::MoveTowardsRootNodes
988988
}
989989
}
990990

datafusion/functions/src/core/getfield.rs

Lines changed: 49 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -505,13 +505,13 @@ impl ScalarUDFImpl for GetFieldFunc {
505505
// 1. The base (first arg) is a column or already placeable at leaves
506506
// 2. All field keys (remaining args) are literals
507507
if args.is_empty() {
508-
return ExpressionPlacement::PlaceAtRoot;
508+
return ExpressionPlacement::MoveTowardsRootNodes;
509509
}
510510

511511
let base_placement = args[0];
512512
let base_is_pushable = matches!(
513513
base_placement,
514-
ExpressionPlacement::Column | ExpressionPlacement::PlaceAtLeaves
514+
ExpressionPlacement::Column | ExpressionPlacement::MoveTowardsLeafNodes
515515
);
516516

517517
let all_keys_are_literals = args
@@ -520,9 +520,9 @@ impl ScalarUDFImpl for GetFieldFunc {
520520
.all(|p| matches!(p, ExpressionPlacement::Literal));
521521

522522
if base_is_pushable && all_keys_are_literals {
523-
ExpressionPlacement::PlaceAtLeaves
523+
ExpressionPlacement::MoveTowardsLeafNodes
524524
} else {
525-
ExpressionPlacement::PlaceAtRoot
525+
ExpressionPlacement::MoveTowardsRootNodes
526526
}
527527
}
528528
}
@@ -575,22 +575,31 @@ mod tests {
575575

576576
// get_field(col, 'literal') -> leaf-pushable (static field access)
577577
let args = vec![ExpressionPlacement::Column, ExpressionPlacement::Literal];
578-
assert_eq!(func.placement(&args), ExpressionPlacement::PlaceAtLeaves);
578+
assert_eq!(
579+
func.placement(&args),
580+
ExpressionPlacement::MoveTowardsLeafNodes
581+
);
579582

580583
// get_field(col, 'a', 'b') -> leaf-pushable (nested static field access)
581584
let args = vec![
582585
ExpressionPlacement::Column,
583586
ExpressionPlacement::Literal,
584587
ExpressionPlacement::Literal,
585588
];
586-
assert_eq!(func.placement(&args), ExpressionPlacement::PlaceAtLeaves);
589+
assert_eq!(
590+
func.placement(&args),
591+
ExpressionPlacement::MoveTowardsLeafNodes
592+
);
587593

588-
// get_field(get_field(col, 'a'), 'b') represented as PlaceAtLeaves for base
594+
// get_field(get_field(col, 'a'), 'b') represented as MoveTowardsLeafNodes for base
589595
let args = vec![
590-
ExpressionPlacement::PlaceAtLeaves,
596+
ExpressionPlacement::MoveTowardsLeafNodes,
591597
ExpressionPlacement::Literal,
592598
];
593-
assert_eq!(func.placement(&args), ExpressionPlacement::PlaceAtLeaves);
599+
assert_eq!(
600+
func.placement(&args),
601+
ExpressionPlacement::MoveTowardsLeafNodes
602+
);
594603
}
595604

596605
#[test]
@@ -599,15 +608,21 @@ mod tests {
599608

600609
// get_field(col, other_col) -> NOT leaf-pushable (dynamic per-row lookup)
601610
let args = vec![ExpressionPlacement::Column, ExpressionPlacement::Column];
602-
assert_eq!(func.placement(&args), ExpressionPlacement::PlaceAtRoot);
611+
assert_eq!(
612+
func.placement(&args),
613+
ExpressionPlacement::MoveTowardsRootNodes
614+
);
603615

604616
// get_field(col, 'a', other_col) -> NOT leaf-pushable (dynamic nested lookup)
605617
let args = vec![
606618
ExpressionPlacement::Column,
607619
ExpressionPlacement::Literal,
608620
ExpressionPlacement::Column,
609621
];
610-
assert_eq!(func.placement(&args), ExpressionPlacement::PlaceAtRoot);
622+
assert_eq!(
623+
func.placement(&args),
624+
ExpressionPlacement::MoveTowardsRootNodes
625+
);
611626
}
612627

613628
#[test]
@@ -616,32 +631,47 @@ mod tests {
616631

617632
// get_field(root_expr, 'literal') -> NOT leaf-pushable
618633
let args = vec![
619-
ExpressionPlacement::PlaceAtRoot,
634+
ExpressionPlacement::MoveTowardsRootNodes,
620635
ExpressionPlacement::Literal,
621636
];
622-
assert_eq!(func.placement(&args), ExpressionPlacement::PlaceAtRoot);
637+
assert_eq!(
638+
func.placement(&args),
639+
ExpressionPlacement::MoveTowardsRootNodes
640+
);
623641

624642
// get_field(col, root_expr) -> NOT leaf-pushable
625643
let args = vec![
626644
ExpressionPlacement::Column,
627-
ExpressionPlacement::PlaceAtRoot,
645+
ExpressionPlacement::MoveTowardsRootNodes,
628646
];
629-
assert_eq!(func.placement(&args), ExpressionPlacement::PlaceAtRoot);
647+
assert_eq!(
648+
func.placement(&args),
649+
ExpressionPlacement::MoveTowardsRootNodes
650+
);
630651
}
631652

632653
#[test]
633654
fn test_placement_edge_cases() {
634655
let func = GetFieldFunc::new();
635656

636657
// Empty args -> NOT leaf-pushable
637-
assert_eq!(func.placement(&[]), ExpressionPlacement::PlaceAtRoot);
658+
assert_eq!(
659+
func.placement(&[]),
660+
ExpressionPlacement::MoveTowardsRootNodes
661+
);
638662

639-
// Just base, no key -> PlaceAtLeaves (not a valid call but should handle gracefully)
663+
// Just base, no key -> MoveTowardsLeafNodes (not a valid call but should handle gracefully)
640664
let args = vec![ExpressionPlacement::Column];
641-
assert_eq!(func.placement(&args), ExpressionPlacement::PlaceAtLeaves);
665+
assert_eq!(
666+
func.placement(&args),
667+
ExpressionPlacement::MoveTowardsLeafNodes
668+
);
642669

643670
// Literal base with literal key -> NOT leaf-pushable (would be constant-folded)
644671
let args = vec![ExpressionPlacement::Literal, ExpressionPlacement::Literal];
645-
assert_eq!(func.placement(&args), ExpressionPlacement::PlaceAtRoot);
672+
assert_eq!(
673+
func.placement(&args),
674+
ExpressionPlacement::MoveTowardsRootNodes
675+
);
646676
}
647677
}

datafusion/optimizer/src/optimize_projections/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -525,7 +525,7 @@ fn merge_consecutive_projections(proj: Projection) -> Result<Transformed<Project
525525
expr.iter()
526526
.for_each(|expr| expr.add_column_ref_counts(&mut column_referral_map));
527527

528-
// If an expression is non-trivial (PlaceAtRoot) and appears more than once, do not merge
528+
// If an expression is non-trivial (MoveTowardsRootNodes) and appears more than once, do not merge
529529
// them as consecutive projections will benefit from a compute-once approach.
530530
// For details, see: https://github.com/apache/datafusion/issues/8296
531531
if column_referral_map.into_iter().any(|(col, usage)| {

datafusion/physical-expr-common/src/physical_expr.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -437,9 +437,9 @@ pub trait PhysicalExpr: Any + Send + Sync + Display + Debug + DynEq + DynHash {
437437
/// This is used by optimizers to make decisions about expression placement,
438438
/// such as whether to push expressions down through projections.
439439
///
440-
/// The default implementation returns [`ExpressionPlacement::PlaceAtRoot`].
440+
/// The default implementation returns [`ExpressionPlacement::MoveTowardsRootNodes`].
441441
fn placement(&self) -> ExpressionPlacement {
442-
ExpressionPlacement::PlaceAtRoot
442+
ExpressionPlacement::MoveTowardsRootNodes
443443
}
444444
}
445445

datafusion/physical-plan/src/projection.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@ impl ExecutionPlan for ProjectionExec {
288288
.all(|proj_expr| {
289289
!matches!(
290290
proj_expr.expr.placement(),
291-
ExpressionPlacement::PlaceAtRoot
291+
ExpressionPlacement::MoveTowardsRootNodes
292292
)
293293
});
294294
// If expressions are all either column_expr or Literal (or other cheap expressions),
@@ -1007,7 +1007,7 @@ fn try_unifying_projections(
10071007
.unwrap();
10081008
});
10091009
// Merging these projections is not beneficial, e.g
1010-
// If an expression is not trivial (PlaceAtRoot) and it is referred more than 1, unifies projections will be
1010+
// If an expression is not trivial (MoveTowardsRootNodes) and it is referred more than 1, unifies projections will be
10111011
// beneficial as caching mechanism for non-trivial computations.
10121012
// See discussion in: https://github.com/apache/datafusion/issues/8296
10131013
if column_ref_map.iter().any(|(column, count)| {

0 commit comments

Comments
 (0)