use of org.apache.jena.sparql.engine.ResultSetStream in project jena by apache.
the class TableBase method toResultSet.
@Override
public ResultSet toResultSet() {
QueryIterator qIter = iterator(null);
ResultSet rs = new ResultSetStream(getVarNames(), null, qIter);
rs = ResultSetFactory.makeRewindable(rs);
qIter.close();
return rs;
}
use of org.apache.jena.sparql.engine.ResultSetStream in project jena by apache.
the class CSVInput method fromCSV.
public static ResultSet fromCSV(InputStream in) {
CSVParser parser = CSVParser.create(in);
final List<Var> vars = vars(parser);
List<String> varNames = Var.varNames(vars);
Function<List<String>, Binding> transform = new Function<List<String>, Binding>() {
private int count = 1;
@Override
public Binding apply(List<String> row) {
if (row.size() != vars.size())
FmtLog.warn(log, "Row %d: Length=%d: expected=%d", count, row.size(), vars.size());
BindingMap binding = BindingFactory.create();
// Check.
for (int i = 0; i < vars.size(); i++) {
Var v = vars.get(i);
String field = (i < row.size()) ? row.get(i) : "";
Node n = NodeFactory.createLiteral(field);
binding.add(v, n);
}
count++;
return binding;
}
};
Iterator<Binding> bindings = Iter.map(parser.iterator(), transform);
//This will parse actual result rows as needed thus minimising memory usage
return new ResultSetStream(varNames, null, bindings);
}
use of org.apache.jena.sparql.engine.ResultSetStream in project jena by apache.
the class JSONInput method process.
// TODO Streaming version of JSON Result set processing
private SPARQLResult process(InputStream in, Model model) {
parse(in);
if (model == null)
model = GraphFactory.makeJenaDefaultModel();
if (rows != null) {
QueryIterator qIter = new QueryIterPlainWrapper(rows.iterator());
ResultSet rs = new ResultSetStream(Var.varNames(vars), model, qIter);
super.set(rs);
} else
super.set(booleanResult);
return this;
}
use of org.apache.jena.sparql.engine.ResultSetStream in project jena by apache.
the class BIOInput method fromBIO.
public static ResultSet fromBIO(InputStream input) {
// Scan the stream for VARS and accumulate the total variables.
// Trade off of guessing first line is all the VARS and coping with
// anything possible. -> Cope with anything possible.
BindingInputStream bin = new BindingInputStream(input);
List<Binding> bindings = new ArrayList<>();
List<Var> vars = new ArrayList<>();
while (bin.hasNext()) {
Binding b = bin.next();
bindings.add(b);
for (Var v : bin.vars()) {
if (!vars.contains(v))
vars.add(v);
}
}
QueryIterator qIter = new QueryIterPlainWrapper(bindings.iterator());
return new ResultSetStream(Var.varNames(vars), m, qIter);
}
Aggregations