|
20 | 20 | //! of a projection on table `t1` where the expressions `a`, `b`, and `a+b` are the |
21 | 21 | //! projection expressions. `SELECT` without `FROM` will only evaluate expressions. |
22 | 22 |
|
23 | | -use super::expressions::{Column, Literal}; |
| 23 | +use super::expressions::Column; |
24 | 24 | use super::metrics::{BaselineMetrics, ExecutionPlanMetricsSet, MetricsSet}; |
25 | 25 | use super::{ |
26 | 26 | DisplayAs, ExecutionPlanProperties, PlanProperties, RecordBatchStream, |
@@ -253,18 +253,16 @@ impl ExecutionPlan for ProjectionExec { |
253 | 253 | } |
254 | 254 |
|
255 | 255 | fn benefits_from_input_partitioning(&self) -> Vec<bool> { |
256 | | - let all_simple_exprs = |
257 | | - self.projector |
258 | | - .projection() |
259 | | - .as_ref() |
260 | | - .iter() |
261 | | - .all(|proj_expr| { |
262 | | - proj_expr.expr.as_any().is::<Column>() |
263 | | - || proj_expr.expr.as_any().is::<Literal>() |
264 | | - }); |
265 | | - // If expressions are all either column_expr or Literal, then all computations in this projection are reorder or rename, |
266 | | - // and projection would not benefit from the repartition, benefits_from_input_partitioning will return false. |
267 | | - vec![!all_simple_exprs] |
| 256 | + let all_trivial_exprs = self |
| 257 | + .projector |
| 258 | + .projection() |
| 259 | + .as_ref() |
| 260 | + .iter() |
| 261 | + .all(|proj_expr| proj_expr.expr.is_trivial()); |
| 262 | + // If expressions are all trivial (columns, literals, or field accessors), |
| 263 | + // then all computations in this projection are reorder or rename, |
| 264 | + // and projection would not benefit from the repartition. |
| 265 | + vec![!all_trivial_exprs] |
268 | 266 | } |
269 | 267 |
|
270 | 268 | fn children(&self) -> Vec<&Arc<dyn ExecutionPlan>> { |
@@ -630,11 +628,10 @@ pub fn make_with_child( |
630 | 628 | .map(|e| Arc::new(e) as _) |
631 | 629 | } |
632 | 630 |
|
633 | | -/// Returns `true` if all the expressions in the argument are `Column`s. |
634 | | -pub fn all_columns(exprs: &[ProjectionExpr]) -> bool { |
635 | | - exprs |
636 | | - .iter() |
637 | | - .all(|proj_expr| proj_expr.expr.as_any().is::<Column>()) |
| 631 | +/// Returns `true` if all the expressions in the argument are trivial |
| 632 | +/// (columns, literals, or field accessors). |
| 633 | +pub fn all_trivial(exprs: &[ProjectionExpr]) -> bool { |
| 634 | + exprs.iter().all(|proj_expr| proj_expr.expr.is_trivial()) |
638 | 635 | } |
639 | 636 |
|
640 | 637 | /// Updates the given lexicographic ordering according to given projected |
@@ -990,10 +987,9 @@ fn new_columns_for_join_on( |
990 | 987 | } |
991 | 988 |
|
992 | 989 | /// Checks if the given expression is trivial. |
993 | | -/// An expression is considered trivial if it is either a `Column` or a `Literal`. |
| 990 | +/// An expression is considered trivial if it is a `Column`, `Literal`, or field accessor. |
994 | 991 | fn is_expr_trivial(expr: &Arc<dyn PhysicalExpr>) -> bool { |
995 | | - expr.as_any().downcast_ref::<Column>().is_some() |
996 | | - || expr.as_any().downcast_ref::<Literal>().is_some() |
| 992 | + expr.is_trivial() |
997 | 993 | } |
998 | 994 |
|
999 | 995 | #[cfg(test)] |
|
0 commit comments