Search in sources :

Example 1 with QueryIterator

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

the class QueryTest method unique.

private static ResultSetRewindable unique(ResultSetRewindable results) {
    // VERY crude.  Utilises the fact that bindings have value equality.
    List<Binding> x = new ArrayList<>();
    Set<Binding> seen = new HashSet<>();
    for (; results.hasNext(); ) {
        Binding b = results.nextBinding();
        if (seen.contains(b))
            continue;
        seen.add(b);
        x.add(b);
    }
    QueryIterator qIter = new QueryIterPlainWrapper(x.iterator());
    ResultSet rs = new ResultSetStream(results.getResultVars(), ModelFactory.createDefaultModel(), qIter);
    return ResultSetFactory.makeRewindable(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) ResultSet(org.apache.jena.query.ResultSet) ResultSetStream(org.apache.jena.sparql.engine.ResultSetStream) HashSet(java.util.HashSet)

Example 2 with QueryIterator

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

the class SQLBridgeBase method assembleResults.

@Override
public final QueryIterator assembleResults(ResultSetJDBC rs, Binding binding, ExecutionContext execCxt) {
    if (execCxt == null || execCxt.getContext().isTrueOrUndef(SDB.jdbcStream)) {
        // Stream
        return new QueryIterSQL(rs, binding, execCxt);
    }
    // Debugging or problems with unreleasing JDBC ResultSets - read all in now.
    QueryIterator qIter = new QueryIterSQL(rs, binding, execCxt);
    List<Binding> results = new ArrayList<Binding>();
    for (; qIter.hasNext(); ) results.add(qIter.nextBinding());
    qIter.close();
    return new QueryIterPlainWrapper(results.iterator(), execCxt);
}
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)

Example 3 with QueryIterator

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

the class TupleTable method dump.

// Dump, using SQL.
public void dump() {
    QueryIterator qIter = iterator();
    ResultSetFormatter.out(ResultSetFactory.create(qIter, Var.varNames(vars)));
}
Also used : QueryIterator(org.apache.jena.sparql.engine.QueryIterator)

Example 4 with QueryIterator

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

the class TestSolverTDB method exec.

private static ResultSet exec(String pattern, Graph graph) {
    Op op = SSE.parseOp(pattern, pmap);
    List<Var> vars = new ArrayList<>();
    vars.addAll(OpVars.visibleVars(op));
    QueryIterator qIter = Algebra.exec(op, graph);
    return ResultSetFactory.create(qIter, Var.varNames(vars));
}
Also used : Op(org.apache.jena.sparql.algebra.Op) QueryIterator(org.apache.jena.sparql.engine.QueryIterator) Var(org.apache.jena.sparql.core.Var) ArrayList(java.util.ArrayList)

Example 5 with QueryIterator

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

the class AlgebraEx method main.

public static void main(String[] args) {
    String s = "SELECT DISTINCT ?s { ?s ?p ?o }";
    // Parse
    Query query = QueryFactory.create(s);
    System.out.println(query);
    // Generate algebra
    Op op = Algebra.compile(query);
    op = Algebra.optimize(op);
    System.out.println(op);
    // Execute it.
    QueryIterator qIter = Algebra.exec(op, ExQuerySelect1.createModel());
    // Results
    for (; qIter.hasNext(); ) {
        Binding b = qIter.nextBinding();
        System.out.println(b);
    }
    qIter.close();
}
Also used : Binding(org.apache.jena.sparql.engine.binding.Binding) Op(org.apache.jena.sparql.algebra.Op) Query(org.apache.jena.query.Query) QueryIterator(org.apache.jena.sparql.engine.QueryIterator)

Aggregations

QueryIterator (org.apache.jena.sparql.engine.QueryIterator)146 Binding (org.apache.jena.sparql.engine.binding.Binding)36 Var (org.apache.jena.sparql.core.Var)21 Node (org.apache.jena.graph.Node)19 Op (org.apache.jena.sparql.algebra.Op)19 ArrayList (java.util.ArrayList)18 Triple (org.apache.jena.graph.Triple)13 TableN (org.apache.jena.sparql.algebra.table.TableN)13 QueryIterConcat (org.apache.jena.sparql.engine.iterator.QueryIterConcat)12 ExecutionContext (org.apache.jena.sparql.engine.ExecutionContext)8 ResultSet (org.apache.jena.query.ResultSet)7 DatasetGraph (org.apache.jena.sparql.core.DatasetGraph)7 Graph (org.apache.jena.graph.Graph)6 BasicPattern (org.apache.jena.sparql.core.BasicPattern)6 ResultSetStream (org.apache.jena.sparql.engine.ResultSetStream)6 QueryIterPlainWrapper (org.apache.jena.sparql.engine.iterator.QueryIterPlainWrapper)6 Query (org.apache.jena.query.Query)4 QueryExecException (org.apache.jena.query.QueryExecException)4 ARQInternalErrorException (org.apache.jena.sparql.ARQInternalErrorException)4 Table (org.apache.jena.sparql.algebra.Table)4