Search in sources :

Example 76 with Var

use of org.apache.jena.sparql.core.Var in project jena by apache.

the class SolverLib method graphNames.

/** Find all the graph names in the quads table. */
public static QueryIterator graphNames(DatasetGraphTDB ds, Node graphNode, QueryIterator input, Predicate<Tuple<NodeId>> filter, ExecutionContext execCxt) {
    List<Abortable> killList = new ArrayList<>();
    Iterator<Tuple<NodeId>> iter1 = ds.getQuadTable().getNodeTupleTable().find(NodeId.NodeIdAny, NodeId.NodeIdAny, NodeId.NodeIdAny, NodeId.NodeIdAny);
    if (filter != null)
        iter1 = Iter.filter(iter1, filter);
    Iterator<NodeId> iter2 = Iter.map(iter1, (t) -> t.get(0));
    iter2 = makeAbortable(iter2, killList);
    Iterator<NodeId> iter3 = Iter.distinct(iter2);
    iter3 = makeAbortable(iter3, killList);
    Iterator<Node> iter4 = NodeLib.nodes(ds.getQuadTable().getNodeTupleTable().getNodeTable(), iter3);
    final Var var = Var.alloc(graphNode);
    Iterator<Binding> iterBinding = Iter.map(iter4, node -> BindingFactory.binding(var, node));
    // Not abortable.
    return new QueryIterTDB(iterBinding, killList, input, execCxt);
}
Also used : Binding(org.apache.jena.sparql.engine.binding.Binding) Var(org.apache.jena.sparql.core.Var) Node(org.apache.jena.graph.Node) NodeId(org.apache.jena.tdb.store.NodeId) Tuple(org.apache.jena.atlas.lib.tuple.Tuple)

Example 77 with Var

use of org.apache.jena.sparql.core.Var in project jena by apache.

the class BindingNodeId method putAll.

public void putAll(BindingNodeId other) {
    Iterator<Var> vIter = other.iterator();
    for (; vIter.hasNext(); ) {
        Var v = vIter.next();
        if (v == null)
            throw new IllegalArgumentException("Null key");
        NodeId n = other.get(v);
        if (n == null)
            throw new IllegalArgumentException("(" + v + "," + n + ")");
        super.put(v, n);
    }
}
Also used : Var(org.apache.jena.sparql.core.Var) NodeId(org.apache.jena.tdb.store.NodeId)

Example 78 with Var

use of org.apache.jena.sparql.core.Var in project jena by apache.

the class BinRDF method writeResultSet.

public static void writeResultSet(TProtocol protocol, ResultSet resultSet, boolean encodeValues) {
    List<Var> vars = Var.varList(resultSet.getResultVars());
    try (Binding2Thrift b2t = new Binding2Thrift(protocol, vars, encodeValues)) {
        for (; resultSet.hasNext(); ) {
            Binding b = resultSet.nextBinding();
            b2t.output(b);
        }
    }
//Done by Binding2Thrift.close() -- LibThriftRDF.flush(protocol) ;
}
Also used : Binding(org.apache.jena.sparql.engine.binding.Binding) Var(org.apache.jena.sparql.core.Var)

Example 79 with Var

use of org.apache.jena.sparql.core.Var in project jena by apache.

the class Binding2Thrift method output.

public void output(Binding binding) {
    Iterator<Var> vIter = (vars == null ? null : vars.iterator());
    if (vIter == null)
        vIter = binding.vars();
    //        }) ;
    while (vIter.hasNext()) {
        Var v = vIter.next();
        Node n = binding.get(v);
        RDF_Term rt = (n == null) ? TRDF.tUNDEF : ThriftConvert.convert(n, encodeValues);
        row.addToRow(rt);
    }
    try {
        row.write(protocol);
    } catch (TException e) {
        TRDF.exception(e);
    }
    row.clear();
}
Also used : TException(org.apache.thrift.TException) Var(org.apache.jena.sparql.core.Var) Node(org.apache.jena.graph.Node) RDF_Term(org.apache.jena.riot.thrift.wire.RDF_Term)

Example 80 with Var

use of org.apache.jena.sparql.core.Var 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)

Aggregations

Var (org.apache.jena.sparql.core.Var)264 Node (org.apache.jena.graph.Node)83 ArrayList (java.util.ArrayList)53 Test (org.junit.Test)47 Binding (org.apache.jena.sparql.engine.binding.Binding)33 VarExprList (org.apache.jena.sparql.core.VarExprList)30 Op (org.apache.jena.sparql.algebra.Op)29 Expr (org.apache.jena.sparql.expr.Expr)28 Triple (org.apache.jena.graph.Triple)17 HashMap (java.util.HashMap)15 ContractTest (org.xenei.junit.contract.ContractTest)13 BindingMap (org.apache.jena.sparql.engine.binding.BindingMap)12 Query (org.apache.jena.query.Query)11 ExprList (org.apache.jena.sparql.expr.ExprList)11 SortCondition (org.apache.jena.query.SortCondition)10 ExprVar (org.apache.jena.sparql.expr.ExprVar)10 HashSet (java.util.HashSet)9 Pair (org.apache.jena.atlas.lib.Pair)9 SqlColumn (org.apache.jena.sdb.core.sqlexpr.SqlColumn)9 QueryIterator (org.apache.jena.sparql.engine.QueryIterator)9