Search in sources :

Example 6 with Table

use of org.apache.jena.sparql.algebra.Table in project jena by apache.

the class Eval 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;
}
Also used : ExecutionContext(org.apache.jena.sparql.engine.ExecutionContext) DatasetGraph(org.apache.jena.sparql.core.DatasetGraph) OpGraph(org.apache.jena.sparql.algebra.op.OpGraph) Graph(org.apache.jena.graph.Graph) Table(org.apache.jena.sparql.algebra.Table) Var(org.apache.jena.sparql.core.Var) Node(org.apache.jena.graph.Node) TableEmpty(org.apache.jena.sparql.algebra.table.TableEmpty) ARQInternalErrorException(org.apache.jena.sparql.ARQInternalErrorException) InternalErrorException(org.apache.jena.atlas.lib.InternalErrorException) DatasetGraph(org.apache.jena.sparql.core.DatasetGraph)

Example 7 with Table

use of org.apache.jena.sparql.algebra.Table in project jena by apache.

the class Eval method eval.

public static Table eval(Evaluator evaluator, Op op) {
    EvaluatorDispatch ev = new EvaluatorDispatch(evaluator);
    op.visit(ev);
    Table table = ev.getResult();
    return table;
}
Also used : Table(org.apache.jena.sparql.algebra.Table)

Example 8 with Table

use of org.apache.jena.sparql.algebra.Table in project jena by apache.

the class EvaluatorDispatch method visit.

@Override
public void visit(OpFilter opFilter) {
    Table table = eval(opFilter.getSubOp());
    table = evaluator.filter(opFilter.getExprs(), table);
    push(table);
}
Also used : Table(org.apache.jena.sparql.algebra.Table)

Example 9 with Table

use of org.apache.jena.sparql.algebra.Table in project jena by apache.

the class EvaluatorDispatch method visit.

@Override
public void visit(OpTopN opTop) {
    Table table = eval(opTop.getSubOp());
    //table = evaluator.topN(table, opTop.getLimti(), opTop.getConditions()) ;
    table = evaluator.order(table, opTop.getConditions());
    table = evaluator.slice(table, 0, opTop.getLimit());
    push(table);
}
Also used : Table(org.apache.jena.sparql.algebra.Table)

Example 10 with Table

use of org.apache.jena.sparql.algebra.Table in project jena by apache.

the class EvaluatorDispatch method visit.

@Override
public void visit(OpOrder opOrder) {
    Table table = eval(opOrder.getSubOp());
    table = evaluator.order(table, opOrder.getConditions());
    push(table);
}
Also used : Table(org.apache.jena.sparql.algebra.Table)

Aggregations

Table (org.apache.jena.sparql.algebra.Table)37 Var (org.apache.jena.sparql.core.Var)4 QueryIterator (org.apache.jena.sparql.engine.QueryIterator)4 Binding (org.apache.jena.sparql.engine.binding.Binding)4 Node (org.apache.jena.graph.Node)3 Op (org.apache.jena.sparql.algebra.Op)3 Graph (org.apache.jena.graph.Graph)2 ARQInternalErrorException (org.apache.jena.sparql.ARQInternalErrorException)2 OpGraph (org.apache.jena.sparql.algebra.op.OpGraph)2 TableEmpty (org.apache.jena.sparql.algebra.table.TableEmpty)2 BasicPattern (org.apache.jena.sparql.core.BasicPattern)2 DatasetGraph (org.apache.jena.sparql.core.DatasetGraph)2 ExecutionContext (org.apache.jena.sparql.engine.ExecutionContext)2 Test (org.junit.Test)2 InternalErrorException (org.apache.jena.atlas.lib.InternalErrorException)1 Triple (org.apache.jena.graph.Triple)1 OpBGP (org.apache.jena.sparql.algebra.op.OpBGP)1 OpTable (org.apache.jena.sparql.algebra.op.OpTable)1 TableN (org.apache.jena.sparql.algebra.table.TableN)1 QueryIterConcat (org.apache.jena.sparql.engine.iterator.QueryIterConcat)1