Search in sources :

Example 61 with QueryIterator

use of org.apache.jena.sparql.engine.QueryIterator 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));
}
Also used : IndentedWriter(org.apache.jena.atlas.io.IndentedWriter) PlanOp(org.apache.jena.sparql.engine.PlanOp) Op(org.apache.jena.sparql.algebra.Op) TerminationException(jena.cmd.TerminationException) QueryIterator(org.apache.jena.sparql.engine.QueryIterator) ModDataset(arq.cmdline.ModDataset) Dataset(org.apache.jena.query.Dataset) PlanOp(org.apache.jena.sparql.engine.PlanOp) Plan(org.apache.jena.sparql.engine.Plan) DatasetGraph(org.apache.jena.sparql.core.DatasetGraph)

Example 62 with QueryIterator

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

the class TestPath method eval.

private static List<Binding> eval(Graph graph, Node start, String pathStr, Node finish) {
    Path path = SSE.parsePath(pathStr, pmap);
    QueryIterator qIter = PathLib.execTriplePath(BindingFactory.root(), start, path, finish, new ExecutionContext(ARQ.getContext(), graph, null, null));
    return Iter.toList(qIter);
}
Also used : WriterPath(org.apache.jena.sparql.sse.writers.WriterPath) BuilderPath(org.apache.jena.sparql.sse.builders.BuilderPath) ExecutionContext(org.apache.jena.sparql.engine.ExecutionContext) QueryIterator(org.apache.jena.sparql.engine.QueryIterator)

Example 63 with QueryIterator

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

the class TestResultSet method make.

private ResultSet make(String var1, Node val1, String var2, Node val2) {
    BindingMap b = BindingFactory.create();
    b.add(Var.alloc(var1), val1);
    b.add(Var.alloc(var2), val2);
    List<String> vars = new ArrayList<>();
    vars.add(var1);
    vars.add(var2);
    QueryIterator qIter = QueryIterSingleton.create(b, null);
    ResultSet rs = new ResultSetStream(vars, null, qIter);
    return rs;
}
Also used : QueryIterator(org.apache.jena.sparql.engine.QueryIterator) ArrayList(java.util.ArrayList) BuilderResultSet(org.apache.jena.sparql.sse.builders.BuilderResultSet) ResultSet(org.apache.jena.query.ResultSet) BindingMap(org.apache.jena.sparql.engine.binding.BindingMap) ResultSetStream(org.apache.jena.sparql.engine.ResultSetStream)

Example 64 with QueryIterator

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

the class TestResultSet method make2.

private ResultSet make2(String var, Node val) {
    BindingMap b1 = BindingFactory.create();
    b1.add(Var.alloc(var), val);
    BindingMap b2 = BindingFactory.create();
    b2.add(Var.alloc(var), val);
    List<String> vars = new ArrayList<>();
    vars.add(var);
    List<Binding> solutions = new ArrayList<>();
    solutions.add(b1);
    solutions.add(b2);
    QueryIterator qIter = new QueryIterPlainWrapper(solutions.iterator(), null);
    ResultSet rs = new ResultSetStream(vars, null, qIter);
    return rs;
}
Also used : Binding(org.apache.jena.sparql.engine.binding.Binding) QueryIterPlainWrapper(org.apache.jena.sparql.engine.iterator.QueryIterPlainWrapper) QueryIterator(org.apache.jena.sparql.engine.QueryIterator) ArrayList(java.util.ArrayList) BuilderResultSet(org.apache.jena.sparql.sse.builders.BuilderResultSet) ResultSet(org.apache.jena.query.ResultSet) BindingMap(org.apache.jena.sparql.engine.binding.BindingMap) ResultSetStream(org.apache.jena.sparql.engine.ResultSetStream)

Example 65 with QueryIterator

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

the class SpatialOperationPFBase method variableSubject.

private QueryIterator variableSubject(Binding binding, Node s, SpatialMatch match, ExecutionContext execCxt) {
    Var v = Var.alloc(s);
    List<Node> r = query(match);
    // Make distinct. Note interaction with limit is imperfect
    r = Iter.iter(r).distinct().toList();
    QueryIterator qIter = new QueryIterExtendByVar(binding, v, r.iterator(), execCxt);
    return qIter;
}
Also used : QueryIterator(org.apache.jena.sparql.engine.QueryIterator) QueryIterExtendByVar(org.apache.jena.sparql.engine.iterator.QueryIterExtendByVar) Var(org.apache.jena.sparql.core.Var) Node(org.apache.jena.graph.Node) QueryIterExtendByVar(org.apache.jena.sparql.engine.iterator.QueryIterExtendByVar)

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