Skip to content

fix(r2rml): PR-0 — loud-refuse silent-empty virtual sub-scopes (breaking: previously silent-empty queries now error) - #1476

Closed
aaj3f wants to merge 6 commits into
bench/virtual-dataset-corpusfrom
perf/r2rml-pr0-correctness
Closed

aaj3f wants to merge 6 commits into
bench/virtual-dataset-corpusfrom
perf/r2rml-pr0-correctness

Conversation

@aaj3f

@aaj3f aaj3f commented Jul 11, 2026 •

Copy link
Copy Markdown
Contributor

First PR of the virtual-dataset perf roadmap (docs/audit/2026-07-virtual-dataset-perf/ROADMAP.md, PR-0). Correctness before performance: converts silently-wrong empty results into loud, actionable errors.

Breaking behavior (release notes): queries with a transitive property path (+/*) or subquery inside a GRAPH scope over an R2RML/virtual source previously "succeeded" with 0 rows; they now fail with InvalidQuery and guidance. The old behavior was the bug — no kill switch by design. Labeled breaking-change for the release-notes section.

Fixes

0a — Silent-empty guard (findings F1/F2). Transitive property paths (+/*) and subqueries inside a GRAPH scope over an R2RML source aren't lowered to R2RML and silently evaluated against the source's empty native index — returning 0 rows as success (q034: 0 vs native 4,514; q051: 0 vs 247). The whole-scope guard counted only top-level unconverted triples; sub-scopes escaped it. Now the scope fails with the same InvalidQuery shape. Patterns that only transform bound solutions (FILTER/BIND/VALUES/UNWIND) and self-routing search patterns are deliberately not flagged; sequence paths (a/b) are unaffected (decomposed upstream). No lowering attempted — that's a later capability PR.

0b — Bound-subject wildcard rdf:type (finding F3) — landed on main ahead of this PR. Originally part of this batch; during the #1450 review response it was generalized to both wildcard shapes (1c0064f, operator.rs, with unit test bound_subject_wildcard_emits_rdf_type) and reached main when #1450 merged. After the restack this PR's diff no longer carries it (operator.rs here is byte-identical to main); the corpus q042 hash-parity blessing rides in #1475. Recorded here for the roadmap paper-trail: <iri> ?p ?o emits the rr:class-derived type triple (q042: 24 rows, hash-parity with native).

Review response (2026-07-13)

  • fmt (blocking): cargo fmt --all -- --check is clean workspace-wide at HEAD (rustfmt from stable 1.97.0, what CI resolves). The flagged operator.rs drift left this PR's delta with the restack; the remaining violation (VALUES negative-case test) is fixed.
  • Duplicate error blocks: the two copy-identical GRAPH-scope InvalidQuery blocks (seeded + batched paths) are now a shared rewrite::unsupported_subscope_error, placed next to the R2rmlRewriteResult::unsupported field whose contract it implements.
  • Kind dedup: repeated kind names collapse in the message ("property path", not "property path, property path"), first-seen order preserved, unit-tested. Message text otherwise unchanged; the corpus harness gates on error status, so no blessing churn.
  • Fused-aggregate invariant: comment added at the single-[Pattern::R2rml] shape gate documenting why the third rewrite_patterns_for_r2rml caller is decline-safe against non-lowered sub-scopes (falls back to the normal GRAPH path, which raises the loud error).
  • Release-notes surface: retitled + breaking-change label (the repo's .github/release.yml categorizes by label).
  • Restack rider: the bench: virtual-dataset performance corpus, harness, baselines + audit (pre-work for the perf PR series) #1475 review response added a corpus unit test pinning "no query declares virtual=error"; this PR's manifest deliberately flips q034/q051, so that test failed at this HEAD after the restack. Updated it to pin exactly [q034, q051] (both still ok on native).

Validation (per the roadmap DoD)

At current HEAD (724d255): cargo fmt --all -- --check clean; scoped clippy clean (fluree-db-query, fluree-bench-virtual); fluree-db-query 1254/1254; fluree-bench-virtual 33/33.

From the pre-restack validation (details in commit history, unchanged by the review response): fluree-db-api full suite (all grp_* bins) 0 failed; W3C SPARQL suite unregressed (3 pre-existing syntax-bin failures proven pre-existing by stash-and-rerun); corpus native 54/54 with 0 hash mismatches vs blessed oracles; virtual-SF01 targeted: q034/q051 fail loudly (expected_status enforced by the harness), q042 24 rows hash-parity with native; 3 native micro-query perf "violations" (1.1–1.2×, 1–27ms absolute) exonerated by base-binary A/B.

Notes / follow-ups (non-blocking)

  • Exotic <iri> ?p <class-iri> (bound-object) shape still misses the type row — noted in ROADMAP residuals.
  • Harness follow-up: per-query budgets need an absolute floor (10% of 8ms is a 0.8ms tripwire) and baselines should be re-blessed same-day before gating.
  • CI note (stack-wide): ci.yml triggers only on PRs whose base is main, so the gates above are local until the stack retargets. fluree-bench-virtual has one remaining clippy warning (too_many_arguments, bench: virtual-dataset performance corpus, harness, baselines + audit (pre-work for the perf PR series) #1475-scope, non-gating today).

Stacks on #1475 (harness/baselines/audit). Roadmap PR-1 (#1478, COUNT(*) manifest shortcut) follows.

aaj3f added 2 commits July 11, 2026 17:18
A PropertyPath (transitive +/*) or Subquery inside a GRAPH scope over an
R2RML source is not lowered to R2RML leaves and evaluates against the
source's empty native index, silently returning zero rows as success
(corpus q034: 0 vs native 4,514; q051: 0 vs 247). The whole-scope guard
counted only unconverted top-level triples, so sub-scopes escaped it.

Track non-lowered sub-scope kinds (property path, shortest path, subquery)
through the rewrite recursion and fail the GRAPH scope with InvalidQuery,
matching the unconverted-triple guard. Patterns that only transform bound
solutions (FILTER/BIND/VALUES/UNWIND) and search patterns that route by
their own graph_source_id are deliberately not flagged. No lowering is
attempted here; this converts silent-wrong into loud-refuse only.

Corpus: q034/q051 expected_status flips to virtual=error.
<iri> ?p ?o over a virtual dataset returned the POM data predicates but
omitted the rr:class-derived rdf:type triple (corpus q042: 21 vs native 24
rows; the UI subject inspector showed no @type for virtual subjects). The
subject-var wildcard path already binds the class; the bound-subject
prefix-prune branch skipped class emission.

Emit ?p=rdf:type / ?o=<class> per matching TriplesMap class in the
bound-subject true-wildcard materialization, gated to a variable predicate
with no predicate filter and no fused type-var, and only for a matched
subject row (dangling IRIs still produce nothing).
aaj3f added a commit that referenced this pull request Jul 13, 2026
… single-scan crawl, tracked-terminal interception

Query-path response to bplatz's #1450 review comments 1-5.

1. True wildcards emit the rr:class rdf:type triple (native parity). The POM
   loop materialized only data predicates, so `<iri> ?p ?o` (the subject
   inspector) and `?s ?p ?o` never returned the subject's type. The operator
   now emits one rdf:type row per declared class for any true wildcard
   (predicate_var set, no predicate_filter, no projected type_var — a fused
   type-var pattern already carries the class, no double emission). Supersedes
   the bound-subject-only version staged in #1476, whose operator.rs hunk
   should be dropped on restack (its test remains valid).

2. Templated/column (non-constant) predicates bind ?p per-row. Previously a
   non-constant predicate left ?p unbound while still pushing ?o — a malformed
   solution. New materialize_predicate_from_batch (mirrors the subject/object
   batch helpers) expands the predicate from the row; a NULL referenced column
   means the triple does not exist, so the POM is skipped — never a half-bound
   row. Constant predicates keep the zero-cost as_constant() fast path.

3. The browse crawl is ONE budgeted scan. The injected `?s a ?type` was a
   REQUIRED join — inner-joining out subjects whose TriplesMap declares no
   rr:class — and the type-var merge only fired when the WHERE bound a class,
   so a plain unfiltered crawl kept a standalone type-var scan sitting topmost
   on the LIMIT budget (the exact starvation 6fdcedb fixed, but only for
   class-bound crawls). The Wildcard crawl no longer injects the type pattern:
   the wildcard's own rdf:type rows (1) carry the classes and the regroup folds
   `?p == rdf:type` into @type. Class-less subjects survive; multi-class cost
   becomes +1 row per class per subject instead of x-classes per (p,o) row.
   The Predicates+@type shape keeps its star-collapsed type member. The
   rewrite-side merge machinery is left in place (now unreachable from crawls).

4. Crawl OFFSET hardening: MAX_CRAWL_OFFSET_SUBJECTS (10k) errors with
   guidance past browse depth instead of quietly launching an O(offset) remote
   scan, and the ordering comment is rewritten as best-effort (first-seen scan
   order is not enforced across separately-executed requests; keyset/cursor is
   the real answer for a first-class pagination surface).

5. The alias-path execute_tracked now intercepts crawls. d4d9930 wired the
   three FromQueryBuilder terminals but GraphQueryBuilder::execute_tracked
   still fell through to native hydration and returned [] under tracking
   headers. It now expands identically (200 + empty tracking). The snapshot
   builder is deliberately not wired: graph sources are not loadable into
   materialized snapshots.

Also: bound_subject_variable_predicate_binds_predicate_var becomes a
#[tokio::test] — it builds a Fluree, and main's builder (merged in 2581847)
now spawns the cache-event listener, which panics without a runtime. This was
the single CI `test` failure on the merged head (9,576/9,577).

Tests: bound/var-subject wildcard type-row units, templated-predicate
bind-or-skip unit, engine_e2e_wildcard_binds_predicate_var updated 9 -> 12
rows (3 subjects x (3 POMs + 1 type)), offset-ceiling e2e, and the 19 crawl
unit/e2e tests (multi-class, vertical-partition, subject parity, scan count,
offset, LIMIT) all passing through the single-scan plan.
aaj3f added 4 commits July 13, 2026 18:01
…ctness

# Conflicts:
#	fluree-db-query/src/r2rml/operator.rs
The #1475 review response added error_boundary_queries_match_observed_behavior
asserting NO corpus query declares virtual=error — true at #1475, but this
PR's manifest deliberately flips q034 (transitive property path) and q051
(subquery) to loud-refuse on virtual (findings F1/F2). After the restack the
base test failed at this branch's HEAD; neither the earlier validation (which
ran fluree-db-query only) nor the review caught it.

Pin the declared-error set to exactly [q034, q051] and assert both stay ok on
native, where the same shapes evaluate fine against the ledger index. The
q043/q044 error-boundary assertions are unchanged.
…kind dedup

Review items on #1476:

- Extract the two copy-identical GRAPH-scope InvalidQuery blocks (the
  seeded and batched paths in graph.rs) into
  rewrite::unsupported_subscope_error, next to the
  R2rmlRewriteResult::unsupported field it serves, so the loud-refuse
  message cannot drift between the paths.
- Dedup repeated pattern-kind names in that message (two property paths
  in one scope read "property path", not "property path, property
  path"); first-seen order preserved, unit-tested. Message text is
  otherwise unchanged, and nothing pins it (the corpus harness gates on
  error status only).
- Document the single-[Pattern::R2rml] shape gate in fused_aggregate.rs
  that keeps the third rewrite_patterns_for_r2rml caller decline-safe
  against non-lowered sub-scopes without consuming the new field.
- rustfmt: reflow the VALUES negative-case test assert — the one
  cargo fmt --all --check violation in the workspace at this HEAD (the
  operator.rs drift the review flagged left this PR's delta with the
  restack; it is byte-identical to origin/main here).

Gates at this HEAD: cargo fmt --all --check clean; scoped clippy clean;
fluree-db-query 1254/1254; fluree-bench-virtual 33/33.
@aaj3f aaj3f added the breaking-change Backwards-incompatible change; drives the Breaking Changes release-notes section label Jul 13, 2026
@aaj3f aaj3f changed the title fix(r2rml): PR-0 correctness batch — loud-refuse silent-empty sub-scopes + bound-subject rdf:type fix(r2rml): PR-0 — loud-refuse silent-empty virtual sub-scopes (breaking: previously silent-empty queries now error) Jul 13, 2026
aaj3f added a commit that referenced this pull request Jul 13, 2026
cargo fmt --all --check fails on three hunks of this PR's own delta
(fluree-db-api/src/graph_source/r2rml.rs, fused_aggregate.rs import +
manifest-shortcut block) with rustfmt from stable 1.97.0 — what CI's
dtolnay/rust-toolchain@stable resolves. CI never ran here (ci.yml
triggers only on base=main), flagged by the #1476 review stack-wide
note.
aaj3f added a commit that referenced this pull request Jul 13, 2026
cargo fmt --all --check fails on four hunks of this PR's own delta in
fluree-db-iceberg/src/io/send_parquet.rs with rustfmt from stable
1.97.0 — what CI's dtolnay/rust-toolchain@stable resolves. CI never
ran here (ci.yml triggers only on base=main), flagged by the #1476
review stack-wide note.
aaj3f added a commit that referenced this pull request Jul 13, 2026
cargo fmt --all --check fails on four hunks of this PR's own delta
(operator.rs star-fanout block, rewrite.rs disjoint-class-hint + tests)
with rustfmt from stable 1.97.0 — what CI's dtolnay/rust-toolchain@stable
resolves. CI never ran here (ci.yml triggers only on base=main), flagged
by the #1476 review stack-wide note.
@aaj3f

aaj3f commented Jul 21, 2026

Copy link
Copy Markdown
Contributor Author

Consolidating at maintainer request. #1476 (PR-0 — loud-refuse of silently-empty virtual sub-scopes, a breaking correctness fix) is carried forward in #1507 (the R2RML/Iceberg virtual-dataset performance program), which brings the #1475–#1507 lineage forward as a single reviewable unit. Its verification of record is the program's corpus benchmark, published as C2-bench-wave1.md (native == virtual, 0 hash mismatches). The pre-consolidation branch tip is preserved at tag archive/pre-refactor-2026-07-21/perf_r2rml-pr0-correctness — no history was rewritten. Closing in favor of #1507; discussion continues there.

@aaj3f aaj3f closed this Jul 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

breaking-change Backwards-incompatible change; drives the Breaking Changes release-notes section

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant