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));
}
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);
}
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;
}
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));
}
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));
}
Aggregations