Search in sources :

Example 16 with Binding

use of org.apache.jena.sparql.engine.binding.Binding 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 17 with Binding

use of org.apache.jena.sparql.engine.binding.Binding 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 18 with Binding

use of org.apache.jena.sparql.engine.binding.Binding in project jena by apache.

the class TableBase method equals.

@Override
public boolean equals(Object other) {
    if (this == other)
        return true;
    if (!(other instanceof Table))
        return false;
    Table table = (Table) other;
    if (table.size() != this.size())
        return false;
    QueryIterator qIter1 = iterator(null);
    QueryIterator qIter2 = table.iterator(null);
    try {
        for (; qIter1.hasNext(); ) {
            Binding bind1 = qIter1.nextBinding();
            Binding bind2 = qIter2.nextBinding();
            if (!BindingBase.equals(bind1, bind2))
                return false;
        }
        return true;
    } finally {
        qIter1.close();
        qIter2.close();
    }
}
Also used : Binding(org.apache.jena.sparql.engine.binding.Binding) Table(org.apache.jena.sparql.algebra.Table) QueryIterator(org.apache.jena.sparql.engine.QueryIterator)

Example 19 with Binding

use of org.apache.jena.sparql.engine.binding.Binding in project jena by apache.

the class TableBase method hashCode.

@Override
public int hashCode() {
    int hash = 0;
    QueryIterator qIter = iterator(null);
    try {
        for (; qIter.hasNext(); ) {
            Binding binding = qIter.nextBinding();
            hash ^= binding.hashCode();
        }
        return hash;
    } finally {
        qIter.close();
    }
}
Also used : Binding(org.apache.jena.sparql.engine.binding.Binding) QueryIterator(org.apache.jena.sparql.engine.QueryIterator)

Example 20 with Binding

use of org.apache.jena.sparql.engine.binding.Binding in project jena by apache.

the class NodeTransformLib method transform.

public static Table transform(Table table, NodeTransform transform) {
    // Non-streaming rewrite 
    List<Var> vars = transformVars(transform, table.getVars());
    Iterator<Binding> iter = table.rows();
    List<Binding> newRows = new ArrayList<>();
    for (; iter.hasNext(); ) {
        Binding b = iter.next();
        Binding b2 = transform(b, transform);
        newRows.add(b2);
    }
    return new TableData(vars, newRows);
}
Also used : Binding(org.apache.jena.sparql.engine.binding.Binding) ArrayList(java.util.ArrayList) TableData(org.apache.jena.sparql.algebra.table.TableData)

Aggregations

Binding (org.apache.jena.sparql.engine.binding.Binding)132 Node (org.apache.jena.graph.Node)39 ArrayList (java.util.ArrayList)36 Var (org.apache.jena.sparql.core.Var)33 QueryIterator (org.apache.jena.sparql.engine.QueryIterator)27 Test (org.junit.Test)21 QueryIterPlainWrapper (org.apache.jena.sparql.engine.iterator.QueryIterPlainWrapper)16 BindingMap (org.apache.jena.sparql.engine.binding.BindingMap)10 BindingComparator (org.apache.jena.sparql.engine.binding.BindingComparator)8 BuilderBinding (org.apache.jena.sparql.sse.builders.BuilderBinding)8 NoSuchElementException (java.util.NoSuchElementException)7 Triple (org.apache.jena.graph.Triple)7 ResultSetStream (org.apache.jena.sparql.engine.ResultSetStream)7 ARQInternalErrorException (org.apache.jena.sparql.ARQInternalErrorException)5 Op (org.apache.jena.sparql.algebra.Op)5 BasicPattern (org.apache.jena.sparql.core.BasicPattern)5 ResultSet (org.apache.jena.query.ResultSet)4 SortCondition (org.apache.jena.query.SortCondition)4 TableN (org.apache.jena.sparql.algebra.table.TableN)4 File (java.io.File)3