Hi,
We execute some CONSTRUCT queries, using a block of code similar to the below code. We then convert it to a List<Statement>
and return it. sparql
variable below is the text of our construct query.
try (Connection connection = getConnection()) {
GraphQueryResult result = null;
try {
GraphQuery query = connection.graph(sparql).dataset(dataset);
result = query.execute();
return new ArrayList<>(result.toGraph());
} catch (StardogException | QueryExecutionFailure e) {
log.error(e.toString());
throw new RuntimeException(e);
} finally {
if (result != null) {
try {
result.close();
} catch (QueryExecutionFailure e) {
log.error(e.toString());
}
}
}
}
Questions
1
When we copy the sparql
text and paste it into the stardog studio and execute it, it is so fast and we easily save the result into a file.
However, the above code tries to run the same query but takes forever to be finished.
2
Besides it loads the data in a lazy way, so we do not know how exactly and when is the right time to run return new ArrayList<>(result.toGraph());
to return the graph.
Maybe one way is something like below:
CloseableIterator<Statement> aResultsIter = new CloseableIterator.AbstractCloseableIterator<Statement>() {
@Override
public void close() {
aResults.close();
}
@Override
protected Statement computeNext() {
if (aResults.hasNext()) {
return aResults.next();
}
return endOfData();
}
};
return Streams.stream(aResultsIter);
}
is there any other way?
Thank you!