use of org.apache.jena.sparql.algebra.Table in project jena by apache.
the class EvaluatorDispatch method visit.
@Override
public void visit(OpConditional opCond) {
Table left = eval(opCond.getLeft());
// Ref engine - don;'t care about efficiency
Table right = eval(opCond.getRight());
Table table = evaluator.condition(left, right);
push(table);
}
use of org.apache.jena.sparql.algebra.Table in project jena by apache.
the class EvaluatorDispatch method visit.
@Override
public void visit(OpList opList) {
Table table = eval(opList.getSubOp());
table = evaluator.list(table);
push(table);
}
use of org.apache.jena.sparql.algebra.Table in project jena by apache.
the class EvaluatorDispatch method visit.
@Override
public void visit(OpReduced opReduced) {
Table table = eval(opReduced.getSubOp());
table = evaluator.reduced(table);
push(table);
}
use of org.apache.jena.sparql.algebra.Table in project jena by apache.
the class BuilderTable method build.
public static Table build(Item item) {
BuilderLib.checkTagged(item, Tags.tagTable, "Not a (table ...)");
ItemList list = item.getList();
int start = 1;
if (list.size() == 1)
// Null table;
return TableFactory.createEmpty();
// Maybe vars.
List<Var> vars = null;
if (list.size() > 1) {
Item item0 = list.get(1);
if (item0.isTagged(Tags.tagVars)) {
vars = BuilderNode.buildVarList(item0);
list = list.cdr();
}
}
if (list.size() == 2 && list.get(1).isSymbol()) {
// Short hand for well known tables
String symbol = list.get(1).getSymbol();
if (symbol.equals("unit"))
return TableFactory.createUnit();
if (symbol.equals("empty"))
return TableFactory.createEmpty();
BuilderLib.broken(list, "Don't recognized table symbol");
}
Table table = TableFactory.create(vars);
int count = 0;
Binding lastBinding = null;
for (int i = start; i < list.size(); i++) {
Item itemRow = list.get(i);
Binding b = BuilderBinding.build(itemRow);
table.addBinding(b);
lastBinding = b;
count++;
}
if (table.size() == 1) {
// One row, no bindings.
if (lastBinding.isEmpty())
return TableFactory.createUnit();
}
return table;
}
use of org.apache.jena.sparql.algebra.Table 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);
}
}
Aggregations