Repository navigation
fix(iceberg): a pushed FILTER literal keeps only rows it can compare exactly - #2186
Conversation
…exactly The Arrow row filter evaluates a pushed comparison on each decoded batch before the engine sees it, so it may keep extra rows but must never drop a true match: a dropped row never reaches the in-engine FILTER. It cast the literal into the column type with Arrow's safe cast, which is lossy: - A decimal literal below one built a Decimal128 whose scale exceeded its digit-count precision and panicked the reader (`FILTER(?d >= 0.05)` on a decimal(38,9) column, BigQuery's NUMERIC). - Reducing a decimal's scale rounds, so `?d < 1.0500000001` on decimal(38,9) lost the row 1.050000000. - A literal outside the column's range casts to NULL, not an error, so the keep-all fallback never fired and `?d < 1000` on decimal(5,2) lost every row. The same shape applies to any narrowing cast. The literal is now converted once per file into the column's comparison type and accepted only if the result is non-null and casts back unchanged; otherwise that comparison keeps every row and the in-engine FILTER decides. A literal has no precision of its own, so `ScanValue::Decimal`, `LiteralValue::Decimal` and `TypedValue::Decimal` no longer carry one. Its only reader was the Arrow literal builder, which now builds at decimal128's full precision; every other consumer ignored it. Column types keep theirs.
|
Two follow-ups — neither is a regression from this PR, so a follow-up issue is fine for both. 1. A lossless conversion can still compare differently.
A type-family check in 2. Keep narrowing when a literal is inexact (optional, perf). A literal with no exact value in the column now keeps every row for that comparison. Range ops could still narrow by rounding in the safe direction and adjusting the operator — |
bplatz
left a comment
There was a problem hiding this comment.
Approving. The round-trip check closes all three failure modes in #2185 — the panic, the rounding cast, and overflow to NULL — decimal_literal can no longer panic, and dropping precision is safe since nothing serializes these types. The unit test computing the oracle in integer arithmetic rather than through Arrow is the right call.
Some feedback in the comment above: two follow-ups, neither a regression from this PR.
…rders as the engine The exact-conversion check proves a literal survives the conversion into the column's type, not that the column then orders values as the in-engine FILTER does. Two shapes passed it and still dropped true matches: - A literal of another kind than the column. An integer converts exactly to a string column's "1000", which then compares as text, where an `xsd:integer` map over that column compares numbers: `FILTER(?n < 1000)` lost "999", "50" and "7". `true` against a column holding "1" lost the row an `xsd:boolean` map reads as true. A comparison now runs only between a literal and a column of one kind (integers also with decimals and floats); a string against a date or timestamp column, which the engine orders by parsing it as that type; and a string by `=` against any other column, where the round trip makes it the rendering of the value it matches. A decimal and a float no longer compare: 0.1 round-trips through a double by rounding back, and the engine compares the two exactly. - A zero against a float column. arrow-ord orders floats by IEEE totalOrder, so -0.0 < 0.0, where the engine holds them equal: `FILTER(?d >= 0)` lost the -0.0 row, and `= 0` too. The ordering operators now compare with the zero of the sign on which totalOrder agrees (`< -0.0`, `>= -0.0`, `<= 0.0`, `> 0.0`); equality with a zero keeps every row. Chosen per file when the comparison is prepared, so the per-row kernels are unchanged. The local fixtures gain `silver.literals`: numeric and boolean text, and a double column with both zeros. Every case runs on SPARQL and JSON-LD.
…the row filter A literal a `decimal(p, s)` column cannot hold exactly kept every row for its comparison. It is now restated on the column's grid, in integer arithmetic rather than by a cast: a literal between grid points `lo < x < hi` holds for the cells at or below `lo` (`<`, `<=`) or at or above `hi` (`>`, `>=`), so `< 1.0500000001` on decimal(38,9) is `<= 1.050000000` and `> 1.0499999999` is `>= 1.050000000`; no cell equals it, so `=` drops every row. A literal on the grid but beyond the column's precision compares as itself (`< 1000` on decimal(5,2) keeps every row, `> 1000` none), and one beyond i128 saturates, which can only keep extra rows. Integer literals against a decimal column take the same path at scale 0. An exhaustive test checks every value of a decimal(2,1) column against literals of scale -2 to 4 on, between and around its grid points, its limits and zero, and beyond i128, for every operator, against an exact oracle.
|
Thanks @bplatz — both of these were right, and since they fit the PR's theme I folded them in here rather than filing follow-ups ( 1a, an integer literal against a physically 1b, −0.0 on a 2, narrowing an inexact literal. I know you flagged this as optional, but it turned out bounded enough to do properly: Every new test fails with its fix reverted. One merge note: this and #2193 both edit the decimal pushdown — this PR drops |
…hdown-literals
Conflicts: it_iceberg_local_fs.rs and write_local_iceberg_table.py, both
sides' additions kept (the decimal and literal FILTER tests and the subgraph
crawl tests; the amounts, literals and cells fixture tables).
Seam: a decimal literal carries no precision on this branch, so the
rendered-cell equality literal from main is built as `{ unscaled, scale }`.
The cell it renders through keeps the column's precision, which
`decimal_precision_scale` still supplies.
…hdown-literals Conflict: it_iceberg_local_fs.rs, both sides' tests kept (the decimal and literal FILTER tests, and the manifest row-count tests).
Brings #2247, #2232, #2246, #2248, #2245, #2230, #2205, #2231, #2255, #2219, #2209, #2207, #2190, #2216, #2186, #2215, #2213, #2184, #2210, #2206, #2198, #2187, #2183, #2200, #2193, #2199, #2196 and #2145 into next. Resolutions: - Novelty: main's fact-state trim (a cutoff plus a bounded sweep) and the dictionary's coverage watermark sit on next's graph slots and per-graph OrdMaps. A commit's reification links count toward coverage. Planner stats from segment sums decline under annotations, whose link deltas only the walk counts, and otherwise carry the indexed link counts. - Stats-view identity: the index root's id reaches the snapshot through next's root decoder (`decode` takes the id, as `take_snapshot_metadata` does). `LedgerState::load_record` has a decoding-root form beside `load_decoding_root`. - Transact: #2184's parallel-relationship check runs in next's link cascade, counting the `rdf:reifies` links on the retracted edge that the transaction does not retract itself. Main's bundle `edge_reifiers` is dropped, and `subjects_with_prior_rows` and `enforce_single_target_reifiers` stay deleted. The upsert pre-check takes main's dictionary probe and bounded seek. - Query: geo search resolves the graph's POST tree once at open (pooled graphs keep their filter), an empty manifest when there is none. `branch_or_none` reads the dedicated branch, and the batched joins keep next's pooled lanes. The stats-view key hashes the root id. - Indexer: `apply_dict_novelty` and `compact_forward_streams` take the cycle's compaction budget, so the term dictionary keeps its reserved share. `Prefetched` holds `ContentBytes`. `relocalize_sorted_commit` rewrites next's 20-byte types records. - Disk cache: main's in-flight write registration, with an empty entry still read as crash debris that a write replaces. The process-wide eviction walk stays removed. - Graph import (#2232): fenced CAS and publishes, the seed carries the record's namespace and fence, 32-bit graph ids and next's loaders. An import into a graph of an existing ledger refuses triple terms and edge annotations: the splice merges no triple-term dictionary yet. - Iceberg: `create_iceberg_graph_source` goes with main (a source needs a mapping); the R2RML path keeps next's `model_instance`. - CLI: main's shared import flags without the leaflet flags; `graph import` routes through next's process-wide server routing, and `upload_source_import` serves next's `Destination`. Doc sources read a ledger through the command's open instance. - Tests: sibling ledger ids become distinct names, `genesis_ledger` is awaited, Cypher state dumps include each relationship's `rdf:reifies` link, and the graph-import arena test checks the refusal instead.
Iceberg: a pushed FILTER literal keeps only the rows it can compare exactly
Fixes #2185.
The Arrow row filter evaluates a pushed comparison on each decoded batch before the engine sees it, so it may keep extra rows but must never drop a true match: a dropped row never reaches the in-engine FILTER. It used to cast the literal into the column's type with Arrow's safe cast, which panicked for a decimal literal below one (
FILTER(?d >= 0.05)on BigQuery'sdecimal(38,9)), rounded when it reduced a decimal's scale (?d < 1.0500000001lost the row1.050000000), and turned an out-of-range literal into NULL, which dropped every row (?d < 1000ondecimal(5,2)). The last two were wrong results on main with no error at all.prepare_comparisons,fluree-db-iceberg/src/io/arrow_reader.rs) and only used if the result is non-null and casts back to the original unchanged (exact_literal). Anything else keeps every row for that comparison, with adebug!breadcrumb, and the in-engine FILTER decides. The check doesn't know about decimals specifically, so integer narrowing and a sub-millisecond instant against a millisecond timestamp column are covered the same way.decimal128(38, s)(decimal_literal), with a negative scale rescaled exactly to 0 and anything nodecimal128can hold refused, so building it can no longer panic.precisionis gone fromScanValue::Decimal,LiteralValue::DecimalandTypedValue::Decimal. A value has no precision of its own; the only reader was the Arrow builder above, and every other consumer (decimal_cmp, the SQL renderer, the Delta bridge, the operator) already ignored it. Column types (FieldType::Decimal,Column::Decimal) keep theirs. The "precision is cosmetic" comment that led here goes with it.I didn't run a benchmark for this. The literal cast moves from once per batch to once per file, and the per-batch work is otherwise the same comparison, so I don't expect a regression, but that's an argument, not a measurement.
Tests
row_filter_tests::decimal_literals_keep_exactly_the_true_matches_or_everything. Every op over adecimal(38,9)column, against literals on, between and beside its grid (0.05, -0.05, 0.0500000001, 0.0499999999, 1.0500000001, 4E+2, 1E-50). An exact literal must keep exactly the true matches (computed in integer arithmetic, not by Arrow); one the column can't hold must keep every row.an_out_of_range_literal_keeps_every_row,a_lossy_conversion_of_any_type_is_refused,an_exact_literal_still_filters. Overflow (decimal andInt64intodecimal(5,2)/int), a timestamp truncation, and a check that the exactness test isn't a blanket keep-all.it_iceberg_local_fs::decimal_filters_answer_exactly. End to end over a new pyiceberg fixture,silver.amounts(decimal(38,9)anddecimal(5,2)columns; the generator script gains the table), in SPARQL for six filters and in JSON-LD for the integer case. JSON-LD has no decimal FILTER literal (a fractional number parses as a double, which isn't pushed against a decimal column), so the integer-overflow case is its only route into this filter.Run against
origin/main's source with this PR's tests, the integration test fails on every case it should: the panic,< 1.0500000001→[1, 2, 3, 5],> 1.0499999999→[], and< 1000→[]in both SPARQL and JSON-LD.Locally:
fluree-db-iceberg(all targets), thefluree-db-queryR2RML tests, thefluree-db-apigraph-source unit tests, andit_graph_source_r2rml,it_iceberg_local_fs,it_iceberg_policy,it_iceberg_warehouse_rootall pass, plusit_iceberg_directwithaws-testcontainers(Docker), which CI doesn't run.