Search in sources :

Example 16 with Table

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);
}
Also used : Table(org.apache.jena.sparql.algebra.Table)

Example 17 with 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);
}
Also used : Table(org.apache.jena.sparql.algebra.Table)

Example 18 with 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);
}
Also used : Table(org.apache.jena.sparql.algebra.Table)

Example 19 with 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;
}
Also used : Binding(org.apache.jena.sparql.engine.binding.Binding) Item(org.apache.jena.sparql.sse.Item) Table(org.apache.jena.sparql.algebra.Table) Var(org.apache.jena.sparql.core.Var) ItemList(org.apache.jena.sparql.sse.ItemList)

Example 20 with 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);
    }
}
Also used : Binding(org.apache.jena.sparql.engine.binding.Binding) Table(org.apache.jena.sparql.algebra.Table) Var(org.apache.jena.sparql.core.Var) ARQInternalErrorException(org.apache.jena.sparql.ARQInternalErrorException) Node(org.apache.jena.graph.Node) BasicPattern(org.apache.jena.sparql.core.BasicPattern) TableEmpty(org.apache.jena.sparql.algebra.table.TableEmpty) DatasetGraph(org.apache.jena.sparql.core.DatasetGraph) QueryIterConcat(org.apache.jena.sparql.engine.iterator.QueryIterConcat) 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) QueryIterator(org.apache.jena.sparql.engine.QueryIterator)

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