Search in sources :

Example 1 with QueryIterPlainWrapper

use of org.apache.jena.sparql.engine.iterator.QueryIterPlainWrapper 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 QueryIterPlainWrapper

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

the class QueryTest method convertToStrings.

private ResultSetRewindable convertToStrings(ResultSetRewindable resultsActual) {
    List<Binding> bindings = new ArrayList<>();
    while (resultsActual.hasNext()) {
        Binding b = resultsActual.nextBinding();
        BindingMap b2 = BindingFactory.create();
        for (String vn : resultsActual.getResultVars()) {
            Var v = Var.alloc(vn);
            Node n = b.get(v);
            String s;
            if (n == null)
                s = "";
            else if (n.isBlank())
                s = "_:" + n.getBlankNodeLabel();
            else
                s = NodeFunctions.str(n);
            b2.add(v, NodeFactory.createLiteral(s));
        }
        bindings.add(b2);
    }
    ResultSet rs = new ResultSetStream(resultsActual.getResultVars(), null, new QueryIterPlainWrapper(bindings.iterator()));
    return ResultSetFactory.makeRewindable(rs);
}
Also used : Binding(org.apache.jena.sparql.engine.binding.Binding) QueryIterPlainWrapper(org.apache.jena.sparql.engine.iterator.QueryIterPlainWrapper) Var(org.apache.jena.sparql.core.Var) RDFNode(org.apache.jena.rdf.model.RDFNode) Node(org.apache.jena.graph.Node) ArrayList(java.util.ArrayList) ResultSet(org.apache.jena.query.ResultSet) BindingMap(org.apache.jena.sparql.engine.binding.BindingMap) ResultSetStream(org.apache.jena.sparql.engine.ResultSetStream)

Example 3 with QueryIterPlainWrapper

use of org.apache.jena.sparql.engine.iterator.QueryIterPlainWrapper 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 4 with QueryIterPlainWrapper

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

the class BuilderResultSet method build.

public static ResultSet build(Item item) {
    BuilderLib.checkTagged(item, Tags.tagResultSet, "Not a (resultset ...)");
    ItemList list = item.getList();
    List<Var> vars = BuilderNode.buildVarList(list.get(1));
    // skip tag, skip vars.
    int start = 2;
    List<Binding> bindings = new ArrayList<>();
    for (int i = start; i < list.size(); i++) {
        Item itemRow = list.get(i);
        Binding b = BuilderBinding.build(itemRow);
        bindings.add(b);
    }
    QueryIterator qIter = new QueryIterPlainWrapper(bindings.listIterator());
    return new ResultSetStream(Var.varNames(vars), null, qIter);
}
Also used : Binding(org.apache.jena.sparql.engine.binding.Binding) Item(org.apache.jena.sparql.sse.Item) QueryIterPlainWrapper(org.apache.jena.sparql.engine.iterator.QueryIterPlainWrapper) QueryIterator(org.apache.jena.sparql.engine.QueryIterator) Var(org.apache.jena.sparql.core.Var) ItemList(org.apache.jena.sparql.sse.ItemList) ArrayList(java.util.ArrayList) ResultSetStream(org.apache.jena.sparql.engine.ResultSetStream)

Example 5 with QueryIterPlainWrapper

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

the class XMLInputSAX method worker.

private void worker(InputSource in, Model model) {
    if (model == null)
        model = GraphFactory.makeJenaDefaultModel();
    try {
        XMLReader xr = XMLReaderFactory.createXMLReader();
        xr.setFeature("http://xml.org/sax/features/namespace-prefixes", true);
        // ResultSetXMLHandler1 handler = new ResultSetXMLHandler1() ;
        ResultSetXMLHandler2 handler = new ResultSetXMLHandler2();
        xr.setContentHandler(handler);
        xr.parse(in);
        if (handler.isBooleanResult) {
            // Set superclass member
            set(handler.askResult);
            return;
        }
        ResultSetStream rss = new ResultSetStream(handler.variables, model, new QueryIterPlainWrapper(handler.results.iterator()));
        // Set superclass member
        set(rss);
    } catch (SAXException ex) {
        throw new ResultSetException("Problems parsing file (SAXException)", ex);
    } catch (IOException ex) {
        throw new ResultSetException("Problems parsing file (IOException)", ex);
    }
}
Also used : QueryIterPlainWrapper(org.apache.jena.sparql.engine.iterator.QueryIterPlainWrapper) IOException(java.io.IOException) 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