Search in sources :

Example 6 with ExecutionContext

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));
}
Also used : Context(org.apache.jena.sparql.util.Context) SerializationContext(org.apache.jena.sparql.serializer.SerializationContext) ExecutionContext(org.apache.jena.sparql.engine.ExecutionContext) ExecutionContext(org.apache.jena.sparql.engine.ExecutionContext) QueryCancelledException(org.apache.jena.query.QueryCancelledException) Test(org.junit.Test)

Example 7 with ExecutionContext

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());
}
Also used : Context(org.apache.jena.sparql.util.Context) SerializationContext(org.apache.jena.sparql.serializer.SerializationContext) ExecutionContext(org.apache.jena.sparql.engine.ExecutionContext) ExecutionContext(org.apache.jena.sparql.engine.ExecutionContext) Test(org.junit.Test)

Example 8 with ExecutionContext

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));
}
Also used : Context(org.apache.jena.sparql.util.Context) SerializationContext(org.apache.jena.sparql.serializer.SerializationContext) ExecutionContext(org.apache.jena.sparql.engine.ExecutionContext) ExecutionContext(org.apache.jena.sparql.engine.ExecutionContext) Test(org.junit.Test)

Example 9 with ExecutionContext

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;
}
Also used : Triple(org.apache.jena.graph.Triple) Binding(org.apache.jena.sparql.engine.binding.Binding) Objects(java.util.Objects) Binding(org.apache.jena.sparql.engine.binding.Binding) Iterator(java.util.Iterator) Var(org.apache.jena.sparql.core.Var) Node(org.apache.jena.graph.Node) Predicate(java.util.function.Predicate) Triple(org.apache.jena.graph.Triple) ExtendedIterator(org.apache.jena.util.iterator.ExtendedIterator) Iter(org.apache.jena.atlas.iterator.Iter) ExecutionContext(org.apache.jena.sparql.engine.ExecutionContext) BindingBuilder(org.apache.jena.sparql.engine.binding.BindingBuilder) Graph(org.apache.jena.graph.Graph) BindingBuilder(org.apache.jena.sparql.engine.binding.BindingBuilder) Node(org.apache.jena.graph.Node) Objects(java.util.Objects)

Example 10 with ExecutionContext

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;
}
Also used : Context(org.apache.jena.sparql.util.Context) ExecutionContext(org.apache.jena.sparql.engine.ExecutionContext) VarAlloc(org.apache.jena.sparql.core.VarAlloc)

Aggregations

ExecutionContext (org.apache.jena.sparql.engine.ExecutionContext)40 Context (org.apache.jena.sparql.util.Context)19 Node (org.apache.jena.graph.Node)14 SerializationContext (org.apache.jena.sparql.serializer.SerializationContext)12 Test (org.junit.Test)12 Binding (org.apache.jena.sparql.engine.binding.Binding)11 Triple (org.apache.jena.graph.Triple)9 QueryIterator (org.apache.jena.sparql.engine.QueryIterator)9 Iterator (java.util.Iterator)8 Iter (org.apache.jena.atlas.iterator.Iter)8 Var (org.apache.jena.sparql.core.Var)8 Predicate (java.util.function.Predicate)7 Graph (org.apache.jena.graph.Graph)7 InternalErrorException (org.apache.jena.atlas.lib.InternalErrorException)6 Function (java.util.function.Function)5 ARQInternalErrorException (org.apache.jena.sparql.ARQInternalErrorException)5 DatasetGraph (org.apache.jena.sparql.core.DatasetGraph)5 Quad (org.apache.jena.sparql.core.Quad)5 Substitute (org.apache.jena.sparql.core.Substitute)5 BindingFactory (org.apache.jena.sparql.engine.binding.BindingFactory)5