Skip to content

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

Open
@arianpotter

Description

@arianpotter

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions