I apologize in advance if this is a duplicate: I could not find anything
relevant on Jira.
I came across what appears to be a bug when all 3 elements of a triple
pattern for an INSERT clause are variables that have been assigned using
BIND. After executing the UpdateAction, the desired triples are not
introduced to the underlying graph.
Attached is a small JUnit test case which reproduces this error. It can
likely be further minimized.
Regards,
Rob
package dot2sfg;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import org.junit.Before;
import org.junit.Test;
import com.hp.hpl.jena.rdf.model.Model;
import com.hp.hpl.jena.rdf.model.ModelFactory;
import com.hp.hpl.jena.rdf.model.Property;
import com.hp.hpl.jena.rdf.model.Resource;
import com.hp.hpl.jena.rdf.model.ResourceFactory;
import com.hp.hpl.jena.update.UpdateAction;
import com.hp.hpl.jena.update.UpdateFactory;
import com.hp.hpl.jena.update.UpdateRequest;
/** <p>This test case demonstrates an issue with SPARQL Update
* where a triple pattern in an INSERT clause is not materialized
* despite the fact that all variables for the pattern are
* presently bound.</p>
*
* <p>This test fails with versions in jena-arq <tt>2.11.1</tt></p>
*/
public class InsertVariablesBound {
private static final UpdateRequest replace = UpdateFactory.create(
"DELETE {\n"+
" ?s ?p ?o.\n"+ // Successfully deleted
"}\n"+
"INSERT\n"+
"{\n"+
" ?ns ?np ?no .\n"+ // XXX Desired new triple; does not appear
""+
" <x-test://s1> <x-test://p1> <x-test://o1> .\n"+ // XXX Demonstration only; these lines prove that
" ?ns <x-test://p2> <x-test://o2> .\n"+ // XXX the values for the bound variables exist and are
" <x-test://s3> ?np <x-test://o3> .\n"+ // XXX able to be used in patterns, but not when all three
" <x-test://s4> <x-test://p4> ?no .\n"+ // XXX exist in the same triple.
"}\n"+
"WHERE\n"+
"{\n"+
" {SELECT ?new ?old WHERE {\n"+
" ?new <x-dom://betterThan> ?old .\n"+
" } LIMIT 1}\n"+
""+
" {\n"+
" ?old ?p ?o .\n"+
" BIND( ?old AS ?s ).\n"+
" BIND( ?new AS ?ns ).\n"+
" BIND( ?p AS ?np ).\n"+
" BIND( ?o AS ?no ).\n"+
" } UNION {\n"+
" ?s ?p ?old .\n"+
" BIND( ?old as ?o ).\n"+
" BIND( ?s AS ?ns ).\n"+
" BIND( ?p AS ?np ).\n"+
" BIND( ?new AS ?no ).\n"+
" }\n"+
"}"
);
private Model model = null;
@Before
public void setupModel() {
model = ModelFactory.createDefaultModel();
}
@Test
public void queryFail()
{
final Resource sNew = model.createResource("x-data://new");
final Property criteria = ResourceFactory.createProperty("x-dom://betterThan");
final Resource sOld = model.createResource("x-data://old");
model.add(sNew, criteria, sOld);
final Property p = model.createProperty("x-data://p");
final Resource o = model.createResource("x-data://o");
model.add(sOld, p, o);
// System.out.println("BEFORE");
// System.out.println("======================================");
// model.write(System.out, "N3");
assertTrue( model.contains(sOld, p, o) );
assertFalse( model.contains(sNew, p, o) );
UpdateAction.execute(replace, model);
// System.out.println();
// System.out.println("After");
// System.out.println("======================================");
// model.write(System.out, "N3");
assertFalse( model.contains(sOld, p, o) );
assertTrue( model.contains(sNew, p, o) ); // NOTE Assertion fails
}
}