use of org.apache.jena.sparql.engine.Plan in project jena by apache.
the class QueryOutputUtils method printPlan.
// ModQueryOut
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();
}
use of org.apache.jena.sparql.engine.Plan in project jena by apache.
the class sse_query method exec.
@Override
protected void exec() {
Op op = modAlgebra.getOp();
if (op == null) {
System.err.println("No query expression to execute");
throw new TerminationException(9);
}
Dataset dataset = modDataset.getDataset();
// Check there is a dataset.
if (dataset == null)
dataset = DatasetFactory.createGeneral();
modTime.startTimer();
DatasetGraph dsg = dataset.asDatasetGraph();
if (printOp || printPlan) {
if (printOp) {
divider();
IndentedWriter out = new IndentedWriter(System.out, true);
op.output(out);
out.flush();
}
if (printPlan) {
QueryIterator qIter = Algebra.exec(op, dsg);
Plan plan = new PlanOp(op, null, qIter);
divider();
IndentedWriter out = new IndentedWriter(System.out, false);
plan.output(out);
out.flush();
}
//return ;
}
// Do not optimize. Execute as-is.
QueryExecUtils.execute(op, dsg, modResults.getResultsFormat());
long time = modTime.endTimer();
if (modTime.timingEnabled())
System.out.println("Time: " + modTime.timeStr(time));
}
use of org.apache.jena.sparql.engine.Plan in project jena by apache.
the class UpdateEngineWorker method evalBindings.
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;
}
use of org.apache.jena.sparql.engine.Plan 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.Plan 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