You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
ANSI: comparisons evaluate the right operand on rows where the left one is NULL #7468
Under ANSI mode, Comet evaluates the right side of =, <, <=, >, >= on rows where the left side is NULL. Spark skips the right side on those rows: EqualTo and the ordering comparisons use defineCodeGen, which goes through nullSafeCodeGen, so the right operand is only evaluated where the left one is not NULL. When the right side can fail, such as an ANSI cast of a malformed string, Comet raises an error that Spark never raises.
This is the same shape as #7246, which covers arithmetic and concat and is being fixed in #7456. It was raised in review there by @comphead: #7456 (review)
Steps to reproduce
With spark.sql.ansi.enabled=true and spark.sql.adaptive.enabled=false (Spark 4.1.3, Comet built from #7456):
CREATETABLEcmp(id int, n int, txt string) USING parquet;
INSERT INTO cmp SELECT/*+ REPARTITION(1) */*FROMVALUES
(1, CAST(NULLASINT), 'bad'), (2, 2, '2') AS t(id, n, txt);
SELECT id, n < CAST(txt ASINT) FROM cmp;
Comet fails in CometProject with:
[CAST_INVALID_INPUT] The value 'bad' of the type "STRING" cannot be cast to "INT" because it is malformed. ...
Expected behavior
Same as Spark: (1, NULL), (2, false). The cast is never evaluated for row 1 because n is NULL.
Additional context
SELECT id FROM cmp WHERE n = CAST(txt AS INT) did not fail in the same run, presumably because the inferred isnotnull(n) filter and Comet's lazy AND skip the row first. A projection, or any position where no such filter is inferred, does fail.
A fix could mark the comparisons the same way #7456 marks arithmetic, with NullShortCircuit over the comparison when the right side can fail.
Activity