Weiwei Su created FLINK-41809:
---------------------------------

             Summary: FLOAT column compared with DOUBLE literal (= / IN) 
silently narrows DOUBLE to FLOAT and returns wrong rows
                 Key: FLINK-41809
                 URL: https://issues.apache.org/jira/browse/FLINK-41809
             Project: Flink
          Issue Type: Bug
          Components: Table SQL / Planner
    Affects Versions: 2.3.0
         Environment: Apache Flink: 2.3.0 (SQL Gateway, Batch execution mode)
            Reporter: Weiwei Su


h3. Summary

In Apache Flink 2.3.0 (Batch SQL), comparing a {{FLOAT}} column {{x}} storing 
{{0.1f}} against a {{DOUBLE}} literal {{CAST(0.1 AS DOUBLE)}} using {{=}} or 
{{IN}} returns the row as a match, even with source predicate pushdown 
completely disabled ({{table.optimizer.source.predicate-pushdown-enabled = 
'false'}}).

This directly contradicts IEEE-754 floating-point widening semantics 
({{(double) 0.1f == 0.10000000149011612 != 0.1d}}), directly contradicts 
Flink's own {{CAST(x AS DOUBLE) = CAST(0.1 AS DOUBLE)}} and {{CAST(x AS DOUBLE) 
- CAST(0.1 AS DOUBLE)}} on the exact same table, and disagrees with Spark 
4.1.2, Trino 484, and DuckDB 2.0.1 (all of which return 0 rows).

h3. Minimal Reproduction (1-Row Table, Predicate Pushdown Disabled)

Given a 1-row table {{repro_flt_in (x FLOAT)}} containing {{CAST(0.1 AS 
FLOAT)}} (with source predicate pushdown explicitly disabled):

{code:sql}
SET 'table.optimizer.source.predicate-pushdown-enabled' = 'false';

SELECT
  x,
  CAST(x AS DOUBLE) - CAST(0.1 AS DOUBLE) AS diff
FROM iceberg.`default`.repro_flt_in;
{code}
Actual result (confirms stored {{x}} is 32-bit IEEE-754 {{0.1f != 0.1d}}):
{noformat}
x   | diff
----+-----------------------
0.1 | 1.4901161138336505e-09
{noformat}

*Control query (explicit widening to {{DOUBLE}}):*
{code:sql}
SELECT x
FROM iceberg.`default`.repro_flt_in
WHERE CAST(x AS DOUBLE) = CAST(0.1 AS DOUBLE);
{code}
Actual result: *0 rows* ({{[]}}).

*Buggy queries (implicit {{FLOAT}} vs {{DOUBLE}} comparison):*
{code:sql}
SELECT x
FROM iceberg.`default`.repro_flt_in
WHERE x = CAST(0.1 AS DOUBLE);
{code}
Actual result: *1 row* ({{[[0.1]]}}).

{code:sql}
SELECT x
FROM iceberg.`default`.repro_flt_in
WHERE x IN (CAST(42 AS DOUBLE), CAST(0.1 AS DOUBLE));
{code}
Actual result: *1 row* ({{[[0.1]]}}).

h3. Cross-Engine Comparison (Same Table & Query)

* *Spark 4.1.2*: {{[]}} (0 rows)
* *Trino 484*: {{[]}} (0 rows)
* *DuckDB 2.0.1*: {{[]}} (0 rows)
* *Flink 2.3.0*: {{[[0.1]]}} (1 row — wrong result)

h3. Expected Behavior

When comparing a {{FLOAT}} column with a {{DOUBLE}} literal via {{=}} or 
{{IN}}, Flink should widen the {{FLOAT}} operand to {{DOUBLE}} (matching 
{{CAST(x AS DOUBLE) = CAST(0.1 AS DOUBLE)}}) rather than narrowing the 
{{DOUBLE}} literal to {{FLOAT}}. Both {{WHERE x = CAST(0.1 AS DOUBLE)}} and 
{{WHERE x IN (CAST(42 AS DOUBLE), CAST(0.1 AS DOUBLE))}} should return 0 rows.




--
This message was sent by Atlassian Jira
(v10.3.26#10030026)

Reply via email to