Search in sources :

Example 1 with QueryIterConcat

use of org.apache.jena.sparql.engine.iterator.QueryIterConcat in project jena by apache.

the class ListBase method allLists.

protected QueryIterator allLists(Binding binding, Collection<Node> x, Var listVar, Node predicate, PropFuncArg argObject, ExecutionContext execCxt) {
    // BFI: Find all lists; work hard.
    QueryIterConcat qIter = new QueryIterConcat(execCxt);
    for (Node n : x) {
        Binding b = BindingFactory.binding(binding, listVar, n);
        QueryIterator q = execOneList(b, n, predicate, argObject, execCxt);
        qIter.add(q);
    }
    return qIter;
}
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 2 with QueryIterConcat

use of org.apache.jena.sparql.engine.iterator.QueryIterConcat in project jena by apache.

the class QueryIterUnion method nextStage.

@Override
protected QueryIterator nextStage(Binding binding) {
    QueryIterConcat unionQIter = new QueryIterConcat(getExecContext());
    for (Op subOp : subOps) {
        subOp = QC.substitute(subOp, binding);
        QueryIterator parent = QueryIterSingleton.create(binding, getExecContext());
        QueryIterator qIter = QC.execute(subOp, parent, getExecContext());
        unionQIter.add(qIter);
    }
    return unionQIter;
}
Also used : QueryIterConcat(org.apache.jena.sparql.engine.iterator.QueryIterConcat) Op(org.apache.jena.sparql.algebra.Op) QueryIterator(org.apache.jena.sparql.engine.QueryIterator)

Example 3 with QueryIterConcat

use of org.apache.jena.sparql.engine.iterator.QueryIterConcat 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 4 with QueryIterConcat

use of org.apache.jena.sparql.engine.iterator.QueryIterConcat 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 5 with QueryIterConcat

use of org.apache.jena.sparql.engine.iterator.QueryIterConcat in project jena by apache.

the class Eval method evalQuadPattern.

static Table evalQuadPattern(OpQuadPattern opQuad, Evaluator evaluator) {
    if (opQuad.isEmpty())
        return TableFactory.createUnit();
    ExecutionContext cxt = evaluator.getExecContext();
    DatasetGraph ds = cxt.getDataset();
    BasicPattern pattern = opQuad.getBasicPattern();
    if (!opQuad.getGraphNode().isVariable()) {
        if (!opQuad.getGraphNode().isURI()) {
            throw new ARQInternalErrorException("Not a URI or variable: " + opQuad.getGraphNode());
        }
        Graph g = null;
        if (opQuad.isDefaultGraph())
            g = ds.getDefaultGraph();
        else
            g = ds.getGraph(opQuad.getGraphNode());
        if (g == null)
            return new TableEmpty();
        ExecutionContext cxt2 = new ExecutionContext(cxt, g);
        QueryIterator qIter = executeBGP(pattern, QueryIterRoot.create(cxt2), cxt2);
        return TableFactory.create(qIter);
    } else {
        // Variable.
        Var gVar = Var.alloc(opQuad.getGraphNode());
        // Or just just devolve to OpGraph and get OpUnion chain of OpJoin
        QueryIterConcat concat = new QueryIterConcat(cxt);
        for (Iterator<Node> graphNodes = cxt.getDataset().listGraphNodes(); graphNodes.hasNext(); ) {
            Node gn = graphNodes.next();
            //Op tableVarURI = TableFactory.create(gn.getName(), Node.createURI(uri)) ;
            Graph g = cxt.getDataset().getGraph(gn);
            Binding b = BindingFactory.binding(BindingRoot.create(), gVar, gn);
            ExecutionContext cxt2 = new ExecutionContext(cxt, g);
            // Eval the pattern, eval the variable, join.
            // Pattern may be non-linear in the variable - do a pure execution.  
            Table t1 = TableFactory.create(gVar, gn);
            QueryIterator qIter = executeBGP(pattern, QueryIterRoot.create(cxt2), cxt2);
            Table t2 = TableFactory.create(qIter);
            Table t3 = evaluator.join(t1, t2);
            concat.add(t3.iterator(cxt2));
        }
        return TableFactory.create(concat);
    }
}
Also used : Binding(org.apache.jena.sparql.engine.binding.Binding) Table(org.apache.jena.sparql.algebra.Table) Var(org.apache.jena.sparql.core.Var) ARQInternalErrorException(org.apache.jena.sparql.ARQInternalErrorException) Node(org.apache.jena.graph.Node) BasicPattern(org.apache.jena.sparql.core.BasicPattern) TableEmpty(org.apache.jena.sparql.algebra.table.TableEmpty) DatasetGraph(org.apache.jena.sparql.core.DatasetGraph) QueryIterConcat(org.apache.jena.sparql.engine.iterator.QueryIterConcat) ExecutionContext(org.apache.jena.sparql.engine.ExecutionContext) DatasetGraph(org.apache.jena.sparql.core.DatasetGraph) OpGraph(org.apache.jena.sparql.algebra.op.OpGraph) Graph(org.apache.jena.graph.Graph) QueryIterator(org.apache.jena.sparql.engine.QueryIterator)

Aggregations

QueryIterator (org.apache.jena.sparql.engine.QueryIterator)5 QueryIterConcat (org.apache.jena.sparql.engine.iterator.QueryIterConcat)5 Node (org.apache.jena.graph.Node)4 Binding (org.apache.jena.sparql.engine.binding.Binding)4 Graph (org.apache.jena.graph.Graph)1 ARQInternalErrorException (org.apache.jena.sparql.ARQInternalErrorException)1 Op (org.apache.jena.sparql.algebra.Op)1 Table (org.apache.jena.sparql.algebra.Table)1 OpGraph (org.apache.jena.sparql.algebra.op.OpGraph)1 TableEmpty (org.apache.jena.sparql.algebra.table.TableEmpty)1 BasicPattern (org.apache.jena.sparql.core.BasicPattern)1 DatasetGraph (org.apache.jena.sparql.core.DatasetGraph)1 Var (org.apache.jena.sparql.core.Var)1 ExecutionContext (org.apache.jena.sparql.engine.ExecutionContext)1 QueryIterYieldN (org.apache.jena.sparql.engine.iterator.QueryIterYieldN)1