Repository navigation
Conversation
…issing While reviewing apache#1153, I noticed that the inclusive IN evaluator stopped as soon as it found a missing lower bound. For example, a file with an upper bound of 50 was still read for id IN (51, 70). Use each available bound to rule out candidates. Add regression tests for candidates above the upper bound, a candidate equal to it, and a NaN candidate that the upper bound cannot rule out.
|
|
||
| return kRowsMightMatch; | ||
| const bool has_lower = lower.has_value() && !lower->IsNull(); | ||
| const bool has_upper = upper.has_value() && !upper->IsNull() && !upper->IsNaN(); |
There was a problem hiding this comment.
A v3 file can retain a four-byte date upper bound after promotion to timestamp. The shared decoder treats the day count as micros or nanos. This bug predates #1153 and can cause its strict NOT IN path to delete files incorrectly. This patch also exposes the bug in inclusive IN when the lower bound is missing.
There was a problem hiding this comment.
Thanks for catching this. I opened #1157 to fix the date conversion in the shared decoder, please take a look when available.
| return std::ranges::any_of(literal_set, [&](const Literal& lit) { | ||
| // Bounds exclude NaN values and may be missing on either side. | ||
| return lit.IsNaN() || | ||
| ((!has_lower || *lower <= lit) && (!has_upper || lit <= *upper)); |
There was a problem hiding this comment.
On libc++, a date upper bound in year 32768 becomes a negative year. With no lower bound, this can prune a file containing 1970 for year(d) IN (0, 1).
There was a problem hiding this comment.
Yeah, I opened #1158 to fix both year() and month() in TemporalUtils
|
|
||
| ICEBERG_ASSIGN_OR_RAISE(auto lower, LowerBound(expr)); | ||
| if (!lower.has_value() || lower->IsNull() || lower->IsNaN()) { | ||
| if (lower.has_value() && lower->IsNaN()) { |
There was a problem hiding this comment.
The old check returned early when the lower bound was missing or null, so we never checked the upper bound. For example, if the upper bound is 50, we can still skip the file for IN (51, 70). We still return early for a NaN lower bound because it means the bounds are unreliable.
There was a problem hiding this comment.
nit: readability, an inline comment might be helpful to explain this.
There was a problem hiding this comment.
if lower bound is NaN, it sounds like we're saying both bounds are unreliable. If so, should we have a defensive check: if either bounds are NaN, then don't rely on the bounds at all.
After a date column is promoted to timestamp or timestamp_ns, existing files can still have four-byte bounds in days since 1970-01-01. For example, day 1 represents midnight on January 2, or 86,400,000,000 microseconds since the epoch. The decoder used to read it as 1 microsecond. With only that upper bound, the strict NOT IN check from apache#1153 can conclude that every row matches even if the file contains an excluded timestamp. The inclusive IN change in apache#1156 exposes the same problem when deciding whether to skip a file. Scale the day count to microseconds or nanoseconds in FromBytes and check for overflow. This also fixes callers that decode manifest bounds and compare delete-file bounds. Reject four-byte time and zoned timestamps because Iceberg does not allow date promotion to those types. Add coverage for both precisions, overflow in either direction, and strict NOT IN with only a promoted upper bound. The strict regression fails with the previous decoder. All 559 expression tests pass.
After a date column is promoted to timestamp or timestamp_ns, existing files can still have four-byte bounds in days since 1970-01-01. For example, day 1 represents midnight on January 2, or 86,400,000,000 microseconds since the epoch. The decoder used to read it as 1 microsecond. With only that upper bound, the strict NOT IN check from apache#1153 can conclude that every row matches even if the file contains an excluded timestamp. The inclusive IN change in apache#1156 exposes the same problem when deciding whether to skip a file. Scale the day count to microseconds or nanoseconds in FromBytes and check for overflow. This also fixes callers that decode manifest bounds and compare delete-file bounds. Reject four-byte time and zoned timestamps because Iceberg does not allow date promotion to those types. Add coverage for both precisions, overflow in either direction, and strict NOT IN with only a promoted upper bound. The strict regression fails with the previous decoder. All 559 expression tests pass.
deepaknettem
left a comment
There was a problem hiding this comment.
thank you, left a couple of minor comments.
| const BoundSetPredicate::LiteralSet& literal_set) override { | ||
| // all terms are null preserving. see #isNullPreserving(Bound) | ||
| int32_t id = expr->reference()->field().field_id(); | ||
| if (ContainsNullsOnly(id) || ContainsNaNsOnly(id)) { |
There was a problem hiding this comment.
Can literal be NaN? For example, is a query like this possible: WHERE x IN {NaN}
If yes, then we could have a case where the file ContainsNansOnly, we return kRowCannotMatch, and incorrectly skip the file.
|
|
||
| ICEBERG_ASSIGN_OR_RAISE(auto lower, LowerBound(expr)); | ||
| if (!lower.has_value() || lower->IsNull() || lower->IsNaN()) { | ||
| if (lower.has_value() && lower->IsNaN()) { |
There was a problem hiding this comment.
if lower bound is NaN, it sounds like we're saying both bounds are unreliable. If so, should we have a defensive check: if either bounds are NaN, then don't rely on the bounds at all.
deepaknettem
left a comment
There was a problem hiding this comment.
one more comment re: partial order check
| return std::ranges::any_of(literal_set, [&](const Literal& lit) { | ||
| // Bounds exclude NaN values and may be missing on either side. | ||
| return lit.IsNaN() || | ||
| ((!has_lower || *lower <= lit) && (!has_upper || lit <= *upper)); |
There was a problem hiding this comment.
I don't think there's a bug here, but in terms of readability I'm wondering if we can do something better..
This evaluator is checking any row in the file could match the predicate. Anytime we return false, constexpr bool kRowCannotMatch = false; means we can prune away / skip the entire file.
Since the Literal uses partial ordering, so these comparators <= >= could willy nilly return false based on the literal value and the bound values, and if the values cannot be compared, then incorrectly prune the file.
There was a problem hiding this comment.
thinking through a bit more, perhaps we could structure this check like so:
auto outside_bounds = [&](<const Literal& lit>) {
// Logic to check if `lit` is definitely outside bounds..
// If a comparison is unordered or uncertain, return false (treat as inside bounds) to be safe.
};
return std::ranges::all_of(literal_set, outside_bounds) ? kRowCannotMatch
: kRowsMightMatch;
While reviewing #1153, I noticed that the inclusive IN evaluator stopped as soon as it found a missing lower bound. For example, a file with an upper bound of 50 was still read for id IN (51, 70).
Use each available bound to rule out candidates. Add regression tests for candidates above the upper bound, a candidate equal to it, and a NaN candidate that the upper bound cannot rule out.