Repository navigation
fix(query): every R2RML lane answers an un-annotated column the way the generic pipeline does - #2193
Conversation
`silver.cells` holds an int, long, float, double, decimal(38,9), boolean,
date, timestamp, timestamptz, binary and string column, in two data files.
The values make a column's rendered string order differently from its value
("10" before "9", -0.0 apart from 0.0, a date before 1970), repeat so there is
something to group, and leave one row null in every typed column. The second
file holds only two- and three-digit integers, so a file-level prune by the
column's numeric bounds reaches a different answer than the string
comparison an un-annotated mapping makes.
Generated by scripts/local/write_local_iceberg_table.py, whose other tables
are unchanged; only the new table's directory was copied in.
…dered string An `rr:column` with no `rr:datatype` materializes as the `xsd:string` of the cell's rendering, and the fused fold defaulted such a key to `xsd:string` to match. But it read the key straight from the batch, and a string key reads only a string column: over an integer, float, decimal, boolean, date, timestamp or binary column every cell read as null and every row dropped, so `GROUP BY` returned no rows where the generic pipeline returned one group per rendered value. This held on the single-table fold, a composite key, and a key read from the dim side of a join. A key column now reaches `key_at` only as a `KeyColumn`, which the group column builds once per batch: a string key over any other physical type is rendered there through the materializer's own `lexical_column`, so the fold groups by "10", "-0" and "0.050000000" exactly as the materialized rows do, and no read site can hand it a raw column. A string column is borrowed, so string keys cost what they did; the rendering is paid only by the shape that used to answer nothing.
…for an un-annotated column The lowering classed a column by its `rr:datatype` alone, so an un-annotated column was `Str` whatever the database held, and every check that trusts `Str` to mean text let the database order and group a `bigint`, `double`, `decimal`, `timestamp` or `varbinary` by value where the engine compares the rendered string. Against the fake Trino endpoint that gave: `MAX` of an integer column 100 where the generic answer is "9"; `ORDER BY ... LIMIT` and the grouped top-k keeping the numerically largest rows; `GROUP BY`, `COUNT(DISTINCT)` and `SELECT DISTINCT` over a float merging -0.0 and 0.0, which render apart; and joins on a value pairing -0.0 with 0.0, 10 with 10.00, and 0.05 with 0.050000000. Such a column is now `RdfClass::Rendered(type)`, from the probed schema, so the `Str` arms no longer reach it: no ordering, extreme or comparison of it is pushed, and equality (a key, a `DISTINCT`, a `COUNT(DISTINCT)`, a join) only where `database_eq_is_exact` holds — integers, decimals of one scale, booleans, dates and bytes, whose rendering the database's `=` matches. A float or timestamp key falls to the fused fold, which renders each row. An unprobed column is `Rendered(None)` and pushes nothing, where it was trusted.
…parison
Both lanes share the R2RML scan's file- and row-level pushdowns, so these
were wrong with fast paths off too, where the differential cannot see them.
Over an un-annotated integer column on two files:
- `ORDER BY DESC(?v) LIMIT 1` answered "100" where the string answer is
"9": the scan-side top-k read files by their numeric upper bound and
skipped the file holding the 9s.
- `FILTER(?v < "5")` and `FILTER(?v > "50")` lost rows: the reader cast the
string literal to the column's type and filtered by value, though "10" <
"5" as strings.
`ScanTopK` now says whether the engine orders the column's rendered string
(`lexical`), and the provider admits such a directive on a string column
only. A string literal pushes to a string column, or by `=`/`IN` to an
integer or date column when it is exactly how a cell renders ("10", never
"010"), checked through the materializer. A boolean or integer constant no
longer pushes to a string column, where the cast text misses the cells the
operator's loose match keeps ("1" for true, "010" for 10). A `!=` against a
non-string literal no longer pushes for a string-compared column: a string
never equals one, so `!=` keeps every row the physical comparison would
prune. String columns and canonical integer keys prune as before.
…ipeline does One binary, two sources with one column of every physical type: the local Iceberg `cells` table (the fused aggregate and the scan's pushdowns) and the same rows on a fake Trino endpoint (the SQL block and aggregate lanes). Each shape runs per column on SPARQL and on its JSON-LD twin, with fast paths on and off: `GROUP BY` (single, composite, a key across a join, ordered with a `LIMIT` both ways), `MIN`/`MAX` (plain and grouped), `COUNT(DISTINCT)`, `SELECT DISTINCT`, `ORDER BY ... LIMIT`, comparisons with string and typed literals, constant objects, `IN`, and joins on a value. Each case pins its routing stamps: `MustFire` where a lane serves it, `MustNotFire` where it must decline, every decline paired with a shape the same lane serves on the same source. Because the scan's pushdowns run with fast paths off as well, the answers that differ from the physical order are pinned outright, and the number of data files read shows that a string column and a canonical integer key still prune.
`ntext` holds the `i32` column's values as text ("2", "9", "-3", "9" in the
first file; "10", "100", "10" in the second), for a mapping that declares a
numeric datatype over a string column. Its terms order by number while its
file bounds order by string, where "9" sorts above "100".
… again The first cut treated every rendered timestamp as unequal-safe, sending GROUP BY, DISTINCT, COUNT(DISTINCT) and joins on an un-annotated timestamp to the engine. Only a source precision finer than microseconds needs that: a value decodes to the microsecond, so a `timestamp(9)` holds instants a nanosecond apart that render alike. Trino's default `timestamp(3)`, and the `timestamp(6)` the bridge reports for Postgres and MySQL, decode exactly, and the database's `=` there is the rendered strings' equality, as it was before. The probe now keeps the declared precision: `schema_from_columns` records a timestamp's fractional digits on the `BatchSchema` (`with_fractional_digits`), and the lowering reads them into the class. `RdfClass::Rendered` carries whether its equality is exact, decided once by `rendered_eq_is_exact`; a `timestamp(p)` qualifies for p <= 6, an undeclared precision does not. The class also carries a language tag now. A language-tagged map over a non-text column stayed `LangStr`, whose equality was trusted, so a statement grouped "-0"@en with "0"@en over a double; it is `Rendered` like the plain string, and two rendered columns are one class only in one language.
…e terms do The first cut flagged a lexical directive (an un-annotated or xsd:string column) and admitted it on string columns only, but still admitted every other directive on any column. A mapping that declares `xsd:integer` over a string column orders its terms by number while the file bounds sort as text: with "9" in one file and "10"/"100" in another, `ORDER BY DESC(?v) LIMIT 1` read the first file by its "9" upper bound, set the k-th bound to 9, skipped the other, and answered 9 where the truth is 100, with fast paths off too. The same held for a decimal, double, date or dateTime declared over text. `ScanTopK.lexical` becomes `order: TermOrder` (Lexical, Numeric, Date, Instant, Boolean), from the object map's term type and datatype (`term_order`); a datatype with no such order offers no directive. The provider admits a directive only when the column's type sorts its bounds in that order (`bound_order`): string, numeric, date, timestamp and boolean columns, and not nanosecond timestamps, whose cells hold microseconds. The SQL lanes had the same hole: `order_columns` and the MIN/MAX gate trusted a numeric, date, dateTime or boolean class over any column, so a numeric datatype over a varchar pushed `ORDER BY`/`MAX` the database answers as text. Both now go through `orders_as`, which needs the probed type to hold the class.
…g literal Defensive, unreachable today: `rewrite::cmp_op` pushes no `!=`, so no query reaches this gate; only its unit test does. The first cut kept a typed literal's `!=` off a string-compared column. It missed the mirror case, an annotated non-string term against a string literal: `FILTER(?v != "10")` over `xsd:integer` holds on every row (an integer never equals a string), but over a string column the pushed `text != '10'` would prune the rows that hold "10". The gate now pushes `!=` only when the literal's kind (`literal_order`) is the term's order class (`term_order`), so a string term with a string literal, or a numeric term with a numeric one; a datatype with no order class pushes none.
… float columns again The first cut pushed a string literal's `=`/`IN` only to integer and date columns, where it is exactly how a cell renders, and declined it on every other non-string column. On main a cast `=` there was a safe superset, so those point lookups lost their row filtering. The round trip now covers each type it can decide: the constant is read as the column's type (a boolean; a decimal at the column's own scale; a dateTime, as the cell's microseconds, for `timestamp` and `timestamptz`; a double or float) and rendered back through the materializer, and equality pushes only when the rendering is the constant. "0.050000000" pushes on a decimal(38,9) column, "0.05" does not; "1969-12-31T23:59:59.999999Z" pushes on a timestamp column, "…+00:00" does not. A float pushes only finite and non-zero values: NaN equals nothing by value, and -0 and 0 render apart but compare equal, so those still decline. Ordering by a string still pushes to string columns only.
Iceberg: a top-k over `xsd:integer` declared on the numeric-text column answers 100, reading both files, and over the long column still prunes to one file; string equality on decimal, timestamp, timestamptz, double and float columns prunes to the file holding the value, while NaN and -0 read both. SQL: the `timestamp(6)` columns group, count distinct and join in the statement again; a `timestamp(9)` column holding instants a nanosecond apart does not, and the fused fold answers one group; a language-tagged double keeps "-0"@en apart from "0"@en, a language-tagged long still groups in the statement; MIN/MAX of `xsd:integer` over text declines, over a bigint fires. The `< "5"` and `!= 10` comparisons now pin their answers, computed from a table of what each row renders as.
`self.caps` is already a reference; clippy's needless_borrow flags the `&`.
The fixture writer script conflicted: PR-A and D1 each added a table (silver.amounts and silver.cells). Both are kept, and so are both doc bullets and both sets of imports. The committed fixtures are separate directories and did not conflict. One seam with PR-A goes in this merge so that it builds. PR-A removed LiteralValue::Decimal's precision (a literal has none of its own: a comparison is evaluated against the column's decimal(p, s)), and D1's rendered_cell_literal and its test still set it. D1 now builds the literal from the unscaled value and the scale only.
bplatz
left a comment
There was a problem hiding this comment.
Approving, with feedback inline to look at before merging. The main one is a pushdown this drops that was sound on main: a plain-string range FILTER over an xsd:date map. The other two are a nit and a docs note.
The rest checks out:
- The engine treats a string-vs-number
</>as a type error and drops the row, so the mismatched-kind range filters that still push only prune rows the FILTER drops anyway.!=is the one operator that needed the gate. - String equality pushes to a typed column only through the materializer's own round trip (NaN and ±0 declined), and
timestamp_nsgets no top-k. Renderedjoins push only between identical classes; an unprobed type fails closed.- Answers are pinned to ground truth rather than lane agreement, with JSON-LD twins, routing stamps and a mutation per guard.
| ScanValue::Str(s) => match field_type { | ||
| Some("string") => LiteralValue::String(s.clone()), | ||
| _ if equality => rendered_cell_literal(field_type, s)?, | ||
| _ => return None, | ||
| }, |
There was a problem hiding this comment.
This also drops a push that was sound on main: a plain-string range FILTER over a map annotated xsd:date (or xsd:dateTime), e.g. FILTER(?d > "2024-01-01") on a date column. The engine reads a plain string as a date when it orders it against a date term (cmp_values_inner's temporal_string_coerce), and the Arrow reader casts the String literal to the column's type, so the two agreed and the rows were filtered at read time. The provider can't see the map's datatype here, so the annotated case loses its push along with the un-annotated one (which is right to decline).
iceberg.md's own Performance example (FILTER (?date > "2024-01-01")) is this shape, and Behavior changes doesn't list it.
Suggest coercing in pattern_scan_filters, where the object map is in hand: when the map is annotated xsd:date / xsd:dateTime and the string parses as that type, turn the Str into the typed ScanValue::Date / Timestamp, as coerce_scalar_for_pushdown already does for xsd:integer, and let the existing typed gates (date column only, the timestamptz frame rule) decide. If you'd rather leave it, it belongs under Behavior changes, and the docs example should use a typed literal.
There was a problem hiding this comment.
You're right, and thank you for catching it — this was a real regression for exactly the docs' own example. Fixed in 8ab945e2c the way you suggested: pattern_scan_filters now turns a plain string under an xsd:date / xsd:dateTime map into the typed Date / Timestamp when it parses the way the engine parses it (through the existing to_scan_value), and leaves the typed gates to decide, so un-annotated maps stay declined. Only the four range operators coerce, since a plain string never equals a date in the engine (= keeps no row, != keeps every row, and the != gate still runs first); it's once per pattern, nothing per row. Interestingly, main only ever filtered these rows at read time — it read the same number of files — so with the typed literal they now prune files as well. Seven new cases in it_r2rml_untyped_columns pin the rows (hand-computed, SPARQL and JSON-LD, fast and generic lanes) and the file count, and dropping the coercion fails them. The iceberg.md example now names the xsd:date annotation it relies on, and the cases that stay declined are listed under Behavior changes in the body: an xsd:dateTime map over a wall-clock timestamp column (the frame rule), any dateTime range with FLUREE_ICEBERG_TIMESTAMP_STATS off, and — newly — an xsd:date/xsd:dateTime map over a string column, which used to push a text comparison that isn't the engine's order.
| /// id, where the source reports them (`timestamp(3)`). A `Column` keeps | ||
| /// microseconds, so a field with more digits decodes distinct source | ||
| /// values to one cell. | ||
| fractional_digits: HashMap<i32, u8>, |
There was a problem hiding this comment.
Nit: ColumnBatch::project builds its schema with BatchSchema::new, so a projected batch drops these. Nothing reads precision from a projected schema today, and a missing entry only declines the pushdown, but since the field is documented as riding with the schema, carrying it through project (filtered to the kept field ids) would keep a later caller from losing it silently.
There was a problem hiding this comment.
Agreed — 95c88658a has project carry the precision entries of the fields it keeps, with project_keeps_the_kept_fields_fractional_digits.
| DECIMAL columns at the scale it was started with (`--decimal-scale`, | ||
| default 6), and SQLite's `NUMERIC` is a double. | ||
|
|
||
| **An un-annotated column the database does not hold as text** — a `bigint`, |
There was a problem hiding this comment.
Worth a line in r2rml.md too. This holds for every R2RML source, not only SQL, and the PR notes it changes answers mainly for hand-written mappings, whose authors will look there: an un-annotated rr:column reads as the xsd:string of its rendering, so add an rr:datatype to group, order and compare by value.
The type table in iceberg.md (int, long → xsd:integer, …) also reads as if that mapping were automatic; it holds for generated mappings.
There was a problem hiding this comment.
Done in 62904b72c: r2rml.md now says, beside the ex:customerId "1" example, that an un-annotated rr:column reads as the xsd:string of its rendering and that rr:datatype is what makes it group, order and compare by value. And you were right that the iceberg.md table read as automatic — it now says it's what generated mappings declare. It was also a bit off against the generator itself (naming::xsd_datatype): float and double are xsd:float / xsd:double, not xsd:decimal; decimal, binary/fixed → xsd:hexBinary and timestamptz were missing; and uuid, time and nested columns are skipped by the generator rather than mapped to xsd:string, so those rows are fixed too.
… again
On main a plain string pushed to any column as a string literal, which the
Arrow row filter cast to the column's type: `FILTER(?d > "2024-01-01")` over
an `xsd:date` map was filtered at read time. The first cut sends a string
only to string columns, or by equality to a cell that renders as it, so that
shape lost its pushdown along with the un-annotated one, which is right to
decline.
The engine orders a plain string against a date or dateTime term by parsing
it as that type. `pattern_scan_filters` now does the same where the object
map is in hand: under `xsd:date` or `xsd:dateTime`, a string that parses
becomes the typed value a typed FILTER literal would, and the typed gates
decide (a date only against a date column, a dateTime only in its column's
frame). The push now prunes files by their bounds as well, which the cast
string never did. Only `<`, `<=`, `>`, `>=` coerce: a plain string never
equals a temporal, so `=` keeps no row and `!=` every row.
Still declined: a dateTime map over a wall-clock `timestamp` column (frame
rule), any dateTime with FLUREE_ICEBERG_TIMESTAMP_STATS off, and a date or
dateTime map over a string column, whose text order is not the engine's date
order ("2024-01-15Z" is 2024-01-15).
… is the generator's r2rml.md now says, beside the mapping example that produces `ex:customerId "1"`, that an `rr:column` with no `rr:datatype` reads as the `xsd:string` of its rendering for every R2RML source, and that a datatype is what makes it group, order and compare by value. iceberg.md's type table read as a conversion applied at read time. It is what a generated mapping declares, and now says so; it also lists what the generator writes (`xsd:float`/`xsd:double` for floats, `xsd:decimal`, `xsd:hexBinary`, both timestamp types) and that `uuid`, `time` and nested columns are left out. The query-planning example names the `xsd:date` annotation its plain-string FILTER relies on.
…igits `ColumnBatch::project` built its schema with `BatchSchema::new`, so the projected batch dropped the source-reported precision that rides with the schema. Nothing reads it from a projected batch today, and a missing entry only declines a pushdown, but a later caller would lose it silently. The projection now carries the entries of the fields it keeps.
One conflict, docs/graph-sources/iceberg.md: main's column-type table (the datatype an un-annotated rr:column reads as, and what the generator emits) is kept, with its last row narrowed to string: uuid and time do not parse to a scan type, so the generator leaves them out like nested columns.
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.
R2RML: every lane answers a mapped column the way the generic pipeline does
Fixes #2191.
An
rr:columnwith norr:datatypeis thexsd:stringof its rendering today, and that doesn't change here. But several lanes read the physical column instead: the fused aggregate, the SQL block and aggregate lanes, and the Iceberg scan pushdowns. So they grouped, ordered and compared differently from the generic pipeline:GROUP BYreturning nothing,MAXreturning 100 where the answer is "9",FILTER(?v < "5")losing rows. The scan pushdowns run withFLUREE_DISABLE_QUERY_FAST_PATHStoo, so the fast-vs-generic differential couldn't see those (the #1700 pattern). Each lane is now pinned to the generic answer, which was itself checked with comparisons spelled so nothing can push them (STR(?v)).lexical_column, through aKeyColumntype), so a raw physical column can't reach the key reader. String andxsd:integerkeys still borrow, with no per-row allocation.RdfClass::Rendered { ty, lang, eq_exact }:=is exact on the rendering: integers, decimals at a probed scale, booleans, dates, bytes, andtimestamp(p ≤ 6)(precision now rides onBatchSchemafrom the probe).ORDER BY … LIMIT, grouped and subquery top-k,MIN/MAX) pushes only where the probed type orders the same way (orders_as).TermOrder) and prunes only by bounds that sort the same way (bound_order)."010"never matches 10.Behavior changes for annotated columns (results change only where they were wrong; the rest are pushdowns that no longer happen):
rr:datatype xsd:stringover a non-string column is now rendered in the fused fold, where it returned[], and isRenderedin the SQL lanes.stringcolumn, including annotatedxsd:integer/xsd:booleanover text. The cast text missed cells the operator's loose match keeps ("010"for 10,"1"for true).xsd:time,xsd:gYear, custom) gets no top-k, and neither do nanosecond timestamp columns.ORDER BY … LIMITandMIN/MAXof a numeric, date, dateTime or boolean datatype push only when the probed column holds that class. A numeric datatype over a varchar stays in the engine.!=scan-filter gate pushes only between a term and a literal of one order class. It's defensive:rewrite::cmp_opemits no!=today, so only its unit test covers it.<,<=,>,>=) under anxsd:date/xsd:dateTimemap is typed as that temporal when it parses (8ab945e2c), so it pushes again and now also prunes files. It stays declined in three cases: anxsd:dateTimemap over a wall-clocktimestampcolumn (the frame rule), any dateTime range withFLUREE_ICEBERG_TIMESTAMP_STATSoff, and (newly) anxsd:date/xsd:dateTimemap over a string column, which used to push a text comparison that isn't the engine's order.For the release notes:
GROUP BYover un-annotated non-string columns now answers on every lane.MIN/MAX/ORDER BY … LIMITand float grouping over un-annotated columns now run in the engine.timestamp(p ≤ 6)keys still group in the statement exactly as before;timestamp(9)keys group in the engine.Generated mappings annotate every non-string column, so in practice this changes answers for hand-written mappings.
Follow-up: #2192 (the R2RML natural datatype for un-annotated columns, and the remaining annotated declared-vs-physical mismatches this PR doesn't cover: an
xsd:integer-annotated text column read by the fused integer key, a numeric class over a varchar in SQL equality, an IRI term map over a non-text column).Tests
it_r2rml_untyped_columns(new):MustFireand 70MustNotFire.silver.cells, one column of every physical type in two files. The second file holds only multi-digit integers, so numeric-bound pruning visibly diverges from string order.orders_astables.!=gate mutation leaves the integration suite green, as expected for an unreachable gate.it_sql_pushdown_lane21 (golden statements unchanged),grp_graphsource255,grp_query552, and the Iceberg, Delta and SQL integration targets.cargo clippy --workspace --all-targets --all-features -D warnings.it_iceberg_glue_moto,it_iceberg_direct.Perf
The fused aggregate is a hot path. Measured with a release-mode probe over a 2,000,000-row Iceberg table in 4 files, before (
fused_aggregate.rsfrom main) and after, three alternations of 11 timed runs on a loaded machine. Medians, in ms:xsd:integerkey (1000 groups)The string- and integer-keyed paths are unchanged within noise. The previously empty shape now answers, about 14× faster than the generic lane. Iceberg point lookups by a string constant on a typed column: about 8 ms, against 8.3 ms on main.