thaddywu opened a new issue, #19102:
URL: https://github.com/apache/iceberg/issues/19102

   ### Apache Iceberg version
   
   1.12.0 (latest release)
   
   ### Query engine
   
   Flink
   
   ### Please describe the bug 🐞
   
   When a Flink SQL filter compares a column with a literal of a wider numeric 
type, `FlinkFilters` pushes the comparison into the Iceberg scan with the 
literal converted to the column type. Narrowing a DOUBLE literal to FLOAT 
changes the predicate, so rows that match are dropped and no error is raised. 
When the literal cannot be converted (a fractional value for an INT / BIGINT 
column, a DECIMAL for a FLOAT column), the query fails.
   
   Flink 2.3.0, iceberg-flink-runtime-2.3 1.12.0, batch mode, hadoop catalog:
   
   ```sql
   CREATE CATALOG ice WITH ('type'='iceberg', 'catalog-type'='hadoop', 
'warehouse'='file:///tmp/ice');
   CREATE DATABASE ice.db;
   CREATE TABLE ice.db.t (f FLOAT, i INT) WITH ('format-version'='2');
   INSERT INTO ice.db.t VALUES (CAST(0.1 AS FLOAT), 7);
   
   SELECT * FROM ice.db.t WHERE f > 0.1E0;
   -- expected: (0.1, 7)    0.1f = 0.100000001490116... > 0.1 (Flink compares 
in DOUBLE)
   -- actual:   no rows
   
   SELECT * FROM ice.db.t WHERE f > CAST(0.1 AS DOUBLE);   -- no rows, expected 
(0.1, 7)
   
   SELECT * FROM ice.db.t WHERE i > 6.5E0;
   -- expected: (0.1, 7)
   -- actual:   org.apache.iceberg.exceptions.ValidationException: Invalid 
value for conversion to type int: 6.5 (java.lang.Double)
   
   SELECT * FROM ice.db.t WHERE i > 6.5;
   -- actual:   ValidationException: Invalid value for conversion to type int: 
6.5 (java.math.BigDecimal)
   ```
   
   For comparison, the same queries over a `VALUES` view with the same row 
return `(0.1, 7)` in all four cases.
   
   * Same with Parquet, ORC and Avro data files, with 
`write.metadata.metrics.default=none`, and with or without partitioning. The 
row is dropped by the source's row filter as well as by file pruning, and Flink 
cannot bring it back by re-evaluating the filter.
   * BIGINT columns fail the same way (`b < 5.5`: `Invalid value for conversion 
to type long`), and so do FLOAT columns compared with a DECIMAL literal (`f > 
0.1`: `Invalid value for conversion to type float: 0.1 (java.math.BigDecimal)`).
   
   **Cause** (`flink/v2.3/.../FlinkFilters.java`, unchanged on main as of 
2026-11-20):
   * `convertFieldAndLiteral` builds `Expressions.greaterThan(name, value)` 
from the literal's Java value (`convertLiteral` uses 
`getValueAs(defaultConversion)`), and does not look at the column's or the 
literal's type.
   * Binding the unbound predicate to the column then converts the literal to 
the column type (`UnboundPredicate.bindLiteralOperation` -> `Literal.to(type)`):
     * DOUBLE -> FLOAT narrows 0.1d to 0.1f, so `f > 0.1d` is evaluated as `f > 
0.1f`, which is false for the stored value.
     * DOUBLE / DECIMAL -> INT / LONG / FLOAT has no conversion, so binding 
throws `ValidationException` while splits are planned.
   * `IcebergTableSource.applyFilters` accepts every filter that 
`FlinkFilters.convert` converts.
   
   A possible fix: push a comparison down only when the literal converts to the 
column type without loss (for example INT -> BIGINT), and otherwise return 
`Optional.empty()`, which leaves the filter to Flink.
   
   
   ### Willingness to contribute
   
   - [x] I can contribute a fix for this bug independently
   - [ ] I would be willing to contribute a fix for this bug with guidance from 
the Iceberg community
   - [ ] I cannot contribute a fix for this bug at this time


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