joelrobin18 commented on code in PR #59954:
URL: https://github.com/apache/spark/pull/59954#discussion_r4540940342


##########
sql/core/src/test/resources/sql-tests/inputs/try_arithmetic.sql:
##########
@@ -111,3 +111,26 @@ SELECT try_multiply(interval 2 year, 0);
 SELECT try_multiply(interval 2 second, 0);
 SELECT try_multiply(interval 2147483647 month, 2);
 SELECT try_multiply(interval 106751991 day, 2);
+
+-- try_add and try_multiply chains over non-foldable inputs keep their written 
grouping, both at
+-- the top level and nested in regular arithmetic.
+CREATE TABLE try_arithmetic_chains(a INT, b INT) USING parquet;
+INSERT INTO try_arithmetic_chains VALUES (2147483647, 1), (-10, 0), 
(2147483643, 0), (1073741824, 2);
+SELECT try_add(try_add(a, -5), b) FROM try_arithmetic_chains WHERE a = 
2147483647;
+SELECT try_add(try_add(a, -5), b) + 1 FROM try_arithmetic_chains WHERE a = 
2147483647;
+SELECT try_add(try_add(a, 2147483647), 1) FROM try_arithmetic_chains WHERE a = 
-10;
+SELECT -5 + try_add(try_add(a, 2147483647), 1) FROM try_arithmetic_chains 
WHERE a = -10;
+SELECT try_add(try_add(a, 5), -3) FROM try_arithmetic_chains WHERE a = 
2147483643;
+SELECT try_multiply(try_multiply(a, -1), b) FROM try_arithmetic_chains WHERE a 
= 1073741824;
+SELECT try_multiply(try_multiply(a, -1), b) * 3 FROM try_arithmetic_chains 
WHERE a = 1073741824;
+-- Chains with one column operand and literals that move away from zero fold 
exactly.
+SELECT try_add(try_add(a, 1), 2) FROM try_arithmetic_chains WHERE a = 
2147483643;
+SELECT try_add(try_add(a, 2), 3) FROM try_arithmetic_chains WHERE a = 
2147483643;
+SELECT try_multiply(try_multiply(a, 2), 3) FROM try_arithmetic_chains WHERE a 
= -10;
+SELECT try_multiply(try_multiply(a, 2), 2) FROM try_arithmetic_chains WHERE a 
= 1073741824;
+-- A differently grouped TRY chain is not the grouping expression.
+SELECT try_add(try_add(a, -5), b) FROM try_arithmetic_chains WHERE a = 
2147483647

Review Comment:
   Dropped the two GROUP BY queries and added projections that select both 
groupings: `try_add` returns `2147483643` and `NULL`, `try_multiply` returns 
`-2147483648` and `NULL`, with and without ANSI. Verified that with the base 
branch's Add/Multiply canonicalization the `try_add` projection returns 
`2147483643` in both columns, so the golden comparison fails. Updated the PR 
description to drop the GROUP BY claims.
   
   Addressed in c94ab88ce0f.



-- 
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]

Reply via email to