HolgerKnublauch commented on issue #3267:
URL: https://github.com/apache/jena/issues/3267#issuecomment-2994769775
Did some further experiments, and notice that (with substitution) SELECT is
still working as before (with initialBindings), while CONSTRUCT also seems to
create fresh blank nodes.
```
import static org.junit.jupiter.api.Assertions.*;
import org.apache.jena.query.Dataset;
import org.apache.jena.query.DatasetFactory;
import org.apache.jena.query.Query;
import org.apache.jena.query.QueryExecution;
import org.apache.jena.query.QueryExecutionDatasetBuilder;
import org.apache.jena.query.QueryFactory;
import org.apache.jena.query.QuerySolution;
import org.apache.jena.query.QuerySolutionMap;
import org.apache.jena.query.ResultSet;
import org.apache.jena.rdf.model.Literal;
import org.apache.jena.rdf.model.Model;
import org.apache.jena.rdf.model.ModelFactory;
import org.apache.jena.rdf.model.Resource;
import org.apache.jena.rdf.model.Statement;
import org.apache.jena.vocabulary.RDFS;
import org.junit.jupiter.api.Test;
public class BindingQueryTest {
private static boolean SUBSTITUTION = true;
private QueryExecution create(Query query, Dataset dataset,
QuerySolution initialBinding) {
QueryExecutionDatasetBuilder builder = QueryExecution
.create()
.dataset(dataset)
.query(query);
if(SUBSTITUTION) {
builder = builder.substitution(initialBinding);
}
else {
builder = builder.initialBinding(initialBinding);
}
return builder.build();
}
@Test
public void testSelect() {
Model model = ModelFactory.createDefaultModel();
Dataset dataset = DatasetFactory.create(model);
Resource blank1 = model.createResource();
Resource blank2 = model.createResource();
Literal label1 = model.createTypedLiteral("One");
blank1.addLiteral(RDFS.label, label1);
blank2.addLiteral(RDFS.label, "Two");
QuerySolutionMap binding = new QuerySolutionMap();
binding.add("node", blank1);
{
Query query = QueryFactory.create("CONSTRUCT { $node ?p
?label } WHERE { $node ?p ?label }");
QueryExecution qexec = create(query, dataset, binding);
Model result = qexec.execConstruct();
assertEquals(1, result.size());
Statement s = result.listStatements().next();
assertEquals(s.getSubject(), blank1);
assertEquals(s.getObject(), label1);
}
{
Query query = QueryFactory.create("SELECT $node ?label
WHERE { $node ?p ?label }");
QueryExecution qexec = create(query, dataset, binding);
ResultSet rs = qexec.execSelect();
assertTrue(rs.hasNext());
QuerySolution s = rs.next();
assertEquals(s.get("label"), label1);
assertEquals(s.get("node"), blank1);
assertFalse(rs.hasNext());
}
}
}
```
What is the reason why SELECT would still work as before while
CONSTRUCT/INSERT produce new blank nodes?
Also, are there technical reasons why the old behaviour couldn't be restored
for substitution too? At least as a flag?
This is critical for the continued use of SPARQL in our stack. We may not be
able to upgrade to 6.0 and may instead have to maintain our own fork of Jena.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]