Vivek Gangavarapu created SPARK-62225:
-----------------------------------------
Summary: Re-association of integral Add/Multiply hides ANSI
overflow in canonicalization
Key: SPARK-62225
URL: https://issues.apache.org/jira/browse/SPARK-62225
Project: Spark
Issue Type: Bug
Components: SQL
Affects Versions: 5.0.0
Reporter: Vivek Gangavarapu
Under ANSI mode, integral Add/Multiply can overflow, so re-associating them is
not semantics-preserving. Canonicalization still treats them as associative, so
two expressions that behave differently are considered semantically equal.
Repro (spark.sql.ansi.enabled=true):
{code:sql}
CREATE TABLE t (a BIGINT, b BIGINT, c BIGINT) USING parquet;
INSERT INTO t VALUES (1099511627776, 1099511627776, 0); -- a = b = 2^40, c = 0
SELECT (a * b) * c FROM t; -- ARITHMETIC_OVERFLOW
SELECT a * (b * c) FROM t; -- 0
SELECT (a * b) * c FROM t GROUP BY a * (b * c); -- passes analysis, returns 0
without error
{code}
Expected: the last query should not match the select expression to the grouping
expression, since the two associations behave differently under ANSI.
Fixing this needs more than a canonicalization change, since
ReorderAssociativeOperator also re-associates integral Add.
Follow-up from the review of SPARK-60178
(https://github.com/apache/spark/pull/59437), which covers FLOAT, DOUBLE and
max-precision DECIMAL.
--
This message was sent by Atlassian Jira
(v10.3.26#10030026)
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]