Search in sources :

Example 6 with NodeId

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

the class NodeTableTrans method append.

/** Copy from the journal file to the real file */
/*package*/
void append() {
    Iterator<Pair<NodeId, Node>> iter = nodeTableJournal.all();
    Pair<NodeId, Node> firstPair = null;
    Pair<NodeId, Node> lastPair = null;
    for (; iter.hasNext(); ) {
        Pair<NodeId, Node> x = iter.next();
        if (firstPair == null)
            firstPair = x;
        lastPair = x;
        NodeId nodeId = x.getLeft();
        Node node = x.getRight();
        debug("  append: %s -> %s", x, mapFromJournal(nodeId));
        // This does the write.
        NodeId nodeId2 = base.getAllocateNodeId(node);
        if (!nodeId2.equals(mapFromJournal(nodeId)))
            inconsistent(node, nodeId, nodeId2);
    }
}
Also used : Node(org.apache.jena.graph.Node) NodeId(org.apache.jena.tdb.store.NodeId) Pair(org.apache.jena.atlas.lib.Pair)

Example 7 with NodeId

use of org.apache.jena.tdb.store.NodeId 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 8 with NodeId

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

the class SolverLib method testForGraphName.

/** Find whether a specific graph name is in the quads table. */
public static QueryIterator testForGraphName(DatasetGraphTDB ds, Node graphNode, QueryIterator input, Predicate<Tuple<NodeId>> filter, ExecutionContext execCxt) {
    NodeId nid = TDBInternal.getNodeId(ds, graphNode);
    boolean exists = !NodeId.isDoesNotExist(nid);
    if (exists) {
        // Node exists but is it used in the quad position?
        NodeTupleTable ntt = ds.getQuadTable().getNodeTupleTable();
        // Don't worry about abortable - this iterator should be fast
        // (with normal indexing - at least one G???).
        // Either it finds a starting point, or it doesn't.  We are only 
        // interested in the first .hasNext.
        Iterator<Tuple<NodeId>> iter1 = ntt.find(nid, NodeId.NodeIdAny, NodeId.NodeIdAny, NodeId.NodeIdAny);
        if (filter != null)
            iter1 = Iter.filter(iter1, filter);
        exists = iter1.hasNext();
    }
    if (exists)
        return input;
    else {
        input.close();
        return QueryIterNullIterator.create(execCxt);
    }
}
Also used : NodeTupleTable(org.apache.jena.tdb.store.nodetupletable.NodeTupleTable) NodeId(org.apache.jena.tdb.store.NodeId) Tuple(org.apache.jena.atlas.lib.tuple.Tuple)

Example 9 with NodeId

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

the class SolverLib method convertToNodeIds.

public static Set<NodeId> convertToNodeIds(Collection<Node> nodes, DatasetGraphTDB dataset) {
    Set<NodeId> graphIds = new HashSet<>();
    NodeTable nt = dataset.getQuadTable().getNodeTupleTable().getNodeTable();
    for (Node n : nodes) graphIds.add(nt.getNodeIdForNode(n));
    return graphIds;
}
Also used : Node(org.apache.jena.graph.Node) NodeId(org.apache.jena.tdb.store.NodeId) NodeTable(org.apache.jena.tdb.store.nodetable.NodeTable)

Example 10 with NodeId

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

the class LoaderNodeTupleTable method copyIndex.

static void copyIndex(Iterator<Tuple<NodeId>> srcIter, TupleIndex[] destIndexes, String label, LoadMonitor monitor) {
    monitor.startIndex(label);
    long counter = 0;
    for (; srcIter.hasNext(); ) {
        counter++;
        Tuple<NodeId> tuple = srcIter.next();
        monitor.indexItem();
        for (TupleIndex destIdx : destIndexes) {
            if (destIdx != null)
                destIdx.add(tuple);
        }
    }
    monitor.finishIndex(label);
}
Also used : NodeId(org.apache.jena.tdb.store.NodeId) TupleIndex(org.apache.jena.tdb.store.tupletable.TupleIndex)

Aggregations

NodeId (org.apache.jena.tdb.store.NodeId)76 Tuple (org.apache.jena.atlas.lib.tuple.Tuple)29 BaseTest (org.apache.jena.atlas.junit.BaseTest)28 Test (org.junit.Test)28 TupleIndex (org.apache.jena.tdb.store.tupletable.TupleIndex)20 Node (org.apache.jena.graph.Node)18 NodeTable (org.apache.jena.tdb.store.nodetable.NodeTable)10 Pair (org.apache.jena.atlas.lib.Pair)5 Var (org.apache.jena.sparql.core.Var)5 TDBException (org.apache.jena.tdb.TDBException)5 Record (org.apache.jena.tdb.base.record.Record)5 StatsCollectorNodeId (org.apache.jena.tdb.solver.stats.StatsCollectorNodeId)5 NodeTableTrans (org.apache.jena.tdb.transaction.NodeTableTrans)5 Transaction (org.apache.jena.tdb.transaction.Transaction)5 Predicate (java.util.function.Predicate)2 Location (org.apache.jena.tdb.base.file.Location)2 RangeIndex (org.apache.jena.tdb.index.RangeIndex)2 StatsResults (org.apache.jena.tdb.solver.stats.StatsResults)2 DatasetGraphTDB (org.apache.jena.tdb.store.DatasetGraphTDB)2 Hash (org.apache.jena.tdb.store.Hash)2