use of org.apache.jena.sparql.engine.binding.Binding in project jena by apache.
the class E_BNode method evalSpecial.
// Not really a special form but we need access to
// the binding to use a key.
@Override
public NodeValue evalSpecial(Binding binding, FunctionEnv env) {
Expr expr = null;
if (args.size() == 1)
expr = getArg(1);
if (expr == null)
return NodeValue.makeNode(NodeFactory.createBlankNode());
NodeValue x = expr.eval(binding, env);
if (!x.isString())
throw new ExprEvalException("Not a string: " + x);
Integer key = System.identityHashCode(binding);
// IdentityHashMap
// Normally bindings have structural equality (e.g. DISTINCT)
// we want identify as OpAssign/OpExtend mutates a binding to add new pairs.
@SuppressWarnings("unchecked") IdentityHashMap<Binding, LabelToNodeMap> mapping = (IdentityHashMap<Binding, LabelToNodeMap>) env.getContext().get(keyMap);
if (mapping == null) {
mapping = new IdentityHashMap<>();
env.getContext().set(keyMap, mapping);
}
LabelToNodeMap mapper = mapping.get(binding);
if (mapper == null) {
mapper = LabelToNodeMap.createBNodeMap();
mapping.put(binding, mapper);
}
Node bnode = mapper.asNode(x.getString());
return NodeValue.makeNode(bnode);
}
use of org.apache.jena.sparql.engine.binding.Binding 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);
}
use of org.apache.jena.sparql.engine.binding.Binding in project jena by apache.
the class Eval method evalQuadPattern.
static Table evalQuadPattern(OpQuadPattern opQuad, Evaluator evaluator) {
if (opQuad.isEmpty())
return TableFactory.createUnit();
ExecutionContext cxt = evaluator.getExecContext();
DatasetGraph ds = cxt.getDataset();
BasicPattern pattern = opQuad.getBasicPattern();
if (!opQuad.getGraphNode().isVariable()) {
if (!opQuad.getGraphNode().isURI()) {
throw new ARQInternalErrorException("Not a URI or variable: " + opQuad.getGraphNode());
}
Graph g = null;
if (opQuad.isDefaultGraph())
g = ds.getDefaultGraph();
else
g = ds.getGraph(opQuad.getGraphNode());
if (g == null)
return new TableEmpty();
ExecutionContext cxt2 = new ExecutionContext(cxt, g);
QueryIterator qIter = executeBGP(pattern, QueryIterRoot.create(cxt2), cxt2);
return TableFactory.create(qIter);
} else {
// Variable.
Var gVar = Var.alloc(opQuad.getGraphNode());
// Or just just devolve to OpGraph and get OpUnion chain of OpJoin
QueryIterConcat concat = new QueryIterConcat(cxt);
for (Iterator<Node> graphNodes = cxt.getDataset().listGraphNodes(); graphNodes.hasNext(); ) {
Node gn = graphNodes.next();
//Op tableVarURI = TableFactory.create(gn.getName(), Node.createURI(uri)) ;
Graph g = cxt.getDataset().getGraph(gn);
Binding b = BindingFactory.binding(BindingRoot.create(), gVar, gn);
ExecutionContext cxt2 = new ExecutionContext(cxt, g);
// Eval the pattern, eval the variable, join.
// Pattern may be non-linear in the variable - do a pure execution.
Table t1 = TableFactory.create(gVar, gn);
QueryIterator qIter = executeBGP(pattern, QueryIterRoot.create(cxt2), cxt2);
Table t2 = TableFactory.create(qIter);
Table t3 = evaluator.join(t1, t2);
concat.add(t3.iterator(cxt2));
}
return TableFactory.create(concat);
}
}
use of org.apache.jena.sparql.engine.binding.Binding in project jena by apache.
the class ResultSetStream method nextSolution.
/** Moves onto the next result possibility.
* The returned object is actual the binding for this
* result.
*/
@Override
public QuerySolution nextSolution() {
if (queryExecutionIter == null)
// ( queryExecution != null && ! queryExecution.isActive() ) )
throw new NoSuchElementException(this.getClass() + ".next");
Binding binding = nextBinding();
currentQuerySolution = new ResultBinding(model, binding);
return currentQuerySolution;
}
use of org.apache.jena.sparql.engine.binding.Binding in project jena by apache.
the class QueryIter2LoopOnLeft method hasNextBinding.
@Override
protected final boolean hasNextBinding() {
if (slot != null)
return true;
while (getLeft().hasNext()) {
Binding bindingLeft = getLeft().nextBinding();
slot = getNextSlot(bindingLeft);
if (slot != null) {
slot = bindingLeft;
return true;
}
}
getLeft().close();
return false;
}
Aggregations