Skip to content

Commit f168f60

Browse files
committed
rename MoveTowardsRootNodes -> KeepInPlace
1 parent f7a7155 commit f168f60

7 files changed

Lines changed: 21 additions & 40 deletions

File tree

‎datafusion/expr-common/src/placement.rs‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,9 @@ pub enum ExpressionPlacement {
3333
/// at low compute cost.
3434
/// See [`ExpressionPlacement::should_push_to_leaves`] for details.
3535
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).
36+
/// An expensive expression that should stay where it is in the plan.
3837
/// Examples include complex scalar functions or UDFs.
39-
MoveTowardsRootNodes,
38+
KeepInPlace,
4039
}
4140

4241
impl ExpressionPlacement {

‎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::MoveTowardsRootNodes,
1553+
_ => ExpressionPlacement::KeepInPlace,
15541554
}
15551555
}
15561556

‎datafusion/expr/src/udf.rs‎

Lines changed: 3 additions & 3 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::MoveTowardsRootNodes`],
982-
/// meaning the expression should stay at the root of the plan.
981+
/// The default implementation returns [`ExpressionPlacement::KeepInPlace`],
982+
/// meaning the expression should be kept where it is in 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::MoveTowardsRootNodes
987+
ExpressionPlacement::KeepInPlace
988988
}
989989
}
990990

‎datafusion/functions/src/core/getfield.rs‎

Lines changed: 10 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -505,7 +505,7 @@ 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::MoveTowardsRootNodes;
508+
return ExpressionPlacement::KeepInPlace;
509509
}
510510

511511
let base_placement = args[0];
@@ -522,7 +522,7 @@ impl ScalarUDFImpl for GetFieldFunc {
522522
if base_is_pushable && all_keys_are_literals {
523523
ExpressionPlacement::MoveTowardsLeafNodes
524524
} else {
525-
ExpressionPlacement::MoveTowardsRootNodes
525+
ExpressionPlacement::KeepInPlace
526526
}
527527
}
528528
}
@@ -608,21 +608,15 @@ mod tests {
608608

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

616613
// get_field(col, 'a', other_col) -> NOT leaf-pushable (dynamic nested lookup)
617614
let args = vec![
618615
ExpressionPlacement::Column,
619616
ExpressionPlacement::Literal,
620617
ExpressionPlacement::Column,
621618
];
622-
assert_eq!(
623-
func.placement(&args),
624-
ExpressionPlacement::MoveTowardsRootNodes
625-
);
619+
assert_eq!(func.placement(&args), ExpressionPlacement::KeepInPlace);
626620
}
627621

628622
#[test]
@@ -631,34 +625,25 @@ mod tests {
631625

632626
// get_field(root_expr, 'literal') -> NOT leaf-pushable
633627
let args = vec![
634-
ExpressionPlacement::MoveTowardsRootNodes,
628+
ExpressionPlacement::KeepInPlace,
635629
ExpressionPlacement::Literal,
636630
];
637-
assert_eq!(
638-
func.placement(&args),
639-
ExpressionPlacement::MoveTowardsRootNodes
640-
);
631+
assert_eq!(func.placement(&args), ExpressionPlacement::KeepInPlace);
641632

642633
// get_field(col, root_expr) -> NOT leaf-pushable
643634
let args = vec![
644635
ExpressionPlacement::Column,
645-
ExpressionPlacement::MoveTowardsRootNodes,
636+
ExpressionPlacement::KeepInPlace,
646637
];
647-
assert_eq!(
648-
func.placement(&args),
649-
ExpressionPlacement::MoveTowardsRootNodes
650-
);
638+
assert_eq!(func.placement(&args), ExpressionPlacement::KeepInPlace);
651639
}
652640

653641
#[test]
654642
fn test_placement_edge_cases() {
655643
let func = GetFieldFunc::new();
656644

657645
// Empty args -> NOT leaf-pushable
658-
assert_eq!(
659-
func.placement(&[]),
660-
ExpressionPlacement::MoveTowardsRootNodes
661-
);
646+
assert_eq!(func.placement(&[]), ExpressionPlacement::KeepInPlace);
662647

663648
// Just base, no key -> MoveTowardsLeafNodes (not a valid call but should handle gracefully)
664649
let args = vec![ExpressionPlacement::Column];
@@ -669,9 +654,6 @@ mod tests {
669654

670655
// Literal base with literal key -> NOT leaf-pushable (would be constant-folded)
671656
let args = vec![ExpressionPlacement::Literal, ExpressionPlacement::Literal];
672-
assert_eq!(
673-
func.placement(&args),
674-
ExpressionPlacement::MoveTowardsRootNodes
675-
);
657+
assert_eq!(func.placement(&args), ExpressionPlacement::KeepInPlace);
676658
}
677659
}

‎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 (MoveTowardsRootNodes) and appears more than once, do not merge
528+
// If an expression is non-trivial (KeepInPlace) 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::MoveTowardsRootNodes`].
440+
/// The default implementation returns [`ExpressionPlacement::KeepInPlace`].
441441
fn placement(&self) -> ExpressionPlacement {
442-
ExpressionPlacement::MoveTowardsRootNodes
442+
ExpressionPlacement::KeepInPlace
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::MoveTowardsRootNodes
291+
ExpressionPlacement::KeepInPlace
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 (MoveTowardsRootNodes) and it is referred more than 1, unifies projections will be
1010+
// If an expression is not trivial (KeepInPlace) 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)