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;
}
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;
}
}
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;
}
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;
}
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;
}
Aggregations