Search in sources :

Example 41 with NodeId

use of org.apache.jena.tdb2.store.NodeId in project jena by apache.

the class BindingTDB method get1.

@Override
public Node get1(Var var) {
    try {
        Node n = cacheGet(var);
        if (n != null)
            return n;
        NodeId id = idBinding.get(var);
        if (id == null)
            return null;
        if (NodeId.isDoesNotExist(id))
            return null;
        n = nodeTable.getNodeForNodeId(id);
        if (n == null)
            // But there was to put it in the BindingNodeId.
            throw new TDBException("No node in NodeTable for NodeId " + id);
        // Update cache.
        cachePut(var, n);
        return n;
    } catch (Exception ex) {
        Log.error(this, String.format("get1(%s)", var), ex);
        return null;
    }
}
Also used : Node(org.apache.jena.graph.Node) TDBException(org.apache.jena.tdb2.TDBException) NodeId(org.apache.jena.tdb2.store.NodeId) TDBException(org.apache.jena.tdb2.TDBException)

Example 42 with NodeId

use of org.apache.jena.tdb2.store.NodeId in project jena by apache.

the class BindingTDB method fmtVar.

@Override
protected void fmtVar(StringBuffer sbuff, Var var) {
    NodeId id = idBinding.get(var);
    String extra = "";
    if (id != null)
        extra = "/" + id;
    Node node = get(var);
    String tmp = NodeFmtLib.displayStr(node);
    sbuff.append("( ?" + var.getVarName() + extra + " = " + tmp + " )");
}
Also used : Node(org.apache.jena.graph.Node) NodeId(org.apache.jena.tdb2.store.NodeId)

Example 43 with NodeId

use of org.apache.jena.tdb2.store.NodeId in project jena by apache.

the class SolverRX method accessData.

static Iterator<Quad> accessData(Tuple<Node> patternTuple, NodeTupleTable nodeTupleTable, boolean anyGraph, Predicate<Tuple<NodeId>> filter, ExecutionContext execCxt) {
    NodeTable nodeTable = nodeTupleTable.getNodeTable();
    Function<Tuple<NodeId>, Quad> asQuad = asQuad(nodeTable, nodeTupleTable.getTupleLen(), anyGraph);
    Tuple<NodeId> patternTupleId = TupleLib.tupleNodeIds(nodeTable, patternTuple);
    if (patternTupleId.contains(NodeId.NodeDoesNotExist))
        // Can not match.
        return Iter.nullIterator();
    // -- DRY/StageMatchTuple ??
    Iterator<Tuple<NodeId>> iterMatches = nodeTupleTable.find(patternTupleId);
    // Add filter
    if (filter != null)
        iterMatches = Iter.filter(iterMatches, filter);
    // Add anyGraph
    if (anyGraph) {
        // See StageMatchTuple for discussion.
        iterMatches = Iter.map(iterMatches, quadsToAnyTriples);
        iterMatches = Iter.distinctAdjacent(iterMatches);
    }
    // -- DRY/StageMatchTuple
    Iterator<Quad> qIter = Iter.map(iterMatches, asQuad);
    return qIter;
}
Also used : Quad(org.apache.jena.sparql.core.Quad) NodeId(org.apache.jena.tdb2.store.NodeId) NodeTable(org.apache.jena.tdb2.store.nodetable.NodeTable) Tuple(org.apache.jena.atlas.lib.tuple.Tuple)

Example 44 with NodeId

use of org.apache.jena.tdb2.store.NodeId in project jena by apache.

the class StageMatchTuple method tupleToBinding.

private static BindingNodeId tupleToBinding(BindingNodeId input, Tuple<NodeId> tuple, Var[] var) {
    // Reuseable BindingNodeId builder?
    BindingNodeId output = new BindingNodeId(input);
    for (int i = 0; i < var.length; i++) {
        Var v = var[i];
        if (v == null)
            continue;
        NodeId id = tuple.get(i);
        if (!compatible(output, v, id))
            return null;
        output.put(v, id);
    }
    return output;
}
Also used : Var(org.apache.jena.sparql.core.Var) NodeId(org.apache.jena.tdb2.store.NodeId)

Example 45 with NodeId

use of org.apache.jena.tdb2.store.NodeId in project jena by apache.

the class DatasetGraphTDB method listGraphNodes.

@Override
public Iterator<Node> listGraphNodes() {
    checkNotClosed();
    NodeTupleTable quads = getQuadTable().getNodeTupleTable();
    Iterator<Tuple<NodeId>> x = quads.findAll();
    // XXX Future: Ensure we scan a G??? index and use distinctAdjacent.
    // See TupleTable.chooseScanAllIndex
    Iterator<NodeId> z = Iter.iter(x).map(t -> t.get(0)).distinct();
    Iterator<Node> r = NodeLib.nodes(quads.getNodeTable(), z);
    return r;
}
Also used : DatasetGraphStorage(org.apache.jena.dboe.storage.system.DatasetGraphStorage) Iterator(java.util.Iterator) ReorderTransformation(org.apache.jena.sparql.engine.optimizer.reorder.ReorderTransformation) StoragePrefixes(org.apache.jena.dboe.storage.StoragePrefixes) TDBException(org.apache.jena.tdb2.TDBException) NodeTupleTable(org.apache.jena.tdb2.store.nodetupletable.NodeTupleTable) Graph(org.apache.jena.graph.Graph) StoreParams(org.apache.jena.tdb2.params.StoreParams) Location(org.apache.jena.dboe.base.file.Location) Node(org.apache.jena.graph.Node) Quad(org.apache.jena.sparql.core.Quad) NodeLib(org.apache.jena.tdb2.lib.NodeLib) Iter(org.apache.jena.atlas.iterator.Iter) Tuple(org.apache.jena.atlas.lib.tuple.Tuple) TransactionalSystem(org.apache.jena.dboe.transaction.txn.TransactionalSystem) NodeTupleTable(org.apache.jena.tdb2.store.nodetupletable.NodeTupleTable) Node(org.apache.jena.graph.Node) Tuple(org.apache.jena.atlas.lib.tuple.Tuple)

Aggregations

NodeId (org.apache.jena.tdb2.store.NodeId)47 Node (org.apache.jena.graph.Node)24 Tuple (org.apache.jena.atlas.lib.tuple.Tuple)16 TDBException (org.apache.jena.tdb2.TDBException)12 NodeTable (org.apache.jena.tdb2.store.nodetable.NodeTable)11 Quad (org.apache.jena.sparql.core.Quad)7 ArrayList (java.util.ArrayList)6 Var (org.apache.jena.sparql.core.Var)6 Triple (org.apache.jena.graph.Triple)5 NodeTupleTable (org.apache.jena.tdb2.store.nodetupletable.NodeTupleTable)5 Iterator (java.util.Iterator)4 Binding (org.apache.jena.sparql.engine.binding.Binding)4 StatsCollectorNodeId (org.apache.jena.tdb2.solver.stats.StatsCollectorNodeId)4 Predicate (java.util.function.Predicate)3 Iter (org.apache.jena.atlas.iterator.Iter)3 Record (org.apache.jena.dboe.base.record.Record)3 TupleIndex (org.apache.jena.tdb2.store.tupletable.TupleIndex)3 Test (org.junit.Test)3 List (java.util.List)2 Function (java.util.function.Function)2