Skip to content

GH-4129: Fix rdf:reifies triple dropped when pre-bound variable is used inside an RDF 1.2 annotation - #4134

Merged
afs merged 3 commits into
apache:mainfrom
adityaanikam:construct-reifies-prebound-4129
Aug 9, 2026
Merged

GH-4129: Fix rdf:reifies triple dropped when pre-bound variable is used inside an RDF 1.2 annotation#4134
afs merged 3 commits into
apache:mainfrom
adityaanikam:construct-reifies-prebound-4129

Conversation

@adityaanikam

Copy link
Copy Markdown
Contributor

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:reifies triple generated by an RDF 1.2
{| ... |} annotation when the variable being substituted is used inside the
reified triple.

Root cause: in QueryTransformOps.mutateByQueryType()'s CONSTRUCT case, each
quad's subject/predicate/object goes through transformOrSame(Node, ExprTransform).
That method only checked Var.isVar(node) and returned any non-Var node
unchanged. The rdf:reifies triple's object is a quoted triple term
(Node_Triple) that itself contains the variable, not a plain Var, so it was
never substituted. The separate base triple did substitute correctly (its
subject is a plain Var), which is why the bug report shows the base triple
correct but the rdf:reifies triple missing entirely from the CONSTRUCT
output - 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 why
substituting via a WHERE-clause binding already worked, per the original report).

A new regression test, transformTransformReplace_reifies_01 in
TestQuerySyntaxTransform, reproduces the exact query from the issue and
asserts both the base triple and the rdf:reifies triple's quoted triple have
the substitution applied.


  • Tests are included.
  • Documentation change and updates are provided for the Apache Jena website - not applicable, internal bug fix with no user-facing behavior change to document.
  • Commits have been squashed to remove intermediate development commit messages.
  • Key commit messages start with the issue number (GH-xxxx)

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.

afs
afs approved these changes Aug 7, 2026
@afs
afs self-requested a review August 7, 2026 15:53

@afs afs left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A couple of suggested tweaks but otherwise looks good.

adityaanikam and others added 2 commits August 7, 2026 21:42
…nsform/TestQuerySyntaxTransform.java

Co-authored-by: Andy Seaborne <andy@apache.org>
…nsform/QueryTransformOps.java

Co-authored-by: Andy Seaborne <andy@apache.org>
@afs
afs merged commit 641765e into apache:main Aug 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

SPARQL CONSTRUCT: Missing rdf:reifies triple when pre-bound variable is in the reified triple

2 participants