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?

There are methods

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

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