Dandandan commented on code in PR #20111:
URL: https://github.com/apache/datafusion/pull/20111#discussion_r2755734889
##########
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:
That makes a lot of sense!
--
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]