Search in sources :

Example 71 with QueryIterator

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

the class TestDistinctDataBagLimited method createQueryIter.

@Override
protected QueryIterator createQueryIter(List<Binding> data) {
    QueryIterator qIter = new QueryIterPlainWrapper(data.iterator());
    Context cxt = new Context();
    cxt.set(ARQ.spillToDiskThreshold, 2L);
    return new QueryIterDistinct(qIter, new ExecutionContext(cxt, null, null, null));
}
Also used : Context(org.apache.jena.sparql.util.Context) ExecutionContext(org.apache.jena.sparql.engine.ExecutionContext) ExecutionContext(org.apache.jena.sparql.engine.ExecutionContext) QueryIterator(org.apache.jena.sparql.engine.QueryIterator)

Example 72 with QueryIterator

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

the class TestTableJoin method test.

private void test(Table left, Table right, boolean normalJoin, ExprList exprs, Table expected) {
    ExecutionContext execCxt = new ExecutionContext(ARQ.getContext(), null, null, null);
    QueryIterator leftIter = left.iterator(execCxt);
    QueryIterator qIter = normalJoin ? TableJoin.join(leftIter, right, exprs, execCxt) : TableJoin.leftJoin(leftIter, right, exprs, execCxt);
    // Order issues
    Set<String> vars1 = new HashSet<>();
    vars1.addAll(left.getVarNames());
    vars1.addAll(right.getVarNames());
    TableN results = new TableN(qIter);
    boolean b = TableCompare.equalsByTerm(expected, results);
    if (!b) {
        System.out.println("** Expected");
        System.out.println(expected);
        System.out.println("** Actual");
        System.out.println(results);
    }
    assertTrue(b);
}
Also used : ExecutionContext(org.apache.jena.sparql.engine.ExecutionContext) QueryIterator(org.apache.jena.sparql.engine.QueryIterator) TableN(org.apache.jena.sparql.algebra.table.TableN) HashSet(java.util.HashSet)

Example 73 with QueryIterator

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

the class QueryEngineTDB method eval.

@Override
public QueryIterator eval(Op op, DatasetGraph dsg, Binding input, Context context) {
    // Fix DatasetGraph for global union.
    if (context.isTrue(TDB.symUnionDefaultGraph) && !doingDynamicDatasetBySpecialDataset) {
        op = A2.unionDefaultGraphQuads(op);
        Explain.explain("REWRITE(Union default graph)", op, context);
    }
    QueryIterator results = super.eval(op, dsg, input, context);
    results = new QueryIteratorMaterializeBinding(results);
    return results;
}
Also used : QueryIterator(org.apache.jena.sparql.engine.QueryIterator)

Example 74 with QueryIterator

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

the class LibSDB method findTriples.

/** Find triples, in the default graph or a named graph. */
public static Iterator<Triple> findTriples(DatasetGraph dsg, Node g, Node s, Node p, Node o) {
    if (Var.isVar(g))
        throw new InternalErrorException("Graph node is a variable : " + g);
    final Node vs = varOrConst(s, "s");
    final Node vp = varOrConst(p, "p");
    final Node vo = varOrConst(o, "o");
    // Evaluate as an algebra expression
    Triple triple = new Triple(vs, vp, vo);
    BasicPattern pattern = new BasicPattern();
    pattern.add(triple);
    Op op = (g != null) ? new OpQuadPattern(g, pattern) : new OpBGP(pattern);
    Plan plan = QueryEngineSDB.getFactory().create(op, dsg, BindingRoot.create(), null);
    QueryIterator qIter = plan.iterator();
    Iterator<Binding> iter;
    if (SDB.getContext().isTrue(SDB.streamGraphAPI)) {
        // Assumes iterator closed properly.
        iter = qIter;
    } else {
        // ---- Safe version: 
        List<Binding> x = Iter.toList(qIter);
        Iterator<Binding> qIter2 = x.iterator();
        qIter.close();
        iter = qIter2;
    }
    return Iter.map(iter, (b) -> bindingToTriple(vs, vp, vo, b));
}
Also used : Triple(org.apache.jena.graph.Triple) Binding(org.apache.jena.sparql.engine.binding.Binding) Op(org.apache.jena.sparql.algebra.Op) OpQuadPattern(org.apache.jena.sparql.algebra.op.OpQuadPattern) QueryIterator(org.apache.jena.sparql.engine.QueryIterator) Node(org.apache.jena.graph.Node) OpBGP(org.apache.jena.sparql.algebra.op.OpBGP) InternalErrorException(org.apache.jena.atlas.lib.InternalErrorException) BasicPattern(org.apache.jena.sparql.core.BasicPattern) Plan(org.apache.jena.sparql.engine.Plan)

Example 75 with QueryIterator

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

the class LibSDB method findInQuads.

/** Match a quad pattern (not triples in the default graph) */
public static Iterator<Quad> findInQuads(DatasetGraph dsg, Node g, Node s, Node p, Node o) {
    // If null, create and remember a variable, else use the node.
    final Node vg = varOrConst(g, "g");
    final Node vs = varOrConst(s, "s");
    final Node vp = varOrConst(p, "p");
    final Node vo = varOrConst(o, "o");
    Triple triple = new Triple(vs, vp, vo);
    // Evaluate as an algebra expression
    BasicPattern pattern = new BasicPattern();
    pattern.add(triple);
    Op op = new OpQuadPattern(vg, pattern);
    Plan plan = QueryEngineSDB.getFactory().create(op, dsg, BindingRoot.create(), null);
    QueryIterator qIter = plan.iterator();
    Iterator<Binding> iter;
    if (SDB.getContext().isTrue(SDB.streamGraphAPI)) {
        iter = qIter;
    } else {
        // ---- Safe version: 
        List<Binding> x = Iter.toList(qIter);
        Iterator<Binding> qIter2 = x.iterator();
        qIter.close();
        iter = qIter2;
    }
    return Iter.map(iter, (b) -> bindingToQuad(vg, vs, vp, vo, b));
}
Also used : Triple(org.apache.jena.graph.Triple) Binding(org.apache.jena.sparql.engine.binding.Binding) Op(org.apache.jena.sparql.algebra.Op) OpQuadPattern(org.apache.jena.sparql.algebra.op.OpQuadPattern) QueryIterator(org.apache.jena.sparql.engine.QueryIterator) Node(org.apache.jena.graph.Node) BasicPattern(org.apache.jena.sparql.core.BasicPattern) Plan(org.apache.jena.sparql.engine.Plan)

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