Description
Several visitor/evaluator edge cases appear unsafe or inconsistent:
-
_StrictMetricsEvaluator.visit_not_equal/visit_not_inreturnROWS_MUST_MATCHwhen a file can contain nulls or NaNs. Example stats with[null, 5]or[NaN, 5.0]and lower/upper bounds both5return true forNotEqualTo("x", 5)/NotIn("x", {5}), even though one row does not match. This can incorrectly mark whole files deleted. -
_StrictMetricsEvaluator.evalreturnsROWS_MUST_MATCHforrecord_count <= 0.record_count=0is vacuously true, butrecord_count=-1is unknown per the local comment; evenAlwaysFalse()returns true. -
ResidualVisitorcomparison methods directly compare partition values to literals. A nullable identity partition value ofNonewithLessThan("x", 1)raisesTypeError, while row evaluation returns false. -
ResidualVisitor.visit_not_nan(None)returnsAlwaysFalse, while expression evaluation treatsNotNaN(None)as true. Existing tests encode both behaviors, so the semantics are inconsistent.
Validated against the current tree; examples use stats/partition shapes already supported by the repo tests.
Activity
tanmayrauth commentedon Jun 14, 2026
I went through visitors.py and the call sites, and three of the four hold up. The big one is 1: visit_not_equal and visit_not_in short-circuit on _can_contain_nulls/_can_contain_nans and return ROWS_MUST_MATCH without ever checking the bounds, where every other strict method (and Java) uses the contains*_only variants. Since the strict evaluator drives _DeleteFiles (snapshot.py:460), this isn't just over-pruning — a delete(NotEqualTo("x", 5)) against a file with stats [null, 5] would drop the whole file and take the legitimate 5 row with it, so it's effectively silent data loss. 3 and 4 are real too: the ResidualVisitor comparisons hit None < literal and raise TypeError where the row evaluator safely guards for None, and visit_not_nan(None) returns AlwaysFalse while the row evaluator treats it as true — both reachable on the scan path via residual_for. The only one I'd push back on is 2; the record_count <= 0 behavior matches upstream Java and looks intentional, though the comment could be clearer about the -1 case.
If nobody's already on this, I'd like to take it, starting with 1 since it's the data-loss path, with a regression test asserting the 5 row survives the delete, then a follow-up for the ResidualVisitor null handling.
Fix strict NotEqualTo/NotIn pruning with partial nulls or NaNs (#3521)
kevinjqliu commentedon Jun 22, 2026
Issue #3498 evaluation
Validated on PyIceberg
origin/mainat7fff821199bfc111c9b8b1667b80c846d260c6c5, compared with Apache Iceberg Javamainat0b30919372df34afb632f037df88c05cdba0b134.1. Strict metrics
NotEqualTo/NotIncan falsely prove all rows matchStatus: Valid, high severity, Java-parity bug.
PyIceberg returns
ROWS_MUST_MATCHwhen a column merely can contain nulls or NaNs:visit_not_equal:iceberg-python/pyiceberg/expressions/visitors.py
Lines 1667 to 1695 in 7fff821
visit_not_in:iceberg-python/pyiceberg/expressions/visitors.py
Lines 1728 to 1762 in 7fff821
That is unsafe. A file with values
[null, 5]and bounds[5, 5]is not guaranteed to matchNotEqualTo("x", 5)orNotIn("x", {5}), because the5row does not match. Same idea for[NaN, 5.0].Impact is serious because delete planning drops whole data files when strict metrics returns
ROWS_MUST_MATCH:iceberg-python/pyiceberg/table/update/snapshot.py
Lines 432 to 437 in 7fff821
ROWS_MUST_MATCH:iceberg-python/pyiceberg/table/update/snapshot.py
Lines 459 to 463 in 7fff821
Java only short-circuits when the column contains only nulls or only NaNs:
StrictMetricsEvaluator.notEq: https://github.com/apache/iceberg/blob/0b30919372df34afb632f037df88c05cdba0b134/api/src/main/java/org/apache/iceberg/expressions/StrictMetricsEvaluator.java#L341-L375StrictMetricsEvaluator.notIn: https://github.com/apache/iceberg/blob/0b30919372df34afb632f037df88c05cdba0b134/api/src/main/java/org/apache/iceberg/expressions/StrictMetricsEvaluator.java#L418-L462Suggested fix: in
visit_not_equalandvisit_not_in, replace_can_contain_nulls/_can_contain_nanswith_contains_nulls_only/_contains_nans_only, then continue to use bounds checks for mixed-value cases.Suggested tests:
NotEqualTo("x", 5)with value count2, null count1, bounds5..5returnsROWS_MIGHT_NOT_MATCHNotIn("x", {5})with the same stats returnsROWS_MIGHT_NOT_MATCHROWS_MUST_MATCH2. Strict metrics returns true for
record_count <= 0Status: Reproduces, but matches Java; likely not an implementation bug.
PyIceberg returns
ROWS_MUST_MATCHforrecord_count <= 0before visiting the expression:_StrictMetricsEvaluator.eval:iceberg-python/pyiceberg/expressions/visitors.py
Lines 1503 to 1516 in 7fff821
This means even
AlwaysFalse()returns true whenrecord_count=-1.Java does the same:
Suggested action: do not change this as part of a Java-parity fix. If desired, clarify the comment or open a separate design discussion.
3. Residual comparisons raise on nullable identity partition values
Status: Valid PyIceberg runtime bug; Java does not throw for comparable literals.
PyIceberg residual comparison methods directly compare partition values to literals:
iceberg-python/pyiceberg/expressions/visitors.py
Lines 1852 to 1874 in 7fff821
For a nullable identity partition value
None,LessThan("x", 1)raises:Java residual evaluation uses literal comparators, and comparable literals use
nullsFirst, so comparable null partition values do not raise:Suggested fix: centralize comparison in
ResidualVisitorthrough a null-aware comparator matching Iceberg literal ordering. Be careful: Java’s comparator behavior is not the same as PyIceberg row evaluation’sNoneguard. The goal for residuals should be Java parity and no runtime exception.Suggested tests:
Nonefor<,<=,>,>=4. Residual
NotNaN(None)disagrees with row evaluation and JavaStatus: Valid, Java-parity bug.
PyIceberg residual
visit_not_nanreturns false unless the value is float-like and not NaN:visit_not_nan:iceberg-python/pyiceberg/expressions/visitors.py
Lines 1845 to 1850 in 7fff821
For floating identity partitions,
NotNaN(None)returnsAlwaysFalse(). But PyIceberg row evaluation treatsNone == Noneas true forNotNaN(None):visit_not_nan:iceberg-python/pyiceberg/expressions/visitors.py
Lines 478 to 480 in 7fff821
Java also treats
NotNaN(null)as true becauseNaNUtil.isNaN(null)is false:NaNUtil: https://github.com/apache/iceberg/blob/0b30919372df34afb632f037df88c05cdba0b134/api/src/main/java/org/apache/iceberg/util/NaNUtil.java#L25-L37notNaN: https://github.com/apache/iceberg/blob/0b30919372df34afb632f037df88c05cdba0b134/api/src/main/java/org/apache/iceberg/expressions/ResidualEvaluator.java#L155-L163notNaN: https://github.com/apache/iceberg/blob/0b30919372df34afb632f037df88c05cdba0b134/api/src/main/java/org/apache/iceberg/expressions/Evaluator.java#L95-L102Suggested fix: update residual
visit_not_nanso only actual NaN values returnAlwaysFalse;Noneand non-NaN values should returnAlwaysTrue.Suggested tests:
tests/expressions/test_residual_evaluator.pyexpectations forNotNaN(None)NotNaN(None)returnsAlwaysTrue()Fix ResidualVisitor null handling for comparisons and not-NaN
Fix ResidualVisitor null handling for comparisons and not-NaN
kevinjqliu commentedon Aug 22, 2026
These are mostly resolved.
NotEqualTo/NotInpruning — Fixed in Fix strict NotEqualTo/NotIn pruning with partial nulls or NaNs #3521, with additional regression coverage in Add strict NotEqualTo/NotIn null and NaN tests #3547. Both are merged.record_count <= 0— Addressed by #3831, currently open. It preserves zero as empty and treats negative legacy/unknown counts conservatively.<,<=,>, and>=, including a public scan regression test.NotNaN(None)semantics — Fixed by Fix residual NotNaN for null partition values #3689, which is merged.Once #3817 and #3831 are merged, all actionable items will be resolved.