use of org.apache.jena.sparql.engine.ExecutionContext in project jena by apache.
the class TestQueryIterSort method testCancelInterruptsExternalSortAfterStartingIteration.
@Test(expected = QueryCancelledException.class)
public void testCancelInterruptsExternalSortAfterStartingIteration() {
assertEquals(0, iterator.getReturnedElementCount());
Context context = new Context();
context.set(ARQ.spillToDiskThreshold, 10L);
ExecutionContext executionContext = new ExecutionContext(context, (Graph) null, (DatasetGraph) null, (OpExecutorFactory) null);
QueryIterSort qIter = new QueryIterSort(iterator, comparator, executionContext);
try {
assertEquals(0, iterator.getReturnedElementCount());
assertEquals(0, DataBagExaminer.countTemporaryFiles(qIter.db));
// throws a QueryCancelledException
qIter.hasNext();
} catch (QueryCancelledException e) {
// expected
assertEquals(26, iterator.getReturnedElementCount());
// This is zero because QueryIteratorBase will call close() before throwing the QueryCancelledException.
// It does this as a failsafe in case the user doesn't close the QueryIterator themselves.
assertEquals(0, DataBagExaminer.countTemporaryFiles(qIter.db));
throw e;
} finally {
qIter.close();
}
assertEquals(0, DataBagExaminer.countTemporaryFiles(qIter.db));
}
use of org.apache.jena.sparql.engine.ExecutionContext in project jena by apache.
the class TestQueryIterSort method testCloseClosesSourceIterator.
@Test
public void testCloseClosesSourceIterator() {
Context context = new Context();
ExecutionContext ec = new ExecutionContext(context, (Graph) null, (DatasetGraph) null, (OpExecutorFactory) null);
QueryIterSort qis = new QueryIterSort(iterator, comparator, ec);
qis.close();
assertTrue("source iterator should have been closed", iterator.isClosed());
}
use of org.apache.jena.sparql.engine.ExecutionContext in project jena by apache.
the class TestQueryIterSort method testCancelInterruptsInitialisation.
@Test(expected = QueryCancelledException.class)
public void testCancelInterruptsInitialisation() {
assertEquals(0, iterator.getReturnedElementCount());
Context context = new Context();
context.set(ARQ.spillToDiskThreshold, 10L);
ExecutionContext executionContext = new ExecutionContext(context, (Graph) null, (DatasetGraph) null, (OpExecutorFactory) null);
QueryIterSort qIter = new QueryIterSort(iterator, comparator, executionContext);
try {
assertEquals(0, iterator.getReturnedElementCount());
assertEquals(0, DataBagExaminer.countTemporaryFiles(qIter.db));
qIter.cancel();
// throws a QueryCancelledException
qIter.hasNext();
} finally {
assertTrue(iterator.isCanceled());
assertEquals(0, iterator.getReturnedElementCount());
assertEquals(0, DataBagExaminer.countTemporaryFiles(qIter.db));
qIter.close();
}
assertEquals(0, DataBagExaminer.countTemporaryFiles(qIter.db));
}
use of org.apache.jena.sparql.engine.ExecutionContext in project jena by apache.
the class StageMatchTriple method accessTriple.
private static Iterator<Binding> accessTriple(Binding binding, Graph graph, Triple pattern, Predicate<Triple> filter, ExecutionContext execCxt) {
Node s = substituteFlat(pattern.getSubject(), binding);
Node p = substituteFlat(pattern.getPredicate(), binding);
Node o = substituteFlat(pattern.getObject(), binding);
BindingBuilder resultsBuilder = Binding.builder(binding);
Node s2 = tripleNode(s);
Node p2 = tripleNode(p);
Node o2 = tripleNode(o);
ExtendedIterator<Triple> graphIter = graph.find(s2, p2, o2);
ExtendedIterator<Binding> iter = graphIter.mapWith(r -> mapper(resultsBuilder, s, p, o, r)).filterDrop(Objects::isNull);
return iter;
}
use of org.apache.jena.sparql.engine.ExecutionContext in project jena by apache.
the class RX_PG method varAlloc.
private static VarAlloc varAlloc(ExecutionContext execCxt) {
Context context = execCxt.getContext();
VarAlloc varAlloc = VarAlloc.get(context, ARQConstants.sysVarAllocRDFStar);
if (varAlloc == null) {
varAlloc = new VarAlloc(ARQConstants.allocVarTripleTerm);
context.set(ARQConstants.sysVarAllocRDFStar, varAlloc);
}
return varAlloc;
}
Aggregations