use of org.apache.jena.sparql.algebra.op.OpGraph 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.algebra.op.OpGraph in project jena by apache.
the class TransformUnionQuery method union.
private Op union(OpBGP opBGP) {
// By using the unbinding Var.ANON, the distinct works.
// Else, we get duplicates from projection out of the graph var.
// varAlloc.allocVar() ;
Var v = Var.ANON;
Op op = new OpGraph(v, opBGP);
op = OpDistinct.create(op);
return op;
}
use of org.apache.jena.sparql.algebra.op.OpGraph in project jena by apache.
the class RefEval 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.algebra.op.OpGraph in project jena by apache.
the class RefEval method evalGraph.
static Table evalGraph(OpGraph opGraph, Evaluator evaluator) {
ExecutionContext execCxt = evaluator.getExecContext();
if (!Var.isVar(opGraph.getNode())) {
DatasetGraph dsg = execCxt.getDataset();
Node graphNode = opGraph.getNode();
if (!dsg.containsGraph(graphNode))
return new TableEmpty();
Graph graph = execCxt.getDataset().getGraph(opGraph.getNode());
if (// But contains was true?!!
graph == null)
throw new InternalErrorException("Graph was present, now it's not");
ExecutionContext execCxt2 = new ExecutionContext(execCxt, graph);
Evaluator e2 = EvaluatorFactory.create(execCxt2);
return eval(e2, opGraph.getSubOp());
}
// Graph node is a variable.
Var gVar = Var.alloc(opGraph.getNode());
Table current = null;
for (Iterator<Node> iter = execCxt.getDataset().listGraphNodes(); iter.hasNext(); ) {
Node gn = iter.next();
Graph graph = execCxt.getDataset().getGraph(gn);
ExecutionContext execCxt2 = new ExecutionContext(execCxt, graph);
Evaluator e2 = EvaluatorFactory.create(execCxt2);
Table tableVarURI = TableFactory.create(gVar, gn);
// Evaluate the pattern, join with this graph node possibility.
// XXX If Var.ANON then no-opt.
Table patternTable = eval(e2, opGraph.getSubOp());
Table stepResult = evaluator.join(patternTable, tableVarURI);
if (current == null)
current = stepResult;
else
current = evaluator.union(current, stepResult);
}
if (current == null)
// Nothing to loop over
return new TableEmpty();
return current;
}
Aggregations