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);
}
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);
}
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)));
}
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));
}
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();
}
Aggregations