akurmustafa commented on code in PR #13497:
URL: https://github.com/apache/datafusion/pull/13497#discussion_r1851353044


##########
datafusion/physical-expr/src/equivalence/properties.rs:
##########
@@ -1208,7 +1208,12 @@ fn is_constant_recurse(
         return true;
     }
     let children = expr.children();
-    !children.is_empty() && children.iter().all(|c| 
is_constant_recurse(constants, c))
+    // When expression contains branch even if all children are constant
+    // final result may not be constant
+    let is_branched = expr.as_any().is::<CaseExpr>();

Review Comment:
   After you comment, I thought about this. It turns out that my initial 
approach is indeed wrong. `Datafusion` has 2 kinds of constant expressions. One 
is `across_partitions`, other is `per partition`, indicate with 
`across_partitions=false` flag. In following plan
   ```
   02)--ProjectionExec: expr=[CASE WHEN name@0 = name1 THEN 0 WHEN name@0 = 
name2 THEN 0.5 END as a]
   03)----UnionExec
   04)------ProjectionExec: expr=[name1 as name]
   05)--------PlaceholderRowExec
   06)------ProjectionExec: expr=[name2 as name]
   07)--------PlaceholderRowExec
   ``` 
   union has 2 children, each with constant `name` columns (since each source 
has single row, each column is constant). `Union` transforms these constant 
children as constant, but with `across_partitions=false` (which is correct). 
Each partition still receives constant value from their perspective (By the way 
`Union` doesn't merge any partition ). This is also correct for 
`ProjectionExec`. At `ProjectionExec` column `name` is constant, where 
`across_partitions=false`. However, in the current code, it is propagated as 
`across_partitions=true`. This behaviour is the root cause of the issue. I 
changed my implementation to fix this issue.        



-- 
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: github-unsubscr...@datafusion.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscr...@datafusion.apache.org
For additional commands, e-mail: github-h...@datafusion.apache.org

Reply via email to