On 12/04/2021 09:33, Siddharth Trikha wrote:

Or create a second general dataset, then get the named graph objects
(they are reference) and put it in this dataset and query that.

(this is what using several FROM NAMED does anyway)


If I understand it correctly the following example is what you suggested:

Dataset createGeneral = DatasetFactory.createGeneral();

RDFConnectionRemoteBuilder builder = RDFConnectionFuseki.create()
.destination("http://x.x.x.x:3030/ds";);

This is changing the question!

It was a TDB (i.e. local) dataset.


try ( RDFConnectionFuseki conn = (RDFConnectionFuseki)builder.build() ) {
Dataset fetchDataset = conn.fetchDataset();

That reads the whole thing into memory. "fetch"


Model namedModel = fetchDataset.getNamedModel(GRAPH_IRI_PREFIX + "R17");
Model namedModel2 = fetchDataset.getNamedModel(GRAPH_IRI_PREFIX + "R15");

createGeneral.addNamedModel(GRAPH_IRI_PREFIX + "R32", namedModel);
createGeneral.addNamedModel(GRAPH_IRI_PREFIX + "R33", namedModel2);

}
String queryString = "SELECT * { ?s ?p ?o }";
         Query query = QueryFactory.create(queryString);
         QueryExecution qexec = QueryExecutionFactory.create(query,
createGeneral);

         try {
             ResultSet results = qexec.execSelect();
             while ( results.hasNext() ) {
                 QuerySolution soln = results.nextSolution();
                 System.out.println(soln);
             }

That will be no results.

For remote: (untested)

SELECT *
FROM NAMED <..R15>
FROM NAMED <..R17>
WHERE {
    GRAPH ?g { ?s ?p ?o }
}

or

SELECT *
FROM  <..R15> # Full URLs
FROM  <..R17>
# Default graph is those graphs merged.
WHERE {
    GRAPH ?g { ?s ?p ?o }
}

or
SELECT *
# Default graph is those graphs merged.
WHERE {
    VALUES ?g { <..R15> <..R17> }
    GRAPH ?g { ?s ?p ?o }
}

or

SELECT *
FROM  <..R15>
FROM  <..R17>
# Default graph is those graphs merged.
WHERE {
  ?s ?p ?o
}


Here getNamedModel and addNamedModel would be using references not
in-memory ?

The main database is going to have to be local for that to be possible. The TDB example.

    Andy


On Fri, Apr 9, 2021 at 4:25 PM Andy Seaborne <a...@apache.org> wrote:



On 09/04/2021 10:05, Lorenz Buehmann wrote:
You are using TDB which is an external database and indexes to the data
which resides on disk. Why do you think that all the graphs are loaded
into memory?

Why can't you modify the given query in your code? You can either do
string hacks, or what I'd prefer, parse the query and work on the query
element structure. You could use FROM or FROM NAMED can't you?

Indeed.


There are methods

addGraphURI and addNamedGraphURI for the Query object, maybe you could
try one of those methods?

Or create a second general dataset, then get the named graph objects
(they are reference) and put it in this dataset and query that.

(this is what using several FROM NAMED does anyway)

      Andy


On 09.04.21 10:28, Siddharth Trikha wrote:
Hi all,

I have a use case to run a SPARQL query over a limited set of Graphs
in my
TripleStore.

For example:

   String directory = "MyDatabases/DB1" ;
      Dataset dataset = TDBFactory.createDataset(directory) ;

      // Potentially expensive query.
      String sparqlQueryString = "SELECT (count(*) AS ?count) { ?s ?p
?o }" ;

      Query query = QueryFactory.create(sparqlQueryString) ;
      QueryExecution qexec = QueryExecutionFactory.create(query,
dataset) ;
// ...............

The above example would run on the whole Database.

I want to run the above SPARQL Query over lets say just 5 named GRAPHS
whose names I know.

The sparqlQueryString will be provided by the application as given
above without named GRAPHS specified inside the Query String, but
passes the Graph names (IRIs) in another attribute separately.

I wanted to avoid in-memory loading of all named GRAPHS as this number
can increase.

Is there an efficient way of achieving this use case ?

Any help is appreciated.





Reply via email to