Search in sources :

Example 26 with NodeTable

use of org.apache.jena.tdb2.store.nodetable.NodeTable in project jena by apache.

the class SolverLibTDB method convToBinding.

static Binding convToBinding(BindingNodeId bindingNodeIds, NodeTable nodeTable) {
    if (true)
        return new BindingTDB(bindingNodeIds, nodeTable);
    else {
        // Makes nodes immediately. Causing unnecessary NodeTable accesses
        // (e.g. project)
        BindingBuilder builder = Binding.builder();
        for (Var v : bindingNodeIds) {
            NodeId id = bindingNodeIds.get(v);
            Node n = nodeTable.getNodeForNodeId(id);
            builder.add(v, n);
        }
        return builder.build();
    }
}
Also used : BindingBuilder(org.apache.jena.sparql.engine.binding.BindingBuilder) Var(org.apache.jena.sparql.core.Var) Node(org.apache.jena.graph.Node) NodeId(org.apache.jena.tdb2.store.NodeId)

Example 27 with NodeTable

use of org.apache.jena.tdb2.store.nodetable.NodeTable in project jena by apache.

the class SolverLibTDB method convert.

/**
 * Binding {@literal ->} BindingNodeId, given a NodeTable
 */
static BindingNodeId convert(Binding binding, NodeTable nodeTable) {
    if (binding instanceof BindingTDB)
        return ((BindingTDB) binding).getBindingId();
    BindingNodeId b = new BindingNodeId(binding);
    // and copy over, getting NodeIds.
    Iterator<Var> vars = binding.vars();
    for (; vars.hasNext(); ) {
        Var v = vars.next();
        Node n = binding.get(v);
        if (n == null)
            // Can occur with BindingProject
            continue;
        // Rely on the node table cache for efficency - we will likely be
        // repeatedly looking up the same node in different bindings.
        NodeId id = nodeTable.getNodeIdForNode(n);
        // Even put in "does not exist" for a node now known not to be in the DB.
        // Optional: whether to put in "known missing"
        // Currently, we do. The rest of the code should work with either choice.
        // if ( ! NodeId.isDoesNotExist(id) )
        b.put(v, id);
    }
    return b;
}
Also used : Var(org.apache.jena.sparql.core.Var) Node(org.apache.jena.graph.Node) NodeId(org.apache.jena.tdb2.store.NodeId)

Example 28 with NodeTable

use of org.apache.jena.tdb2.store.nodetable.NodeTable in project jena by apache.

the class TDB2StorageBuilder method buildNodeTable.

private NodeTable buildNodeTable(String name, boolean isData) {
    NodeTable nodeTable = buildBaseNodeTable(name);
    nodeTable = addNodeTableCache(nodeTable, params, isData);
    if (nodeTable instanceof NodeTableCache) {
        NodeTableCache nodeTableCache = (NodeTableCache) nodeTable;
        listeners.add(nodeTableCache);
    }
    nodeTable = NodeTableInline.create(nodeTable);
    return nodeTable;
}
Also used : NodeTableCache(org.apache.jena.tdb2.store.nodetable.NodeTableCache) NodeTable(org.apache.jena.tdb2.store.nodetable.NodeTable)

Example 29 with NodeTable

use of org.apache.jena.tdb2.store.nodetable.NodeTable 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 30 with NodeTable

use of org.apache.jena.tdb2.store.nodetable.NodeTable 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)

Aggregations

NodeId (org.apache.jena.tdb2.store.NodeId)21 NodeTable (org.apache.jena.tdb2.store.nodetable.NodeTable)16 Node (org.apache.jena.graph.Node)14 Tuple (org.apache.jena.atlas.lib.tuple.Tuple)6 Quad (org.apache.jena.sparql.core.Quad)6 NodeTupleTable (org.apache.jena.tdb2.store.nodetupletable.NodeTupleTable)6 ArrayList (java.util.ArrayList)5 Triple (org.apache.jena.graph.Triple)5 NodeTableTRDF (org.apache.jena.tdb2.store.nodetable.NodeTableTRDF)5 Iterator (java.util.Iterator)3 Predicate (java.util.function.Predicate)3 RecordFactory (org.apache.jena.dboe.base.record.RecordFactory)3 Index (org.apache.jena.dboe.index.Index)3 RangeIndex (org.apache.jena.dboe.index.RangeIndex)3 Binding (org.apache.jena.sparql.engine.binding.Binding)3 TupleIndex (org.apache.jena.tdb2.store.tupletable.TupleIndex)3 Function (java.util.function.Function)2 Iter (org.apache.jena.atlas.iterator.Iter)2 InternalErrorException (org.apache.jena.atlas.lib.InternalErrorException)2 TupleFactory (org.apache.jena.atlas.lib.tuple.TupleFactory)2