Search in sources :

Example 96 with QueryIterator

use of org.apache.jena.sparql.engine.QueryIterator in project jena by apache.

the class ExecutionDispatch method visit.

@Override
public void visit(OpOrder opOrder) {
    QueryIterator input = pop();
    QueryIterator qIter = opExecutor.execute(opOrder, input);
    push(qIter);
}
Also used : QueryIterator(org.apache.jena.sparql.engine.QueryIterator)

Example 97 with QueryIterator

use of org.apache.jena.sparql.engine.QueryIterator in project jena by apache.

the class PathLib method execUngroundedPathSameVar.

private static QueryIterator execUngroundedPathSameVar(Binding binding, Graph graph, Var var, Path path, ExecutionContext execCxt) {
    // Try each end, ungrounded.
    // Slightly more efficient would be to add a per-engine to do this.
    Iterator<Node> iter = determineUngroundedStartingSet(graph, path, execCxt);
    QueryIterConcat qIterCat = new QueryIterConcat(execCxt);
    for (; iter.hasNext(); ) {
        Node n = iter.next();
        Binding b2 = BindingFactory.binding(binding, var, n);
        int x = existsPath(graph, n, path, n, execCxt);
        if (x > 0) {
            QueryIterator qIter = new QueryIterYieldN(x, b2, execCxt);
            qIterCat.add(qIter);
        }
    }
    return qIterCat;
}
Also used : QueryIterConcat(org.apache.jena.sparql.engine.iterator.QueryIterConcat) Binding(org.apache.jena.sparql.engine.binding.Binding) QueryIterator(org.apache.jena.sparql.engine.QueryIterator) Node(org.apache.jena.graph.Node) QueryIterYieldN(org.apache.jena.sparql.engine.iterator.QueryIterYieldN)

Example 98 with QueryIterator

use of org.apache.jena.sparql.engine.QueryIterator in project jena by apache.

the class PathEngine method graphFindWorker.

private Iterator<Triple> graphFindWorker(Graph graph, Node s, PropertyFunctionFactory f, Node p, Node o, Context context) {
    // Expensive?
    PropertyFunction pf = f.create(p.getURI());
    PropFuncArg sv = arg(s, "S");
    PropFuncArg ov = arg(o, "O");
    QueryIterator r = QueryIterRoot.create(new ExecutionContext(context, graph, null, null));
    QueryIterator qIter = pf.exec(r, sv, p, ov, new ExecutionContext(ARQ.getContext(), graph, null, null));
    if (!qIter.hasNext())
        return Iter.nullIterator();
    List<Triple> array = new ArrayList<>();
    for (; qIter.hasNext(); ) {
        Binding b = qIter.next();
        Node st = value(sv, b);
        Node ot = value(ov, b);
        array.add(Triple.create(st, p, ot));
    }
    // Materialise so the inner QueryIterators are used up. 
    return array.iterator();
}
Also used : Triple(org.apache.jena.graph.Triple) Binding(org.apache.jena.sparql.engine.binding.Binding) ExecutionContext(org.apache.jena.sparql.engine.ExecutionContext) QueryIterator(org.apache.jena.sparql.engine.QueryIterator) Node(org.apache.jena.graph.Node) ArrayList(java.util.ArrayList)

Example 99 with QueryIterator

use of org.apache.jena.sparql.engine.QueryIterator in project jena by apache.

the class PathLib method execUngroundedPath.

// Brute force evaluation of a TriplePath where neither subject nor object are bound 
private static QueryIterator execUngroundedPath(Binding binding, Graph graph, Var sVar, Path path, Var oVar, ExecutionContext execCxt) {
    // Starting points.
    Iterator<Node> iter = determineUngroundedStartingSet(graph, path, execCxt);
    QueryIterConcat qIterCat = new QueryIterConcat(execCxt);
    for (; iter.hasNext(); ) {
        Node n = iter.next();
        Binding b2 = BindingFactory.binding(binding, sVar, n);
        Iterator<Node> pathIter = PathEval.eval(graph, n, path, execCxt.getContext());
        QueryIterator qIter = evalGroundedOneEnd(b2, pathIter, oVar, execCxt);
        qIterCat.add(qIter);
    }
    return qIterCat;
}
Also used : QueryIterConcat(org.apache.jena.sparql.engine.iterator.QueryIterConcat) Binding(org.apache.jena.sparql.engine.binding.Binding) QueryIterator(org.apache.jena.sparql.engine.QueryIterator) Node(org.apache.jena.graph.Node)

Example 100 with QueryIterator

use of org.apache.jena.sparql.engine.QueryIterator in project jena by apache.

the class Eval method evalDS.

static Table evalDS(OpDatasetNames opDSN, Evaluator evaluator) {
    Node graphNode = opDSN.getGraphNode();
    if (graphNode.isURI()) {
        if (evaluator.getExecContext().getDataset().containsGraph(graphNode)) {
            return new TableUnit();
        } else // WRONG
        {
            return new TableEmpty();
        }
    }
    if (!Var.isVar(graphNode))
        throw new ARQInternalErrorException("OpDatasetNames: Not a URI or variable: " + graphNode);
    DatasetGraph dsg = evaluator.getExecContext().getDataset();
    Iterator<Node> iter = dsg.listGraphNodes();
    List<Binding> list = new ArrayList<>((int) dsg.size());
    for (; iter.hasNext(); ) {
        Node gn = iter.next();
        Binding b = BindingFactory.binding(Var.alloc(graphNode), gn);
        list.add(b);
    }
    QueryIterator qIter = new QueryIterPlainWrapper(list.iterator(), evaluator.getExecContext());
    return TableFactory.create(qIter);
}
Also used : Binding(org.apache.jena.sparql.engine.binding.Binding) QueryIterPlainWrapper(org.apache.jena.sparql.engine.iterator.QueryIterPlainWrapper) QueryIterator(org.apache.jena.sparql.engine.QueryIterator) Node(org.apache.jena.graph.Node) ARQInternalErrorException(org.apache.jena.sparql.ARQInternalErrorException) ArrayList(java.util.ArrayList) TableEmpty(org.apache.jena.sparql.algebra.table.TableEmpty) TableUnit(org.apache.jena.sparql.algebra.table.TableUnit) DatasetGraph(org.apache.jena.sparql.core.DatasetGraph)

Aggregations

QueryIterator (org.apache.jena.sparql.engine.QueryIterator)126 Binding (org.apache.jena.sparql.engine.binding.Binding)27 Op (org.apache.jena.sparql.algebra.Op)15 Node (org.apache.jena.graph.Node)13 TableN (org.apache.jena.sparql.algebra.table.TableN)13 ArrayList (java.util.ArrayList)12 ResultSetStream (org.apache.jena.sparql.engine.ResultSetStream)10 Var (org.apache.jena.sparql.core.Var)9 ResultSet (org.apache.jena.query.ResultSet)8 QueryIterPlainWrapper (org.apache.jena.sparql.engine.iterator.QueryIterPlainWrapper)8 Triple (org.apache.jena.graph.Triple)6 ExecutionContext (org.apache.jena.sparql.engine.ExecutionContext)6 BasicPattern (org.apache.jena.sparql.core.BasicPattern)5 QueryIterConcat (org.apache.jena.sparql.engine.iterator.QueryIterConcat)5 Table (org.apache.jena.sparql.algebra.Table)4 DatasetGraph (org.apache.jena.sparql.core.DatasetGraph)4 HashSet (java.util.HashSet)3 Plan (org.apache.jena.sparql.engine.Plan)3 BindingMap (org.apache.jena.sparql.engine.binding.BindingMap)3 Procedure (org.apache.jena.sparql.procedure.Procedure)3