Andy,

thank you. It does work indeed with TDB. It was failing with me at first 
because, for some obscure reason in old code, I was using it against a Dataset 
created calling:
Dataset ds = 
DatasetFactory.create(TDBFactory.createDataset(tdbDir.getAbsolutePath()));
(DatasetFactory.create is deprecated)

With just
Dataset ds = TDBFactory.createDataset(tdbDir.getAbsolutePath());
everything works as expected.

Best,
fps

> Le 7 juil. 2016 à 14:32, Andy Seaborne <[email protected]> a écrit :
> 
> Hi,
> 
> > DatasetFactory.create();
> 
> Union graph doesn't yet work on general datasets consistently.
> 
> It works for TDB and for TxnMem (also known as TIM) - in the latter case the 
> warning from the OpExecutor comes out but it's wrong.
> 
>       Andy
> 
> On 05/07/16 17:15, François-Paul Servant wrote:
>> Hi,
>> 
>> I'm trying to query the named graphs of a TDB dataset using 
>> <urn:x-arq:UnionGraph>, but I must be missing something. Is there something 
>> special to do in order to use <urn:x-arq:UnionGraph> as a graph name in a 
>> query?
>> 
>> Here is what I'm trying (this test uses a memory dataset: only works with 
>> 3.1.1-SNAPSHOT. Normally, I use TDB)
>> 
>> TIA,
>> 
>> fps
>> 
>> package sometests;
>> 
>> import static org.junit.Assert.*;
>> 
>> 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.QueryExecutionFactory;
>> import org.apache.jena.query.QueryFactory;
>> import org.apache.jena.query.QuerySolution;
>> import org.apache.jena.query.ResultSet;
>> import org.apache.jena.rdf.model.Model;
>> import org.apache.jena.rdf.model.ModelFactory;
>> import org.junit.Test;
>> 
>> public class UnionGraphTest {
>> 
>> @Test public final void test() {
>>      Model m = ModelFactory.createDefaultModel();
>>      m.add(
>>                      m.createResource("http://ex.com/s";),
>>                      m.createProperty("http://ex.com/p";),
>>                      m.createResource("http://ex.com/o";));
>>      Dataset ds = DatasetFactory.create();
>>      ds.addNamedModel("http://ex.com/g";, m);
>>      
>>      // query using the named graph: return some results
>>      doIt(ds, "http://ex.com/g";);
>>      // same query, using urn:x-arq:UnionGraph, doens't return any result
>>      doIt(ds, "urn:x-arq:UnionGraph");
>> }
>> 
>> private void doIt(Dataset ds, String graphName) {
>>      String queryString = "SELECT * WHERE { GRAPH <" + graphName + "> {?s ?p 
>> ?o} }";
>>      Query q = QueryFactory.create(queryString) ;
>>      QueryExecution qexec = QueryExecutionFactory.create(q, ds);
>>      ResultSet rs = qexec.execSelect();
>>      assertTrue(rs.hasNext());
>>      for (;rs.hasNext();) {
>>              QuerySolution sol = rs.next();
>>              System.out.println(sol);
>>      }
>> }
>> }
>> 
> 

Reply via email to