GH-4129: Fix rdf:reifies triple dropped when pre-bound variable is used inside an RDF 1.2 annotation - #4134
Merged
Conversation
… is used inside an RDF 1.2 annotation
afs
self-requested a review
August 7, 2026 15:53
afs
reviewed
Aug 7, 2026
…nsform/TestQuerySyntaxTransform.java Co-authored-by: Andy Seaborne <andy@apache.org>
…nsform/QueryTransformOps.java Co-authored-by: Andy Seaborne <andy@apache.org>
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.
GitHub issue resolved #4129
Pull request Description:
QueryTransformOps.replaceVars()(used to pre-bind a variable at the AST level,before query execution) drops the
rdf:reifiestriple generated by an RDF 1.2{| ... |}annotation when the variable being substituted is used inside thereified triple.
Root cause: in
QueryTransformOps.mutateByQueryType()'sCONSTRUCTcase, eachquad's subject/predicate/object goes through
transformOrSame(Node, ExprTransform).That method only checked
Var.isVar(node)and returned any non-Varnodeunchanged. The
rdf:reifiestriple's object is a quoted triple term(
Node_Triple) that itself contains the variable, not a plainVar, so it wasnever substituted. The separate base triple did substitute correctly (its
subject is a plain
Var), which is why the bug report shows the base triplecorrect but the
rdf:reifiestriple missing entirely from the CONSTRUCToutput - it still held an unbound variable and was silently dropped when the
template was later instantiated.
The fix adds triple-term recursion to
transformOrSame, mirroring the existing,correct pattern already used at query-execution time in
org.apache.jena.sparql.core.Substitute.substitute(Node, Binding)(which is whysubstituting via a WHERE-clause binding already worked, per the original report).
A new regression test,
transformTransformReplace_reifies_01inTestQuerySyntaxTransform, reproduces the exact query from the issue andasserts both the base triple and the
rdf:reifiestriple's quoted triple havethe substitution applied.
By submitting this pull request, I acknowledge that I am making a contribution to the Apache Software Foundation under the terms and conditions of the Contributor's Agreement.
See the Apache Jena "Contributing" guide.