Repository navigation
Serialize RDF onto response streams through one source - #453
Merged
Merged
Conversation
Six places serialized statements onto an output stream with the same hand-written Rio loop: find, the SPARQL CONSTRUCT/DESCRIBE path (twice), and the three N-Quads reads of resources and the context registry. They had drifted apart: the N-Quads reads closed the container's response stream, the others left it open. RdfSource is a producer that pushes statements into an RDFHandler, with two sinks: write() onto a stream, and toStreamingOutput() for a response body. Push rather than an Iterable, so the producer owns what it reads from. SparqlQueryService.graphSource() opens the pod connection only while the body is written, which is the shape a streaming producer for find can take later without the endpoint changing again. Sources carry statements only. Neither Rio.write(model, ...) nor GraphQuery.evaluate(handler) is used, because both hand the writer namespaces as well, and the bytes a client receives stay as they were. RdfSource lives in sempods-server, which already declares rio-api on api; in sempods-model it would have widened that module's published contract. RdfWriterUtil keeps its public functions and shares one loop internally. executeGraph(out) and executeGraphAsString had no caller left and are removed. No documentation describes these code paths; the change keeps every HTTP representation as it was. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: dast <der.danilo.stein@gmail.com>
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
With the streaming source in place, several helpers had no caller left: RdfWriterUtil.streamNQuads, writeJsonLd, toJsonLdGraph and the map-taking readJsonLd, SparqlQueryService.executeTupleAsJson, and the SempodsUriBuilder that FindEndpoint was injected with but never used. They were the only code in sempods-model that needed JSON: the module now depends on neither sempods-commons-json nor Jackson, and its tests declare the two for the expected-JSON fixtures they parse. A consumer that reached Jackson through sempods-model has to declare it. The groupBy calls in toJsonLdNamedGraphs work on the Model directly; the intermediate sequence bought nothing. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: dast <der.danilo.stein@gmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What this changes
Six places serialized RDF onto an output stream with the same hand-written Rio loop:
find, the SPARQL CONSTRUCT/DESCRIBE path (twice), and the N-Quads reads of resources, resources by IRI and the context registry. They now go throughRdfSource(sempods-server,org.sempods.rdf.stream): a producer that pushes statements into anRDFHandler, with two sinks,write(format, out)andtoStreamingOutput(format). No issue; a refactor that came out of a review ofFindEndpoint.Why
Streaming will matter more, on both sides. The loops had already drifted: the N-Quads reads closed the container's response stream, the others did not. Push rather than
Iterable, so a producer owns what it reads from:SparqlQueryService.graphSource()opens the pod connection only while the body is written. That is the shape a streaming producer forfindcan take later without the endpoint changing again.Sources carry statements only.
Rio.write(model, …)andGraphQuery.evaluate(handler)both hand the writer namespaces too, so neither is used, and every response body stays byte for byte what it was.Not covered: the canonical JSON-LD shapes (
toCanonicalJsonLdEntry,toJsonLdNamedGraphs) build maps grouped by subject and context and need the whole model; the resource reads also hash the full model for their ETag first. RDF4J's JSON-LD writer buffers untilendRDF(), so only N-Quads streams incrementally.Public API.
RdfSourcelives insempods-server, which already declaresrio-apionapi; insempods-modelit would have widened that module's published contract.SparqlQueryServicegainsgraphSource()and losesexecuteGraph(…, out),executeGraphAsString()andexecuteTupleAsJson(), which had no caller left.RdfWriterUtilshares one loop internally and losesstreamNQuads,writeJsonLd,toJsonLdGraphand the map-takingreadJsonLd, likewise unused. Those were the only JSON code insempods-model, so it no longer depends onsempods-commons-jsonor Jackson; a consumer that reached Jackson through it has to declare it.Verification and documentation
./gradlew test checkNoLoggingBinding checkNoTestLibrariesInPom checkNoMissingPomDependencies checkDocLinks checkImageMetadata checkPublishedSignatures buildHealth— green, 3449 tests, 0 failures (local Mongo up)buildHealth— no advice for:sempods-serveror:sempods-model; only the existing duplicate-class warnings elsewhereRdfSourceTest(round-trip with contexts, stream left open, streaming entity writes the same document) andSparqlQueryServiceTest(empty-store CONSTRUCT, graph source reaches the pod only when written)doc-review: no documentation describes these code paths, and no HTTP representation changed, so none needed updatingBefore requesting review
git commit -s, ordcofails./gradlew testpasses./gradlew buildHealthpasses — required whenever a dependency or apublic signature moved
./gradlew checkDocLinkspasses — every relative link in a markdown filestill resolves
doc-reviewran on this PR — its updates, or the reason none wereneeded, are listed above
Co-Authored-By:trailer, and the change is one I can defend in review
🤖 Generated with Claude Code