kosiew commented on code in PR #27002:
URL: https://github.com/apache/datafusion/pull/27002#discussion_r4639531341
##########
datafusion/optimizer/src/simplify_expressions/expr_simplifier.rs:
##########
@@ -2845,6 +2869,25 @@ mod tests {
assert_eq!(simplify(expr), expected);
}
+ #[test]
+ fn test_simplify_multiply_by_zero_preserves_result_type() {
+ let schema = expr_test_schema();
+
+ // `Int64 * Decimal128(20, 0)` has result type `Decimal128(38, 0)`.
+ // Folding to the zero operand used to leave a `Decimal128(20, 0)`
+ // behind, so the comparison the plan was built around no longer
+ // matched: it failed in interval analysis while planning, or in the
+ // comparison kernel once there were rows.
+ let expr = col("c3_non_null") * lit(ScalarValue::Decimal128(Some(0),
20, 0));
+ let before = expr.get_type(&schema).unwrap();
+ assert_eq!(before, DataType::Decimal128(38, 0));
+ assert_eq!(simplify(expr).get_type(&schema).unwrap(), before);
Review Comment:
Could we use `simplify_no_canonicalize` to test both operand orders and
assert the exact zero literal `Decimal128(Some(0), 38, 0)`? The current
type-only assertion also passes if multiplication remains unsimplified.
##########
datafusion/optimizer/src/simplify_expressions/expr_simplifier.rs:
##########
@@ -2845,6 +2869,25 @@ mod tests {
assert_eq!(simplify(expr), expected);
}
+ #[test]
+ fn test_simplify_multiply_by_zero_preserves_result_type() {
Review Comment:
Could we add a SQL regression in `simplify_expr.slt`? Verify `c * 0 >= 2`
returns no rows on empty and populated `UBIGINT NOT NULL` tables, while `c * 0
>= 0` returns both inserted rows.
--
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]