Skip to content

Streaming queries can't read named graphs under policy or at a time pin: no streaming entry point takes a prepared GraphDb #1996

Open

Description

@aaj3f

A ledger-scoped streaming query only sees named graphs when it runs unscoped at head. With a policy in play, GRAPH <g> and GRAPH ?g stream 0 rows, while the buffered /query/{ledger} returns them. "A policy" here includes an identity header, a policy class, or just the ledger's own configured f:policyDefaults. A time pin isn't supported at all. I think the root of it is that there's no streaming entry point that takes a prepared GraphDb, and I'd love for us to add one.

Where (main @ e4793617f)

  • Fluree::run_stream_query takes a LedgerState and rebuilds GraphDb::from_ledger_state(&ledger) inside (fluree-db-api/src/view/stream_query.rs:153). That's head, with no policy. So a policy-wrapped view, or a view at an earlier t, can't go down the single-view streaming path.
  • The route therefore sends any policy-scoped query down the dataset path, with a spec holding only the ledger's default graph (fluree-db-server/src/routes/stream_query.rs:321-343). plan_with_ledger_defaults does the same when the ledger's configured policy isn't root: DataSetDb::single(graph) (:455-480). A dataset with no named members has no named graphs, so GRAPH matches nothing, and nothing says so.
  • The route already refuses a time pin in the ledger path for exactly this reason, per its own comment: "The streaming dataset path does not enumerate a ledger's named graphs under GRAPH ?g, so a pinned read here would silently drop them" (:266-273).
  • The buffered path doesn't have the problem. query_tracked_with_options takes a &GraphDb (fluree-db-api/src/view/query.rs), so a wrapped or historical view keeps its named graphs and builds a within-ledger dataset for FROM / FROM NAMED.

Who hits it

  • fluree/solo's /v1/fluree/stream/query/{ledger} (the CLI's --stream). Solo always carries policy, since the gate forces the bearer's identity in, so GRAPH ?g streams 0 rows there on every signed-in request. Live on solo's fix build: GRAPH ?g streamed 0 rows, while the default-graph query streamed its 1 row. fluree/solo#1302 fixed the buffered route by querying the prepared ledger view directly, the way execute_sparql_ledger does. Streaming is the piece it couldn't fix.
  • db's own server, for any identity-scoped or config-governed streaming query. That part is from code; I didn't run it live on db.

Direction (more of a proposal than a spec; happy to be told there's a better seam)

  • A streaming run over an owned, prepared view, e.g. run_stream_query_view(view: GraphDb, plan: StreamQueryPlan, tracker, options, tx). plan_stream_query_with_options(&GraphDb, …) already exists. GraphDb is Arc-backed, and DataSetDb already carries them into the producer task, so owning one there seems fine.

  • The streaming route could then do what the buffered one does:

    • open the view, at the pin if there is one;
    • apply wrap_policy, or wrap_policy_defaults when there are no policy inputs;
    • plan and run it.

    Named graphs would be visible, pins would work, and plan_with_ledger_defaults would no longer need the dataset fallback.

  • A dataset clause naming only the ledger's own graphs could go the same way, if the view-based planner builds the within-ledger dataset as the buffered path does. FROM naming another ledger would stay on the dataset path.

  • Same caveat as today's run_stream_query: not wrapped by the residency retry loop.

The alternative I looked at and would rather avoid: have the dataset path enumerate every registered named graph as a member (graph_registry.iter_entries()), each loaded and policy-wrapped. It works with today's API, and a caller like solo could even do it from outside. But it costs a view load and a policy wrap per named graph on every streaming query, and one-graph-per-document ledgers can have thousands.

Related: #1279 / #1292 (the buffered ledger route's version of this, fixed), fluree/solo#1272 / #1302.

Activity

  1. added
    enhancement
    area:server
    area:query
    on Sep 30, 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

    area:queryarea:serverenhancement

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions