AdamGS commented on code in PR #20111:
URL: https://github.com/apache/datafusion/pull/20111#discussion_r2755609963
##########
datafusion/physical-expr/src/simplifier/const_evaluator.rs:
##########
@@ -40,17 +40,22 @@ use crate::expressions::{Column, Literal};
/// - `(1 + 2) * 3` -> `9` (with bottom-up traversal)
/// - `'hello' || ' world'` -> `'hello world'`
pub fn simplify_const_expr(
- expr: &Arc<dyn PhysicalExpr>,
+ expr: Arc<dyn PhysicalExpr>,
) -> Result<Transformed<Arc<dyn PhysicalExpr>>> {
- if !can_evaluate_as_constant(expr) {
- return Ok(Transformed::no(Arc::clone(expr)));
- }
+ simplify_const_expr_with_dummy(expr, &create_dummy_batch()?)
+}
- // Create a 1-row dummy batch for evaluation
- let batch = create_dummy_batch()?;
+pub(crate) fn simplify_const_expr_with_dummy(
+ expr: Arc<dyn PhysicalExpr>,
+ batch: &RecordBatch,
+) -> Result<Transformed<Arc<dyn PhysicalExpr>>> {
+ // If expr is already a const literal or can't be evaluated into one.
+ if expr.as_any().is::<Literal>() || (!can_evaluate_as_constant(&expr)) {
Review Comment:
@Dandandan I'm convinced this is the biggest win and a significant win here.
Right now even something like `lit(5)` will run through 5 simplification steps,
which are completely avoidable. I've also verified it locally.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]