akoshchiy opened a new issue, #27689:
URL: https://github.com/apache/datafusion/issues/27689
### Describe the bug
Comparisons against an overflowing `TRY_CAST` returned `TRUE` for two
conversions: `Timestamp(s)` to `TIMESTAMP(9)` and `BIGINT` to `DECIMAL(10,2)`.
In both cases, using the comparison in a WHERE clause incorrectly kept the
overflowing row.
### To Reproduce
<p>Run these statements in the DataFusion CLI:</p>
<pre><code>-- Case 1: Timestamp(s) to TIMESTAMP(9). The year-2603 value
overflows.
CREATE TABLE ts AS
SELECT arrow_cast(v, 'Timestamp(s)') AS t
FROM (VALUES (0), (20000000000)) AS x(v);
SELECT t,
TRY_CAST(t AS TIMESTAMP(9)) AS c,
TRY_CAST(t AS TIMESTAMP(9)) > TIMESTAMP '1970-01-01 00:00:01' AS try_gt
FROM ts
ORDER BY t;
SELECT t FROM ts
WHERE TRY_CAST(t AS TIMESTAMP(9)) > TIMESTAMP '1970-01-01 00:00:01';
-- Case 2: BIGINT to DECIMAL(10,2). The larger value exceeds the precision.
CREATE TABLE ints AS VALUES (5::bigint), (999999999999::bigint);
SELECT column1,
TRY_CAST(column1 AS DECIMAL(10,2)) AS c,
TRY_CAST(column1 AS DECIMAL(10,2)) > CAST(4 AS DECIMAL(10,2)) AS try_gt
FROM ints
ORDER BY column1;
SELECT column1 FROM ints
WHERE TRY_CAST(column1 AS DECIMAL(10,2)) > CAST(4 AS DECIMAL(10,2));
</code></pre>
### Expected behavior
For both overflowing inputs, c and try_gt should be NULL. A WHERE clause
keeps only rows where the predicate is TRUE, so the timestamp filter should
return no rows and the decimal filter should return only 5.
### Additional context
A #24702 reports the same loss of NULL-on-overflow semantics for narrowing
integer casts
### Willingness to contribute
None
--
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]