Skip to content

feat(r2rml): narrow a triples map over Iceberg with a restricted rr:sqlQuery - #2309

Merged
aaj3f merged 23 commits into
mainfrom
feat/r2rml-iceberg-filtered-logical-table
Nov 13, 2026
Merged

aaj3f merged 23 commits into
mainfrom
feat/r2rml-iceberg-filtered-logical-table

Conversation

@aaj3f

@aaj3f aaj3f commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor

Summary

A triples map over an Iceberg table can now keep only some of the table's rows. It does this with standard R2RML rr:sqlQuery, in a restricted form the source evaluates itself:

SELECT * | <col> [, <col>]... FROM <table> [WHERE <cmp> [AND <cmp>]...]
-- <cmp> := <col> <op> <literal> | <col> IS [NOT] NULL ; <op> := = <> != < <= > >=

The typical use is a history table mapped to its current rows (WHERE is_current = 1 AND is_deleted = FALSE). Before this, a mapping could only name a whole table, so it either mapped every version of an entity or needed a separate current-rows table built upstream.

Fixes #2242

Behavior

  • An Iceberg source accepts an rr:sqlQuery in the subset above at registration. Anything outside the subset is refused at registration with an error naming the construct: joins, OR, functions, sub-queries, aliases, IN, LIKE, ORDER BY and the rest. Binaries before this one refuse every rr:sqlQuery over Iceberg, so a mapping that uses one fails closed on them.
  • The filter is exact. Every row a filtered map reads satisfies its WHERE, on every lane: the generic scan, the parent scan of a referencing object map, the fused aggregates, scan-side top-k, and fluree materialize.
  • Literals are typed against the snapshot's schema at first read:
    • int/long take an in-range integer.
    • decimal(p,s) takes an integer or a decimal, compared exactly.
    • float/double take an integer within ±2^53, compared as IEEE numbers: NaN satisfies only <>, and -0.0 = 0.0.
    • string takes a quoted string, compared in code-point order.
    • boolean takes TRUE/FALSE.
    • date, timestamp, time, binary and uuid take only IS [NOT] NULL.
    • Identifiers match the schema exactly, case included, like rr:tableName and rr:column. That is a documented departure from SQL's identifier folding. Keywords are case-insensitive.
    • NaN follows IEEE, as a SPARQL FILTER over the mapped triples does. That is a documented departure from SQL engines that treat NaN as equal to itself and above every number.
  • The select list is the logical table's columns, as in R2RML. A map that reads a column its query does not select is refused at registration, naming the columns. That covers its term maps and the parent columns of a join into it. SELECT * selects every column.
  • A COUNT over a filtered map scans. The manifest row-count shortcut declines, since manifest counts cover the whole table.
  • /iceberg/materialize and /iceberg/track refuse a mapping with any rr:sqlQuery map, name the map, and point to fluree materialize. A row that stops matching the filter is never read again, so tracking could not retract the subject it produced.
  • /info reports count: null and a new, additive count-upper-bound for a filtered map, and null per-datatype counts. Its tables list the FROM table. A ref-classes count of 0 already meant "unknown"; it now also covers a reference from or into a filtered map.
  • /info bounds a reference from or into a filtered map by the child's row count only when each child row names at most one parent subject, that is, when the parent's subject columns are among its join columns. Otherwise the reference's count is null with no bound.
  • validate_r2rml and the Iceberg create response check and report the FROM table, with the query's columns. An out-of-subset query is a CompileError diagnostic.
  • The provisional-mapping lane (query_provisional_r2rml, which validates a mapping before it is registered) answers a filtered map as the registered source does.
  • The loader refuses an rr:tableName that begins with sqlQuery:, the prefix of rr:sqlQuery aliases. Readers tell the two apart by that prefix, so such a table was taken for an alias.
  • SQL graph sources still pass rr:sqlQuery text to their engine unchanged. Delta sources keep refusing it.

Design

  • The filter is exact, not a hint. A pushed query FILTER is advisory: the engine re-checks every row the reader keeps, so the reader may skip what it cannot decide. Nothing re-checks a mapping filter. So FileScanTask gains an exact_filter (ExactRowFilter), and the Arrow reader enforces it on every row whatever FLUREE_ICEBERG_PREDICATE_PUSHDOWN says. When it cannot decide a row, it fails the read rather than keep the row. The filter's columns are forced into the projection. The filter still prunes files and row groups by statistics.
  • Decimals. The filter reuses the exact decimal grid comparison from the pushdown-literal work. A decimal literal that falls between two grid points of the column equals no cell, so <> holds for every non-null cell. The exact filter maps that case to a non-null check itself. The advisory pushdown keeps its old behavior and lets the engine's FILTER drop the nulls.
  • One choke point. Each consumer resolves tm.table_name() itself. The query's alias (sqlQuery:<hash>) is therefore resolved inside the provider (FlureeR2rmlProvider::logical_scan, memoized per query) to the FROM table plus its typed filter. The snapshot pin, the caches and the build watermark are keyed by the real table, so two maps over one table read one snapshot. load_table_context treats an unresolved alias as an internal error, so a future bypass fails loudly instead of reading unfiltered rows. Registration's table check loads the FROM tables, not the alias.
  • One registration policy. The old allow/refuse flag for rr:sqlQuery is now a three-way SqlQueryPolicy: Execute (SQL), RestrictedSubset (Iceberg) and Refuse (Delta). Registration still refuses an empty mapping first, as on main.
  • No mapping-identity change. TriplesMap and LogicalTable keep their shape, so mapping_hash is unchanged for existing mappings.
Consumer For a filtered map Test
Generic scan; parent scan of a referencing object map resolved in the provider; the reader enforces the filter oracle cases names, refs, ref-join
Fused aggregate scans same scan; must-fire stamp oracle cases count, tiers
COUNT manifest shortcut declines; the count scans paired: fires on an unfiltered map over the same table (8), declines on the filtered one (3)
Scan-side top-k exact before the heap (tasks carry the filter) top-balance: the current rows' top, not the larger non-current row; files_pruned=1
Browse crawl FK shortcut declines for a query-backed parent paired: fires on an unfiltered parent (a dangling customer/99 appears), declines on the filtered one
fluree materialize (bulk) reads through the filtered scan materialize_graph over the real provider
/iceberg/materialize, /iceberg/track refused, naming the map unit + integration
/info count: null + count-upper-bound unit (incl. native + virtual merge) + integration
validate_r2rml, create response FROM table, query columns included unit
Provisional-mapping lane (query_provisional_r2rml) resolves the alias, projects the filter's columns, enforces the filter provisional answer = registered answer

Performance

On an unfiltered map, this adds one string prefix check and one String clone per scan, count and prefetch. A reader task without a row filter does no extra work. The measurement: warm unfiltered queries on the local people_window fixture (3,000 rows, 5 files), 5 interleaved base/branch pairs of 15 timed iterations each, debug build:

Query Base median / min (ms) Branch median / min (ms)
Scan, 3,000 rows 82.1 / 36.9 37.7 / 33.3
COUNT (manifest shortcut) 1.171 / 0.953 1.108 / 0.962

No regression is detectable. The branch's lower scan median is load noise, not a speedup.

Tests

  • Parser unit tests, refusals included (fluree-db-r2rml). Typing unit tests (row_filter.rs).
  • Reader tests (fluree-db-iceberg, aws feature):
    • SQL null semantics.
    • Absent columns.
    • Refusal of undecidable comparisons and of unprojected columns.
    • IEEE floats.
    • A literal beyond a promoted (int→long) column's stored range.
    • An off-grid decimal <>: the exact filter drops a null cell, and the advisory pushdown keeps it.
  • New fixtures silver.customers_history and silver.orders. The history table has two files, repeated ids, a soft delete, a null is_current, a NaN score, and a non-current row with the largest balance.
  • New own-binary test it_iceberg_filtered_logical_table:
    • Every case runs on SPARQL and on JSON-LD, with fast paths on and off, against a native ledger holding the kept rows, with the routing stamps above.
    • The crawl pairing.
    • Bulk materialize.
    • The tracking refusal.
    • Registration and first-read refusals.
  • a_provisional_query_over_a_filtered_map_answers_as_the_registered_source: the provisional lane, through a hidden test hook (query_provisional_r2rml_over_local_tables_for_test) that feeds local table directories to the lane's own scan. A catalog may not place a table on local disk, so this is the only way to reach that scan over a fixture.
  • Unit tests:
    • The select-list refusal, for a term-map column and for a join's parent column. The message is the same at registration and at alias resolution.
    • The /info reference rule: a parent keyed by (customer_id, valid_from) and joined on customer_id gives no bound.
    • The loader's refusal of the alias prefix.
  • it_sql_graph_source: the suite's Iceberg case expected every rr:sqlQuery to be refused at registration. It now registers a query in the subset, and checks that one outside it (an OR) is still refused up front.
  • Non-vacuity: each new regression test failed with its fix reverted:
    • the filter not attached to tasks
    • the filter columns not projected
    • the COUNT decline
    • the FK-shortcut decline
    • the tracking refusal
    • the IEEE float arm
    • the /info bound
    • the validator's resolution
    • the provisional lane loading by the alias, dropping the exact filter, and not projecting the filter's columns (three mutations)
    • the select-list check
    • the /info one-subject-per-key rule
    • the alias-prefix refusal
  • Lint under feature subsets: some items are used only under one feature. SqlQueryPolicy::Execute is built only with sql. Refuse and QueryTables::Alias are built only with delta. mapping_source_tables is called only with iceberg. Each allows dead code when its feature is off. So clippy is clean for fluree-db-api with iceberg,native, with sql,native, and on the wasm32 lane with no default features, not only with all features.
  • Gates, on a clean Linux box at this branch merged with main:
    • fmt (workspace and testsuite-sparql).
    • cargo clippy --all --all-features --all-targets --locked -- -D warnings.
    • CI's default-features check and server no-features check.
    • fluree-db-api clippy with iceberg,native and with sql,native.
    • wasm32 clippy.
    • Crate tests: fluree-db-r2rml (all features, so the loader's Turtle-gated tests run) 181, fluree-db-query 1,789, fluree-db-iceberg (aws) 513.
    • fluree-db-api lib (iceberg,native) 1,217.
    • Integration targets: grp_graphsource 282, grp_query_sparql 558, it_graph_source_r2rml 67, it_iceberg_local_fs 29, it_iceberg_filtered_logical_table 5, it_iceberg_policy 15, it_fused_aggregate_routing 1, it_iceberg_warehouse_root 1, it_sql_graph_source 6, it_sql_pushdown_lane 21, it_r2rml_untyped_columns 2, it_delta_local_fs 16.
    • fluree-db-server lib 225.
    • W3C suite: clippy and the full run, 85 tests.
    • 0 failed.
    • The live-bridge differential (live_bridge in it_sql_pushdown_lane and it_sql_graph_source) against SQLite, Postgres 16 and MySQL 8, as CI's sql-bridge job runs it: 5 passed, none skipped. That run was at 3e3c4d6, before the review fixes; none of those fixes touches the SQL lane, and CI repeats it.

Breaking changes (for embedders)

  • fluree_db_iceberg::scan::FileScanTask has a new public field, exact_filter. Code that builds it with a struct literal must add exact_filter: None. The constructors set it.
  • ClassInfo and PropertyStat (the /info types) have a new public field, count_upper_bound. Code that builds them with struct literals must set it. On the wire it is an additive, optional count-upper-bound key, omitted when absent.
  • An Iceberg source now accepts an rr:sqlQuery in the restricted subset. A caller that relied on registration refusing every rr:sqlQuery for Iceberg sees those registrations succeed.
  • A Delta source's query-time refusal of rr:sqlQuery has new wording.
  • The R2RML loader refuses an rr:tableName beginning with sqlQuery:, for every source type. Before this, such a mapping compiled but misread the table as a query alias on Iceberg and Delta.
  • Fluree gains a #[doc(hidden)] test hook, query_provisional_r2rml_over_local_tables_for_test. It is not part of the supported API.
  • Creating an R2RML graph source now loads its tables before publishing, and returns a 400 (Config) for an rr:sqlQuery row filter its table's schema refuses: a column the map reads missing from the select list, an unknown or miscased column, or a literal that does not type against its column. Before this, such a source registered and failed at its first query. A table that cannot be loaded at registration is skipped, so registration during a catalog outage behaves as before. The validate dry-run may report these as new errors (columnNotFound, compileError).
  • A read of an empty table now refuses a row filter its schema refuses, where it answered no rows.

Not in this PR

Follow-up: #2308. It covers two things: tracked materialization of a filtered map (via latest-by-key tombstones), and comparisons on temporal, binary and uuid columns.

aaj3f added 20 commits November 2, 2026 17:25
…als' into stack/lake-base

# Conflicts:
#	scripts/local/write_local_iceberg_table.py
…valuate

A table-reading source has no SQL engine, so it can run an rr:sqlQuery
only if it can evaluate the query itself: one table narrowed by a
conjunction of column comparisons. RestrictedSelect parses exactly that
(SELECT * or a column list, FROM a possibly namespaced table, WHERE
conditions joined by AND, each a comparison with a literal or IS [NOT]
NULL) and refuses everything else with a message naming the construct,
so a mapping is never approximated. Identifiers keep their case, as
rr:tableName and rr:column match; keywords are case-insensitive. Typing
the literals against the table is left to the source.
A pushed query predicate is advisory: the engine re-checks every row the
reader keeps, so the reader may skip a comparison it cannot state. A
mapping's row filter has nothing behind it, so FileScanTask now carries
an ExactRowFilter that the Arrow reader applies to every row, whatever
the pushdown switch says, and a comparison it cannot decide fails the
read instead of keeping rows. Nulls follow SQL (a comparison with a null
is unknown and drops the row), a column absent from a file reads as
null, and a filter column the scan did not project is an error.

Floating-point columns compare as IEEE numbers, the way the engine
compares doubles: a NaN cell satisfies only <>, and -0.0 equals 0.0.
Arrow's totalOrder kernels would keep NaN under > and split the zeros.
A literal beyond an integer column's stored range (an int column later
widened to long) is decided by the range rather than refused. Float
comparisons are left out of file and row-group pruning, since column
bounds omit NaN. An off-grid decimal <> now keeps only non-null cells.
…count

A virtual source's class and property counts come from table row counts,
which is exact only when every row of a table yields a subject. A triples
map narrowed by an rr:sqlQuery WHERE keeps some of its table's rows, and
a reference into such a map drops the rows whose parent it excludes. For
those, count is now null and a new optional count-upper-bound gives the
sum of the contributing tables' row counts (absent when one is unknown);
per-datatype counts from them are null. The native and virtual merge
carries the field. A query map's FROM table, not its alias, is listed
and counted.
…berg

An Iceberg source now accepts an rr:sqlQuery logical table in the
restricted subset, checked at registration. The provider resolves the
query alias to its FROM table and a filter typed against the snapshot's
schema at the top of every scan and count, so each consumer (the generic
and parent scans, fused aggregates, the scan-side top-k, the bulk
materializer) reads the same filtered rows, and the snapshot pin and
caches are keyed by the real table. The filter's columns are always
projected, and a column or literal the schema cannot decide is refused.

Consumers that answer without reading rows decline a filtered map: the
manifest COUNT shortcut returns no count, and the browse crawl's FK
shortcut keeps the parent scan, since a child's key may name a row the
filter excludes. The tracking materializer refuses any query map: a row
that leaves the WHERE is never read again, so its subject could not be
retracted. The validator and the create response report the FROM table.
Delta keeps refusing rr:sqlQuery; SQL sources are unchanged.
…tive oracle

New fixtures: a customers history table in two files (repeated ids, a
soft delete, a null is_current, a NaN score, and a non-current row with
the largest balance) and orders referencing it. Every case runs on
SPARQL and JSON-LD with fast paths on and off and is compared with a
native ledger holding the rows the filter keeps. Routing stamps pin the
fused aggregate and the scan-side top-k serving the filtered map, the
manifest COUNT firing on an unfiltered map over the same table and
declining on the filtered one, and the crawl's FK shortcut firing on an
unfiltered parent and declining on the filtered one. Bulk materialize,
the tracking refusal and the refusal messages are covered too.
…rule

A decimal literal between two grid points of the column equals no cell,
so <> holds for every non-null cell. The advisory query pushdown keeps
every row there, as it did before, since the engine's FILTER drops the
nulls after it; the shared decimal_check is back to that. The exact row
filter has nothing behind it, so prepare_exact now maps the case to a
non-null check itself, beside its integer-range fallback. A new test pins
the pushdown keeping a null cell under an off-grid <>; the exact path's
test already pins it dropping one.
…t dead code without them

SqlQueryPolicy::Execute is built only with the sql feature, and
SqlQueryPolicy::Refuse and QueryTables::Alias only with delta, so
clippy -D warnings failed for fluree-db-api with iceberg,native or
sql,native. Each variant now allows dead code when its feature is off.
… refuses the rest

The SQL suite's Iceberg case still expected every rr:sqlQuery to be refused
at registration. An Iceberg source now accepts a query in the restricted
subset it evaluates itself, so the case registers one and checks that a
query outside the subset (an OR) is still refused up front.
The mapping check at registration now refuses an empty mapping first (from
main) and then applies the source's rr:sqlQuery policy (from this branch).
… feature

Only Iceberg registration and the Iceberg /info path call it, so the
wasm32 lane's clippy (fluree-db-api with no default features) failed with
-D warnings on an unused function. It now allows dead code when iceberg is
off, like the rr:sqlQuery policy variants.
…ltered

The provisional-mapping lane (query_provisional_r2rml, which validates a
mapping before it is registered) handed an rr:sqlQuery map's alias to the
catalog as a table name, so a filtered mapping failed there with an
internal name while the registered source answered it. The lane now
resolves the alias to its FROM table and the query's conditions, decodes
the filter's columns, prunes files by the filter's statistics and has the
reader enforce it on every row, as the registered scan does.

Loading a table is split from scanning it, so a hidden test hook can drive
the same scan over local fixture directories: a catalog may not place a
table on this host's disk.
The row filter's float comparisons are IEEE: a NaN cell satisfies only <>,
as a SPARQL FILTER over the mapped triples does. The code said its answer
was the one any SQL engine would give, which PostgreSQL and Spark (NaN equal
to itself and above every number) contradict. The docs now list it as a
departure from SQL beside identifier case.
… reads

In R2RML a query's result columns are its logical table's columns, so a
term map, or the join of a map that references this one, can name only a
column the query selects. The select list was advisory: a map could read a
column its query left out. An Iceberg source now refuses such a map at
registration, and again when the alias resolves (a mapping registered by an
address that could not be read is first checked then), naming the columns.
SELECT * still selects every column.
…ject per key

count-upper-bound for a reference into a filtered parent was the child's
row count. That is not a bound when the parent keeps two rows with the
child's join key and different subjects: one child row then yields two
triples. A reference from or into a filtered map is now bounded by the
child's rows only when the parent's subject columns are among its join
columns; otherwise its count is null with no bound. A reference between two
unfiltered maps keeps the child's row count.
…prefix

The Iceberg and Delta readers tell an rr:sqlQuery map's alias from a table
by its "sqlQuery:" prefix, so a table named that way was taken for an
alias: an Iceberg source failed to find its query, and a Delta source
refused it as an rr:sqlQuery. The loader now refuses such a table name, so
a name can no longer be both.

@bplatz bplatz left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The filter itself looks right: every read path resolves the alias in the provider, no cache can hand filtered rows to an unfiltered map, and the shortcuts that skip a parent scan decline. Approving, but please look at the inline comments before merging — the validator one is the one I'd like fixed.

Also: the description has a "Breaking changes (for embedders)" section but the PR has no breaking-change label.

referenced.insert(col.as_str());
}
if let Some(select) = &query {
referenced.extend(select.named_columns());

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The dry-run only checks that the query's columns exist, so it calls clean two mappings that then fail:

  • A select list that omits a column the map reads (SELECT customer_id FROM t on a map that also reads name): validates clean, registration refuses it. compile_for_validate says the dry-run must not call clean what registration refuses.
  • A literal that doesn't type against its column (WHERE valid_from > '2024-01-01', WHERE score > 0.5): validates clean, registers clean, then every query touching the map fails at first read.

The second is the one people will hit — a date comparison is the first thing anyone writes against a history table. The live column types are already here (they drive the join type-mismatch diagnostic), so both can be diagnostics. Surfacing the typing error from the create response's table probe would be a fine follow-up.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @bplatz -- both reproduced exactly as you described, and there was a third one hiding next to them: a query column that only differed from the table's by case was a casingMismatch warning in validate, while the read refuses it outright. So three surfaces were each checking a slightly different subset of the same rules.

b395e0d collapses that into one function, check_query_map (fluree-db-api/src/graph_source/row_filter.rs:82), which holds everything a read checks about a map's query: the subset, the select list covering every column the term maps read (plus the parent columns of joins into the map), exact column names, and literal typing under the ExactRowFilter rules -- including the date/timestamp/time/binary/uuid comparisons that are still refused pending #2308. Validate, registration and the read all run it over the same schema (unpinned_read_schema, i.e. the one an unpinned read actually reads), so they can't drift apart again:

  • validate reports the refusal as an error carrying registration's exact message (columnNotFound for a missing column, compileError otherwise)
  • registration now loads the tables before publishing and refuses with that message as a 400 -- so the create-time follow-up you offered is done here rather than later. A table that can't be loaded at all (catalog briefly unreachable, say) is skipped, so that case still registers as before
  • the read keeps its own check as the backstop (a table changed after registration, or a source registered before this), and an empty table now refuses a bad filter instead of quietly answering no rows

validation_registration_and_reads_refuse_a_row_filter_alike runs seven bad mappings through validate, registration, a read of a source published without registration's checks, and the provisional lane, and asserts the same message from each. Disabling any one of the three sites fails it.

Some(Token::Ident { text, quoted }) => {
let is_keyword = !quoted && KEYWORDS.contains(&text.to_ascii_uppercase().as_str());
let is_refused = !quoted && refusal_for(&text.to_ascii_uppercase()).is_some();
if is_keyword || is_refused {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: a bare column that happens to spell a refused word gets that construct's message — WHERE top = 1 reports "LIMIT / OFFSET are not supported", and left / right / on / all / full report joins or DISTINCT. In identifier position the message should say to quote the column.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch, fixed in 341897b. A reserved or refused word sitting where a name goes now gets "<word> is a reserved word; to use it as a column name, quote it" -- while SELECT TOP 5, SELECT DISTINCT a and WHERE NOT a = 1 still name their construct. The refused words live in one table now, and the test sweeps every one of them, both cases, across nine name positions, so a new keyword can't reintroduce the misleading message.

"table aliases are not supported; name the table alone",
));
}
Ok(LogicalTable::normalize_table_name(&parts.join(".")))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: the loader now reserves the sqlQuery: prefix for rr:tableName, but FROM "sqlQuery:x" still yields a table with that prefix and ends at the "reached the table loader unresolved" internal error. Fails closed; refusing it here would give a clean message.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed it's nicer to stop it at the door -- 341897b has the parser refuse a FROM table that starts with sqlQuery: (quoted, namespaced or slash form) with the same wording the loader uses for rr:tableName, so it never gets as far as the "reached the table loader unresolved" internal error.

…te it

A bare column or table spelled like a refused construct got that construct's
message: `WHERE top = 1` reported "LIMIT / OFFSET are not supported", and
`left`, `right`, `on`, `all` or `full` reported joins or DISTINCT. Where such a
word stands in a name's position and is followed as a name is (an operator,
a comma, a dot, FROM or IS after a column; a dot, `;`, WHERE or the end after
a table), the refusal now says to quote it. Where it starts its construct
(`SELECT TOP 5`, `SELECT DISTINCT a`, `WHERE NOT a = 1`) the construct is
still named. The refused words are now one table, so a test sweeps every one
of them in every name position.

A FROM table spelled with the reserved `sqlQuery:` prefix (`FROM
"sqlQuery:x"`) parsed, then reached the table loader as an alias and failed
with an internal error. The parser now refuses it with the message the
loader gives an `rr:tableName` with that prefix.
…alike

The validate dry-run checked only that an rr:sqlQuery's columns exist, so it
called clean two mappings that then failed: a select list leaving out a
column the map reads (registration refused it), and a literal that does not
type against its column, such as `valid_from > '2024-01-01'` on a date or
`score > 0.5` on a double. That one registered clean too, then failed every
query at its first read. A column spelled in another case was only a
warning, though a read refuses it.

One check, check_query_map, now holds everything a read checks of a map's
query: the restricted subset, the select list covering what the map reads
(its term maps and the parent columns of a join into it), each column named
exactly, and each literal typed under the ExactRowFilter rules, including
the refusal of comparisons on date, timestamp, time, binary and uuid. All
three surfaces run it over the same Iceberg schema, the one an unpinned
read of the table reads (unpinned_read_schema: the current snapshot's,
under current names, else the current schema), so they cannot disagree.

- Validation reports its refusal as an error with the message registration
  gives: columnNotFound for a column the table lacks, compileError
  otherwise. The preview now also hands back the read schema for this.
  Only the schema-free checks run for a table that did not load.
- Registration loads the mapping's tables before it publishes, from the
  configuration it is about to publish, and refuses a mapping whose filter
  a loaded table refuses with a 400 instead of failing at the first read.
  The probe's outcome is reported as before; a table that does not load is
  left to the read.
- A read still checks against the schema of the snapshot it reads, as the
  fail-closed backstop for a table changed after registration or a source
  registered before this check. An empty table now refuses such a filter
  too, where it answered no rows. The provisional lane types its filter
  against the same unpinned read schema.

A test runs each bad mapping through validation, registration, a read of a
source published without registration's checks, and the provisional lane,
and asserts the same message.
aaj3f added a commit that referenced this pull request Nov 13, 2026
The row filter (#2309) lands before this branch, so this branch carries it
and its tests check the planning arms rewritten here.

Resolutions:
- scan/planner.rs, scan/mod.rs: a task holds the shared residual filter
  (this branch) and the exact row filter (row-filter branch); KeptFiles and
  the exact-filter types are both exported.
- io/send_parquet.rs: every decode passes the shared residual by reference
  and the exact filter beside it.
- graph_source/ephemeral.rs: the provisional scan loads a filtered map's
  FROM table and narrows its plan to the row filter (row-filter branch),
  then reads its files in the order the query owes (this branch); the same
  resolution as the integrated branch.
- graph_source/r2rml.rs (merged clean): the row filter is applied after the
  planning arms, to the tasks of whichever arm planned, so a scan-files
  cache hit (memory or disk) is narrowed as a manifest walk is.
- write_local_iceberg_table.py: both sides' tables kept.
aaj3f added a commit that referenced this pull request Nov 13, 2026
aaj3f added a commit that referenced this pull request Nov 13, 2026
Brings the planner branch's review fixes and what it now carries: the
reviewed row-filter (#2309) and scan top-k (#2313) branches, and
origin/main.

Resolutions:
- iceberg io/arrow_reader.rs: one prepared check serves both lanes. The
  row filter's comparisons and its IN sets (keyed scans: a member set
  applied row by row) and the exact row filter of an rr:sqlQuery map
  (#2309) both prepare through prepare_check, whose Check carries the
  literal as a one-element array; check_mask applies Compare (wrapping the
  literal as a scalar), Member (the set's row mask), NotNull and DropAll
  for either lane. An IN member that prepares to NotNull keeps every row,
  like any member the filter cannot compare exactly.
- query r2rml/operator.rs: the top-k tests #2313 adds are the ones keyed
  scans already carries (9d7c7ba and 88ecddc, same code); one copy is
  kept.
- api it_iceberg_local_fs.rs: the #2313 top-k cases over people_window
  likewise appear once. The paging test keeps keyed scans' shared
  paged_scan_order helper and takes the planner branch's selectOne and
  AgentJson checks and doc. The fixture list gains the tombstones table.
- scripts/local/write_local_iceberg_table.py: the planner side's blocks
  (the filtered customers_history/orders tables, versions, tombstones)
  hold keyed scans' versions block verbatim; taken once.

Parent and dimension reads stay on scan_for_lookup (no row order); every
plain scan_table left in the query crate's r2rml lane is in a test.

No test expectation changes.
@aaj3f

aaj3f commented Nov 13, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for the careful pass @bplatz -- the validator one was a good find (and turned up a third case, details in the thread). Everything's in now:

  • the validator thread is fixed in b395e0d, including the create-time refusal you'd offered as a follow-up -- validate, registration and the read now share one check over one schema
  • both nits are fixed in 341897b
  • the breaking-change label is on, and the description's breaking-changes section picks up the one new embedder-visible change: create_r2rml_graph_source now returns a 400 for an rr:sqlQuery filter its table's schema refuses, where it used to register and fail at the first query

On landing order: agreed, this and #2313 should go first. I've merged both into #2315 so the filter-vs-kept-list seam you pointed out gets resolved (and tested against this PR's own tests) there rather than in a later conflict resolution. The trivial Cargo.toml / fixture-script conflict between this and #2313 gets resolved in that merge too, whichever lands second.

@aaj3f
aaj3f merged commit a460c2a into main Nov 13, 2026
19 checks passed
@aaj3f
aaj3f deleted the feat/r2rml-iceberg-filtered-logical-table branch November 13, 2026 14:54
aaj3f added a commit that referenced this pull request Nov 13, 2026
…-iceberg-subselect

# Conflicts:
#	fluree-db-api/Cargo.toml
#	scripts/local/write_local_iceberg_table.py
bplatz added a commit that referenced this pull request Nov 13, 2026
Brings #2296, #2309, #2313, #2315, #2316, #2317, #2367, #2368, #2369,
#2373, #2374, #2378 and #2379.

Ports onto next:

- #2374 (bound-object probe reads POST): main's POST walk and per-type
  flush replace next's OPST walk. The lane keys (o_type, o_key), so next's
  triple-term handles are one more covered type (object_probe_covers takes
  TripleTermDict) rather than a flush per type; a term's matches are read
  whole, as a ref's are. The wildcard cursor still keys refs only. Pooled
  graphs decline through dedicated_branch(Post); o_i is 64-bit. Next's
  pair join keys its subject through the shared LaneKey.
- #2373 (leaflet type constant under replay): replays_history and
  o_type_const_for beside next's may_hold_keys; the row-labelling lanes
  take main's const-unless-replaying form over next's always-read-column.
- #2368: the cyclic join decodes for eager callers with next's list index
  sentinel; both reasoning tests kept (cyclic operator and pair lane).
- #2317 (GRAPH streams): main's work queue and InnerStream with next's
  pooled-graph pruning before each enumerated graph.
- #2315: list predicates are an ordered set in next's multi-ledger view;
  the annotation edge probe stays deleted (no bundle lane on next).
- #2296 (rebase reads its new line): ported onto next's fenced resets,
  erasure checks and peer sync (follow_record keeps next's unchanged-head
  arm); a non-fast-forward rebase moves head and index in one fenced
  reset.
- Main's new tests: async genesis_ledger, graph_source_store for mapping
  writes, leaf_rows for leaflets-per-leaf, storage lock off for two file
  instances. New pattern/function matches cover TermComponents and the
  triple-term functions; AnnotationTarget arms dropped.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:iceberg Iceberg catalogs/credentials, R2RML, virtual datasets, materialize breaking-change Backwards-incompatible change; drives the Breaking Changes release-notes section enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

R2RML over Iceberg: a triples map can't filter its table's rows (rr:sqlQuery is refused, and there's no alternative)

2 participants