Originally posted by **kishand261194** January 4, 2024
Hi all,
We are attempting to upgrade from Jena 3.5 to Jena 4.10.0.
We are using “RDFConnection.connect(TDBFactory.createDataset());” for unit tests.
The below query works totally fine in Jena 3.5 but fails with the following exception in Jena 4.10.0.
I have confirmed that the query is correct and works totally fine in Neptune RDF as well. Can someone please help us on how to go about this ? or please suggest if the query needs to updated to something else for jena 4.10.0.
I have also attached the code sample to reproduce the issue.
Query :
```sparql
INSERT {
GRAPH {
"o1" .
}
}
WHERE
{ GRAPH
{ }
GRAPH
{ FILTER NOT EXISTS { "o3" }}
}
```
Error :
> org.apache.jena.sparql.ARQInternalErrorException: compile(Element)/Not a structural element: ElementFilter
> at app//org.apache.jena.sparql.algebra.AlgebraGenerator.broken(AlgebraGenerator.java:577)
> at app//org.apache.jena.sparql.algebra.AlgebraGenerator.compileUnknownElement(AlgebraGenerator.java:170)
> at app//org.apache.jena.sparql.algebra.AlgebraGenerator.compileElement(AlgebraGenerator.java:156)
> at app//org.apache.jena.sparql.algebra.AlgebraGenerator.compileElementGraph(AlgebraGenerator.java:426)
> at app//org.apache.jena.sparql.algebra.AlgebraGenerator.compileElement(AlgebraGenerator.java:133)
> at app//org.apache.jena.sparql.algebra.AlgebraGenerator.compileOneInGroup(AlgebraGenerator.java:319)
> at app//org.apache.jena.sparql.algebra.AlgebraGenerator.compileElementGroup(AlgebraGenerator.java:202)
> at app//org.apache.jena.sparql.algebra.AlgebraGenerator.compileElement(AlgebraGenerator.java:127)
> at app//org.apache.jena.sparql.algebra.AlgebraGenerator.compile(AlgebraGenerator.java:113)
> at app//org.apache.jena.sparql.algebra.AlgebraGenerator.compile(AlgebraGenerator.java:100)
> at app//org.apache.jena.sparql.algebra.Algebra.compile(Algebra.java:73)
> at app//org.apache.jena.sparql.engine.QueryEngineBase.createOp(QueryEngineBase.java:140)
> at app//org.apache.jena.sparql.engine.QueryEngineBase.(QueryEngineBase.java:57)
> at app//org.apache.jena.sparql.engine.main.QueryEngineMain.(QueryEngineMain.java:45)
> at app//org.apache.jena.tdb.solver.QueryEngineTDB.(QueryEngineTDB.java:63)
> at app//org.apache.jena.tdb.solver.QueryEngineTDB$QueryEngineFactoryTDB.create(QueryEngineTDB.java:135)
> at app//org.apache.jena.query.QueryExecutionFactory.makePlan(QueryExecutionFactory.java:442)
> at app//org.apache.jena.query.QueryExecutionFactory.createPlan(QueryExecutionFactory.java:418)
> at app//org.apache.jena.sparql.modify.UpdateEngineWorker.evalBindings(UpdateEngineWorker.java:532)
> at app//org.apache.jena.sparql.modify.UpdateEngineWorker.visit(UpdateEngineWorker.java:371)
> at app//org.apache.jena.sparql.modify.request.UpdateModify.visit(UpdateModify.java:100)
> at app//org.apache.jena.sparql.modify.UpdateVisitorSink.send(UpdateVisitorSink.java:45)
> at app//org.apache.jena.sparql.modify.UpdateVisitorSink.send(UpdateVisitorSink.java:31)
> at [java.base@17.0.9](mailto:java.base@17.0.9)/java.util.ArrayList$Itr.forEachRemaining(ArrayList.java:1003)
> at [java.base@17.0.9](mailto:java.base@17.0.9)/java.util.Collections$UnmodifiableCollection$1.forEachRemaining(Collections.java:1061)
> at app//org.apache.jena.atlas.iterator.Iter.sendToSink(Iter.java:776)
> at app//org.apache.jena.sparql.modify.UpdateProcessorBase.execute(UpdateProcessorBase.java:60)
> at app//org.apache.jena.sparql.exec.UpdateExecDataset.execute(UpdateExecDataset.java:37)
> at app//org.apache.jena.sparql.exec.UpdateExecDatasetBuilder.execute(UpdateExecDatasetBuilder.java:164)
> at app//org.apache.jena.sparql.exec.UpdateExecDatasetBuilder.execute(UpdateExecDatasetBuilder.java:169)
> at app//org.apache.jena.rdflink.RDFLinkDataset.lambda$update$1(RDFLinkDataset.java:107)
> at app//org.apache.jena.system.Txn.exec(Txn.java:77)
> at app//org.apache.jena.system.Txn.executeWrite(Txn.java:125)
> at app//org.apache.jena.rdflink.RDFLinkDataset.update(RDFLinkDataset.java:107)
> at app//org.apache.jena.rdflink.RDFConnectionAdapter.update(RDFConnectionAdapter.java:131)
> at org.apache.jena.rdfconnection.RDFConnection$update$0.call(Unknown Source)
> at app//org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:47)
> at app//org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:125)
> at app//org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:139)
> at app//com.pk.knowledgestore.rdf.graph.store.RdfQuadStoreSparqlTest.update(RdfQuadStoreSparqlTest.groovy:115)
> at com.pk.knowledgestore.rdf.graph.store.RdfQuadStoreSparqlTest$update.callCurrent(Unknown Source)
> at app//org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallCurrent(CallSiteArray.java:51)
> at app//org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:171)
> at app//org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:194)
> at app//com.amazon.pk.knowledgestore.rdf.graph.store.RdfQuadStoreSparqlTest.testQueryFailure(RdfQuadStoreSparqlTest.groovy:108)
Code to repro the issue :
```java
private final Triple triple1 = new Triple(
createURI("rdf:s1"),
createURI("rdf:p1"),
createLiteral("o1"))
private final Triple triple2 = new Triple(
createURI("rdf:s2"),
createURI("rdf:p2"),
createURI("rdf:o2"))
private final Triple triple3 = new Triple(
createURI("rdf:s3"),
createURI("rdf:p3"),
createLiteral("o3"))
private final graph1 = getNamedGraph()
private final graph2 = getNamedGraph()
@Test
void testQueryFailure() {
RDFConnection conn = RDFConnection.connect(TDBFactory.createDataset());
UpdateBuilder updateBuilder = new UpdateBuilder();
updateBuilder.addInsert(graph1, triple1);
SelectBuilder where = new SelectBuilder();
where.addWhere(triple2);
updateBuilder.addGraph(graph1, where);
SelectBuilder notExists = new SelectBuilder();
notExists.addWhere(triple3);
SelectBuilder where2 = new SelectBuilder();
where2.addFilter(where2.getExprFactory().notexists(notExists));
updateBuilder.addGraph(graph2, where2);
UpdateRequest updateRequest = updateBuilder.buildRequest();
System.out.println("From the tests : " + updateRequest.toString())
update(conn, updateRequest);
}
public void update(final RDFConnection conn, final UpdateRequest request) {
conn.begin(ReadWrite.WRITE);
try {
conn.update(request);
conn.commit();
} finally {
conn.end();
}
}
```
Discussed in https://github.com/apache/jena/discussions/2150