Search in sources :

Example 16 with BindingMap

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

the class QueryIterAssign method accept.

@Override
public Binding accept(Binding binding) {
    BindingMap b = BindingFactory.create(binding);
    for (Var v : exprs.getVars()) {
        // if "binding", not "b" used, we get (Lisp) "let" 
        // semantics, not the desired "let*" semantics
        Node n = exprs.get(v, b, getExecContext());
        if (n == null)
            // Expression failed to evaluate - no assignment
            continue;
        // Check is already has a value; if so, must be sameValueAs
        if (b.contains(v)) {
            // Optimization may linearize to push a stream through an (extend).
            if (false && mustBeNewVar)
                throw new QueryExecException("Already set: " + v);
            Node n2 = b.get(v);
            if (!n2.sameValueAs(n))
                // Error in single assignment.
                return null;
            continue;
        }
        b.add(v, n);
    }
    return b;
}
Also used : Var(org.apache.jena.sparql.core.Var) Node(org.apache.jena.graph.Node) BindingMap(org.apache.jena.sparql.engine.binding.BindingMap) QueryExecException(org.apache.jena.query.QueryExecException)

Example 17 with BindingMap

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

the class SolverLib method convToBinding.

public static Binding convToBinding(BindingNodeId bindingNodeIds, NodeTable nodeTable) {
    if (true)
        return new BindingTDB(bindingNodeIds, nodeTable);
    else {
        // Makes nodes immediately. Causing unnecessary NodeTable accesses
        // (e.g. project)
        BindingMap b = BindingFactory.create();
        for (Var v : bindingNodeIds) {
            NodeId id = bindingNodeIds.get(v);
            Node n = nodeTable.getNodeForNodeId(id);
            b.add(v, n);
        }
        return b;
    }
}
Also used : Var(org.apache.jena.sparql.core.Var) Node(org.apache.jena.graph.Node) NodeId(org.apache.jena.tdb.store.NodeId) BindingMap(org.apache.jena.sparql.engine.binding.BindingMap)

Example 18 with BindingMap

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

the class SQLBridge1 method assembleBinding.

@Override
protected Binding assembleBinding(ResultSetJDBC rs, Binding parent) {
    BindingMap b = BindingFactory.create(parent);
    for (Var v : getProject()) {
        String sqlVarName = getSqlName(v);
        if (sqlVarName == null)
            // Not mentioned in query.
            continue;
        try {
            // because of encoding into SPARQL terms, this is never the empty string.
            String s = rs.get().getString(sqlVarName);
            // Same as rs.wasNull() for things that can return Java nulls.
            if (s == null)
                continue;
            // TupleLoaderSimple used SqlConstant which made the string SQL-safe
            // so it could be embedded in a non-prepared statement.  
            s = SQLUtils.unescapeStr(s);
            Node n = codec.decode(s);
            b.add(v, n);
        // Ignore any access error (variable requested not in results)
        } catch (SQLException ex) {
        }
    }
    return b;
}
Also used : SQLException(java.sql.SQLException) Var(org.apache.jena.sparql.core.Var) SqlNode(org.apache.jena.sdb.core.sqlnode.SqlNode) Node(org.apache.jena.graph.Node) BindingMap(org.apache.jena.sparql.engine.binding.BindingMap)

Example 19 with BindingMap

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

the class Algebra method merge.

// This is the SPARQL merge rule. 
public static Binding merge(Binding bindingLeft, Binding bindingRight) {
    // Test to see if compatible: Iterate over variables in left
    boolean matches = compatible(bindingLeft, bindingRight);
    if (!matches)
        return null;
    // If compatible, merge. Iterate over variables in right but not in left.
    BindingMap b = BindingFactory.create(bindingLeft);
    for (Iterator<Var> vIter = bindingRight.vars(); vIter.hasNext(); ) {
        Var v = vIter.next();
        Node n = bindingRight.get(v);
        if (!bindingLeft.contains(v))
            b.add(v, n);
    }
    return b;
}
Also used : Var(org.apache.jena.sparql.core.Var) Node(org.apache.jena.graph.Node) BindingMap(org.apache.jena.sparql.engine.binding.BindingMap)

Example 20 with BindingMap

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

the class NodeTransformLib method transform.

public static Binding transform(Binding b, NodeTransform transform) {
    BindingMap b2 = BindingFactory.create();
    List<Var> vars = Iter.toList(b.vars());
    for (Var v : vars) {
        Var v2 = (Var) transform.apply(v);
        b2.add(v2, b.get(v));
    }
    return b2;
}
Also used : BindingMap(org.apache.jena.sparql.engine.binding.BindingMap)

Aggregations

BindingMap (org.apache.jena.sparql.engine.binding.BindingMap)29 Node (org.apache.jena.graph.Node)18 Var (org.apache.jena.sparql.core.Var)12 Binding (org.apache.jena.sparql.engine.binding.Binding)10 ArrayList (java.util.ArrayList)8 QueryIterPlainWrapper (org.apache.jena.sparql.engine.iterator.QueryIterPlainWrapper)5 ResultSetStream (org.apache.jena.sparql.engine.ResultSetStream)4 ResultSet (org.apache.jena.query.ResultSet)3 QueryIterator (org.apache.jena.sparql.engine.QueryIterator)3 SQLException (java.sql.SQLException)2 SqlNode (org.apache.jena.sdb.core.sqlnode.SqlNode)2 BuilderResultSet (org.apache.jena.sparql.sse.builders.BuilderResultSet)2 ResultSet (java.sql.ResultSet)1 List (java.util.List)1 Function (java.util.function.Function)1 CSVParser (org.apache.jena.atlas.csv.CSVParser)1 IteratorDelayedInitialization (org.apache.jena.atlas.iterator.IteratorDelayedInitialization)1 JsonArray (org.apache.jena.atlas.json.JsonArray)1 JsonObject (org.apache.jena.atlas.json.JsonObject)1 JsonValue (org.apache.jena.atlas.json.JsonValue)1