static public QueryIterator exec(Op op, DatasetGraph ds) { QueryEngineFactory f = QueryEngineRegistry.findFactory(op, ds, null) ; Plan plan = f.create(op, ds, BindingRoot.create(), null) ; return plan.iterator() ; }
static public QueryIterator execRef(Op op, DatasetGraph dsg) { QueryEngineRef qe = new QueryEngineRef(op, dsg, ARQ.getContext().copy()) ; return qe.getPlan().iterator() ; }
protected static Iterator<Binding> evalBindings(Query query, DatasetGraph dsg, Binding inputBinding, Context context) { // The UpdateProcessorBase already copied the context and made it safe // ... but that's going to happen again :-( Iterator<Binding> toReturn; if ( query != null ) { Plan plan = QueryExecutionFactory.createPlan(query, dsg, inputBinding, context); toReturn = plan.iterator(); } else { toReturn = Iter.singleton((null != inputBinding) ? inputBinding : BindingRoot.create()); } return toReturn; }
private static List<Binding> exec(String queryStr, QueryEngineFactory factory) { Query ast = QueryFactory.create(queryStr); return Iter.toList(factory.create(ast, dsgzero, BindingRoot.create(), ARQ.getContext()).iterator()); }
/** 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)) ; }
/** 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)) ; }