Skip to content

R2RML graph sources return a triple once per source row; an RDF graph holds it once #2238

Closed

Description

@aaj3f

Problem

An R2RML graph source returns a triple once for every source row (or every triples map) that produces it, rather than once. The common way to hit this is a dimension table that keeps one row per historical version of an entity:

customers_history(customer_id, name, valid_from)
  42, "Ada", 2024-01-01
  42, "Ada", 2025-03-01

mapped as

<#Cust> rr:logicalTable [ rr:tableName "customers_history" ] ;
  rr:subjectMap [ rr:template "http://ex.org/customer/{customer_id}" ; rr:class ex:Customer ] ;
  rr:predicateObjectMap [ rr:predicate ex:name ; rr:objectMap [ rr:column "name" ] ] .
  • SELECT ?s ?n WHERE { ?s a ex:Customer ; ex:name ?n } returns customer/42 "Ada" twice.
  • SELECT (COUNT(?s) AS ?k) WHERE { ?s a ex:Customer } returns 2.

The same thing happens across tables: when two triples maps over different tables (say customers_current and customers_history) mint the same subject and class, each of them contributes its own copy. On a real mapping of this shape we saw one entity's rdf:type and key property come back 19 times, and every attribute from the history table 9 times. That makes COUNT, SUM and AVG silently wrong unless every query remembers DISTINCT, which agent-written queries won't do reliably.

Expected

R2RML §11 defines the output of a mapping as an RDF dataset, and an RDF graph is a set of triples (RDF 1.1 Concepts §3). So each triple should appear once: one row and a count of 1 above. A native ledger loaded from the same mapping already behaves that way, which means the virtual and materialized answers for the same data disagree today.

Where (at ca682e2b8)

  • fluree-db-query/src/r2rml/operator.rs:902-934: maps are merged only when they pass same_source_row + mints_alike (fluree-db-r2rml/src/mapping/triples_map.rs:200-230). feat(sql): pushdown lane M3 — subject policies, expressions, sub-selects, unions, HAVING #1788 added that rule and notes that maps deriving the same value differently still each return it. There's no row-level dedupe anywhere.
  • fluree-db-query/src/r2rml/fused_aggregate.rs:1674-1704: the fused COUNT path requires exactly one matching triples map, so a class mapped from several tables falls back to a union of full scans. :1812-1835: the manifest row-count shortcut counts rows, which equals the triple count only when every row mints a distinct subject.

Possible directions

This needs a decision, because dedupe isn't free (see #2223 for the cost side):

  1. Dedupe produced (s, p, o) per pattern whenever the subject template isn't provably unique per row, and union-then-dedupe across maps for ?s a C.
  2. Let a mapping declare a key (an Iceberg identifier field, or an annotation), so dedupe and the COUNT shortcut stay free when uniqueness is declared, and the shortcut is declined when it isn't.
  3. Keep bag output but document it, and at minimum stop the COUNT fast paths from presenting row counts as triple counts.

Whichever we pick, a native-ledger oracle differential with a duplicate-row fixture would pin it.

Related: #1583 (the referencing-object-map side of set semantics), #1788, #2223.

Activity

  1. added
    bug
    P2
    triage:needs-decision
    area:iceberg
    area:query
    on Nov 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2area:icebergarea:querybugtriage:needs-decision

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions