findepi commented on code in PR #13497: URL: https://github.com/apache/datafusion/pull/13497#discussion_r1855233587
########## 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: thanks for the explanation! ########## datafusion/sqllogictest/test_files/order.slt: ########## @@ -1260,3 +1260,34 @@ limit 2; statement ok drop table ordered_table; + +query TT +EXPLAIN SELECT + CASE + WHEN name = 'name1' THEN 0.0 + WHEN name = 'name2' THEN 0.5 + END AS a +FROM ( + SELECT 'name1' AS name + UNION ALL + SELECT 'name2' +) +ORDER BY a DESC; Review Comment: Can you please also add a test case with query that would produce incorrect results before the fix? -- 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