apache / apache/jena

"Attempt to assign an expression again" Error in nested WhereBuilders

Open
#3,223 6 comments 0 reactions 0 assignees View on GitHub
question
Dominant language
Java
Stars
1.4k
Forks
712
Avg merge
15h 41m
Merged PRs (30d)
53

Description

### Version

5.3.0

### Question

Dear Community Members,
As a part of the project that I am working on now, I have to create dynamic SPARQL queries. To this end, I am using Jena's ARQ library QueryBuilder.
The issue that I am facing now is that I need to be able to nest WhereBuilders into each other with FILTER EXISTS and I have a function like below that adds a WhereBuilder to another as FILTER EXISTS:

`
private void addFilterExists(WhereBuilder outerBuilder, WhereBuilder innerBuilder) {
Element innerElement = innerBuilder.build().getQueryPattern();

ElementGroup group = new ElementGroup();
group.addElement(innerElement);

Expr notExistsExpr = new E_Exists(group);

outerBuilder.addFilter(notExistsExpr);
}
`
This works fine if I use it once. But if I have to nest the query again with this function into another WhereBuilder, and there is a BIND clause somewhere in the inner query, I get the error "Attempt to assign an expression again".
I can not remove BIND clauses as they are getting added dynamically and are important. On the other hand, I believe the issue arises from the fact that I have to build the inner query, and when I put this built query into another whereclause and then this whereclause gets built as the inner query of another clause I get this Error while doing: Expr notExistsExpr = new E_Exists(group);
Also, not building the inner query is not an option because trying to nest these without building(with WhereHandler) leads to a NullPointer exception Error.

I really appreciate any help or workaround if it is possible, as I am getting frustrated with this issue and have not found a solution so far.

Contributor guide

Open the contributing guide

Research direction

Start by reproducing the nested FILTER EXISTS case using WhereBuilder, its build() method, ElementGroup, and E_Exists, including a dynamically added BIND clause. Trace where the second "Attempt to assign an expression again" error occurs and compare it with the NullPointerException from nesting without building; done means the supported nesting behavior is established and covered by a regression test.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
backend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.