@Override public Plan create(Query query, DatasetGraph dsg, Binding inputBinding, Context context) { if ( !( dsg instanceof DatasetGraphWrapper ) || dsg instanceof DatasetGraphWrapperView ) return null ; DatasetGraph dsg2 = ((DatasetGraphWrapper)dsg).getWrapped() ; return QueryEngineRegistry.findFactory(query, dsg2, context).create(query, dsg2, inputBinding, context) ; }
@Override public Plan create(Op op, DatasetGraph dsg, Binding inputBinding, Context context) { if ( !( dsg instanceof DatasetGraphWrapper ) || dsg instanceof DatasetGraphWrapperView ) return null ; DatasetGraph dsg2 = ((DatasetGraphWrapper)dsg).getWrapped() ; return QueryEngineRegistry.findFactory(op, dsg2, context).create(op, dsg2, inputBinding, context) ; } }
public Plan getPlan() { if ( plan == null ) { Binding inputBinding = null; if ( initialBinding != null ) inputBinding = BindingUtils.asBinding(initialBinding); if ( inputBinding == null ) inputBinding = BindingRoot.create(); plan = qeFactory.create(query, dsg, inputBinding, getContext()); } return plan; }
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() ; }
private static Plan makePlan(Query query, DatasetGraph dataset, Binding input, Context context) { if ( context == null ) context = new Context(ARQ.getContext()) ; if ( input == null ) input = BindingRoot.create() ; QueryEngineFactory f = findFactory(query, dataset, context) ; if ( f == null ) return null ; return f.create(query, dataset, input, context) ; } // ---------------- Internal routines
public static void printPlan(Query query, QueryExecution qe) { QueryEngineFactory f = QueryEngineRegistry.findFactory(query, qe.getDataset().asDatasetGraph(), ARQ.getContext()) ; if ( f == null ) System.err.println("printPlan: Unknown engine type: "+Lib.className(qe)) ; Plan plan = f.create(query, qe.getDataset().asDatasetGraph(), BindingRoot.create(), ARQ.getContext()) ; SerializationContext sCxt = new SerializationContext(query) ; IndentedWriter out = IndentedWriter.stdout ; plan.output(out, sCxt) ; out.flush(); }
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)) ; }