Search in sources :

Example 1 with NodeTupleTable

use of org.apache.jena.tdb.store.nodetupletable.NodeTupleTable 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 2 with NodeTupleTable

use of org.apache.jena.tdb.store.nodetupletable.NodeTupleTable in project jena by apache.

the class DatasetGraphTDB method deleteAny.

@Override
public void deleteAny(Node g, Node s, Node p, Node o) {
    // Delete in batches.
    // That way, there is no active iterator when a delete
    // from the indexes happens.
    NodeTupleTable t = chooseNodeTupleTable(g);
    @SuppressWarnings("unchecked") Tuple<NodeId>[] array = (Tuple<NodeId>[]) new Tuple<?>[sliceSize];
    while (true) {
        // Convert/cache s,p,o?
        // The Node Cache will catch these so don't worry unduely.
        Iterator<Tuple<NodeId>> iter = null;
        if (g == null)
            iter = t.findAsNodeIds(s, p, o);
        else
            iter = t.findAsNodeIds(g, s, p, o);
        if (iter == null)
            // Finished?
            return;
        // Get a slice
        int len = 0;
        for (; len < sliceSize; len++) {
            if (!iter.hasNext())
                break;
            array[len] = iter.next();
        }
        // Delete them.
        for (int i = 0; i < len; i++) {
            t.getTupleTable().delete(array[i]);
            array[i] = null;
        }
        // Finished?
        if (len < sliceSize)
            break;
    }
}
Also used : NodeTupleTable(org.apache.jena.tdb.store.nodetupletable.NodeTupleTable) Tuple(org.apache.jena.atlas.lib.tuple.Tuple)

Example 3 with NodeTupleTable

use of org.apache.jena.tdb.store.nodetupletable.NodeTupleTable in project jena by apache.

the class tdbstats method stats.

public static StatsResults stats(DatasetGraphTDB dsg, Node gn) {
    NodeTable nt = dsg.getTripleTable().getNodeTupleTable().getNodeTable();
    StatsCollectorNodeId stats = new StatsCollectorNodeId(nt);
    if (gn == null) {
        Iterator<Tuple<NodeId>> iter = dsg.getTripleTable().getNodeTupleTable().findAll();
        for (; iter.hasNext(); ) {
            Tuple<NodeId> t = iter.next();
            stats.record(null, t.get(0), t.get(1), t.get(2));
        }
    } else {
        // If the union graph, then we need to scan all quads but with uniqueness.
        boolean unionGraph = Quad.isUnionGraph(gn);
        NodeId gnid = null;
        if (!unionGraph) {
            gnid = nt.getNodeIdForNode(gn);
            if (NodeId.isDoesNotExist(gnid))
                Log.warn(tdbstats.class, "No such graph: " + gn);
        }
        NodeTupleTable ntt = dsg.getQuadTable().getNodeTupleTable();
        Iterator<Tuple<NodeId>> iter = unionGraph ? SolverLib.unionGraph(ntt) : ntt.find(gnid, null, null, null);
        for (; iter.hasNext(); ) {
            Tuple<NodeId> t = iter.next();
            stats.record(t.get(0), t.get(1), t.get(2), t.get(3));
        }
    }
    return stats.results();
}
Also used : NodeTupleTable(org.apache.jena.tdb.store.nodetupletable.NodeTupleTable) NodeId(org.apache.jena.tdb.store.NodeId) StatsCollectorNodeId(org.apache.jena.tdb.solver.stats.StatsCollectorNodeId) NodeTable(org.apache.jena.tdb.store.nodetable.NodeTable) Tuple(org.apache.jena.atlas.lib.tuple.Tuple) StatsCollectorNodeId(org.apache.jena.tdb.solver.stats.StatsCollectorNodeId)

Example 4 with NodeTupleTable

use of org.apache.jena.tdb.store.nodetupletable.NodeTupleTable in project jena by apache.

the class DumpOps method dump.

public static void dump(Dataset ds) {
    DatasetGraphTDB dsg = (DatasetGraphTDB) (ds.asDatasetGraph());
    NodeTupleTable nodeTupleTableTriples = dsg.getTripleTable().getNodeTupleTable();
    NodeTupleTable nodeTupleTableQuads = dsg.getQuadTable().getNodeTupleTable();
    if (nodeTupleTableTriples.getNodeTable() != nodeTupleTableQuads.getNodeTable())
        throw new TDBException("Different node tables for triples and quads");
    NodeTable nodeTable = nodeTupleTableTriples.getNodeTable();
    // V special.
    Set<NodeTable> dumpedNodeTables = new HashSet<>();
    if (true) {
        System.out.print("## Node Table\n");
        dumpNodeTable(nodeTupleTableTriples.getNodeTable(), dumpedNodeTables);
        dumpNodeTable(nodeTupleTableQuads.getNodeTable(), dumpedNodeTables);
    }
    if (false) {
        System.out.print("## Triple Table\n");
        dumpNodeTupleTable(nodeTupleTableTriples.getTupleTable());
        System.out.print("## Quad Table\n");
        dumpNodeTupleTable(nodeTupleTableQuads.getTupleTable());
    }
    // Indexes.
    if (true) {
        dumpTupleIndexes(nodeTupleTableTriples.getTupleTable().getIndexes());
        dumpTupleIndexes(nodeTupleTableQuads.getTupleTable().getIndexes());
    }
    // Prefixes
    if (true) {
        System.out.print("## Prefix Table\n");
        DatasetPrefixesTDB prefixes = dsg.getPrefixes();
        NodeTupleTable pntt = prefixes.getNodeTupleTable();
        if (!dumpedNodeTables.contains(pntt.getNodeTable())) {
            dumpNodeTable(pntt.getNodeTable(), dumpedNodeTables);
            dumpedNodeTables.add(pntt.getNodeTable());
        }
        dumpTupleIndexes(prefixes.getNodeTupleTable().getTupleTable().getIndexes());
    }
}
Also used : NodeTupleTable(org.apache.jena.tdb.store.nodetupletable.NodeTupleTable) TDBException(org.apache.jena.tdb.TDBException) DatasetPrefixesTDB(org.apache.jena.tdb.store.DatasetPrefixesTDB) NodeTable(org.apache.jena.tdb.store.nodetable.NodeTable) DatasetGraphTDB(org.apache.jena.tdb.store.DatasetGraphTDB) HashSet(java.util.HashSet)

Example 5 with NodeTupleTable

use of org.apache.jena.tdb.store.nodetupletable.NodeTupleTable in project jena by apache.

the class DatasetBuilderStd method makePrefixTable.

protected DatasetPrefixesTDB makePrefixTable(Location location, DatasetControl policy, StoreParams params) {
    String primary = params.getPrimaryIndexPrefix();
    String[] indexes = params.getPrefixIndexes();
    TupleIndex[] prefixIndexes = makeTupleIndexes(location, primary, indexes, new String[] { params.getIndexPrefix() }, params);
    if (prefixIndexes.length != 1)
        error(log, "Wrong number of triple table tuples indexes: " + prefixIndexes.length);
    String pnNode2Id = params.getPrefixNode2Id();
    String pnId2Node = params.getPrefixId2Node();
    // No cache - the prefix mapping is a cache
    NodeTable prefixNodes = makeNodeTableNoCache(location, pnNode2Id, pnId2Node, params);
    NodeTupleTable prefixTable = new NodeTupleTableConcrete(primary.length(), prefixIndexes, prefixNodes, policy);
    DatasetPrefixesTDB prefixes = new DatasetPrefixesTDB(prefixTable);
    log.debug("Prefixes: " + primary + " :: " + String.join(",", indexes));
    return prefixes;
}
Also used : NodeTupleTable(org.apache.jena.tdb.store.nodetupletable.NodeTupleTable) NodeTupleTableConcrete(org.apache.jena.tdb.store.nodetupletable.NodeTupleTableConcrete) TupleIndex(org.apache.jena.tdb.store.tupletable.TupleIndex) NodeTable(org.apache.jena.tdb.store.nodetable.NodeTable)

Aggregations

NodeTupleTable (org.apache.jena.tdb.store.nodetupletable.NodeTupleTable)5 Tuple (org.apache.jena.atlas.lib.tuple.Tuple)3 NodeTable (org.apache.jena.tdb.store.nodetable.NodeTable)3 NodeId (org.apache.jena.tdb.store.NodeId)2 HashSet (java.util.HashSet)1 TDBException (org.apache.jena.tdb.TDBException)1 StatsCollectorNodeId (org.apache.jena.tdb.solver.stats.StatsCollectorNodeId)1 DatasetGraphTDB (org.apache.jena.tdb.store.DatasetGraphTDB)1 DatasetPrefixesTDB (org.apache.jena.tdb.store.DatasetPrefixesTDB)1 NodeTupleTableConcrete (org.apache.jena.tdb.store.nodetupletable.NodeTupleTableConcrete)1 TupleIndex (org.apache.jena.tdb.store.tupletable.TupleIndex)1