Repository navigation
Conversation
|
|
||
| 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.
There was a problem hiding this comment.
Agreed, added an inline comment. If either bound is NaN, we now treat both bounds as unreliable and skip bounds-based pruning.
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.
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;
There was a problem hiding this comment.
Adopted. A bound rules out a candidate only when the candidate is strictly below the lower bound or strictly above the upper bound. An unordered comparison can't establish either condition.
4176238 to
82deb57
Compare
…With when lower bound is missing (#1187) ### Problem Follow-up to #1156 and #1177. In InclusiveMetricsEvaluator::StartsWith, if lower_bounds is missing, the evaluator returns kRowsMightMatch immediately and skips the upper_bounds check. For example, a file with no lower bound and upper_bounds = "dC" is still read for `StartsWith("required", "e")` or `StartsWith("required", "dCa")`, even though no value in the file can match. ### Fix - Only run the lower-bound check when `lower_bounds` is present and non-null, and still fall through to prune against upper_bounds - Use `std::string_view::compare(0, prefix.size(), prefix) > 0` for the lower bound and upper_str < prefix for the upper bound. This matches the StrictMetricsEvaluator::NotStartsWith implementation from #1177. ### Tests Add basic unit tests.
…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.
Binding rewrites a singleton IN to equality. Use the same bounds and NaN counts for both paths so a file can be skipped only when every candidate is excluded. Ignore both bounds if either is NaN.
82deb57 to
7c2aa3f
Compare
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.