Search in sources :

Example 6 with QueryIterPlainWrapper

use of org.apache.jena.sparql.engine.iterator.QueryIterPlainWrapper in project jena by apache.

the class Eval method evalDS.

static Table evalDS(OpDatasetNames opDSN, Evaluator evaluator) {
    Node graphNode = opDSN.getGraphNode();
    if (graphNode.isURI()) {
        if (evaluator.getExecContext().getDataset().containsGraph(graphNode)) {
            return new TableUnit();
        } else // WRONG
        {
            return new TableEmpty();
        }
    }
    if (!Var.isVar(graphNode))
        throw new ARQInternalErrorException("OpDatasetNames: Not a URI or variable: " + graphNode);
    DatasetGraph dsg = evaluator.getExecContext().getDataset();
    Iterator<Node> iter = dsg.listGraphNodes();
    List<Binding> list = new ArrayList<>((int) dsg.size());
    for (; iter.hasNext(); ) {
        Node gn = iter.next();
        Binding b = BindingFactory.binding(Var.alloc(graphNode), gn);
        list.add(b);
    }
    QueryIterator qIter = new QueryIterPlainWrapper(list.iterator(), evaluator.getExecContext());
    return TableFactory.create(qIter);
}
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) Node(org.apache.jena.graph.Node) ARQInternalErrorException(org.apache.jena.sparql.ARQInternalErrorException) ArrayList(java.util.ArrayList) TableEmpty(org.apache.jena.sparql.algebra.table.TableEmpty) TableUnit(org.apache.jena.sparql.algebra.table.TableUnit) DatasetGraph(org.apache.jena.sparql.core.DatasetGraph)

Example 7 with QueryIterPlainWrapper

use of org.apache.jena.sparql.engine.iterator.QueryIterPlainWrapper 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;
}
Also used : QueryIterPlainWrapper(org.apache.jena.sparql.engine.iterator.QueryIterPlainWrapper) QueryIterator(org.apache.jena.sparql.engine.QueryIterator) ResultSet(org.apache.jena.query.ResultSet) ResultSetStream(org.apache.jena.sparql.engine.ResultSetStream)

Example 8 with QueryIterPlainWrapper

use of org.apache.jena.sparql.engine.iterator.QueryIterPlainWrapper 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);
}
Also used : BindingInputStream(org.apache.jena.sparql.engine.binding.BindingInputStream) Binding(org.apache.jena.sparql.engine.binding.Binding) QueryIterPlainWrapper(org.apache.jena.sparql.engine.iterator.QueryIterPlainWrapper) QueryIterator(org.apache.jena.sparql.engine.QueryIterator) Var(org.apache.jena.sparql.core.Var) ArrayList(java.util.ArrayList) ResultSetStream(org.apache.jena.sparql.engine.ResultSetStream)

Aggregations

QueryIterPlainWrapper (org.apache.jena.sparql.engine.iterator.QueryIterPlainWrapper)8 ArrayList (java.util.ArrayList)6 QueryIterator (org.apache.jena.sparql.engine.QueryIterator)6 ResultSetStream (org.apache.jena.sparql.engine.ResultSetStream)6 Binding (org.apache.jena.sparql.engine.binding.Binding)6 ResultSet (org.apache.jena.query.ResultSet)3 Var (org.apache.jena.sparql.core.Var)3 Node (org.apache.jena.graph.Node)2 IOException (java.io.IOException)1 HashSet (java.util.HashSet)1 RDFNode (org.apache.jena.rdf.model.RDFNode)1 ARQInternalErrorException (org.apache.jena.sparql.ARQInternalErrorException)1 TableEmpty (org.apache.jena.sparql.algebra.table.TableEmpty)1 TableUnit (org.apache.jena.sparql.algebra.table.TableUnit)1 DatasetGraph (org.apache.jena.sparql.core.DatasetGraph)1 BindingInputStream (org.apache.jena.sparql.engine.binding.BindingInputStream)1 BindingMap (org.apache.jena.sparql.engine.binding.BindingMap)1 Item (org.apache.jena.sparql.sse.Item)1 ItemList (org.apache.jena.sparql.sse.ItemList)1