Huge Execution Time Difference between stardog studio and snarl api

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!

As I said in the other ticket, you can always return result.toGraph() and be sure that the result is complete and the result set is closed.

I don't know why there's a performance difference. For starters, I'd double check that the query dataset is exactly the same and that you're getting the same results. If both check out, then maybe collect thread dumps to see where things get stuck when you execute your program.

Best,
Pavel