Search in sources :

Example 16 with NodeId

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

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

the class tdbnode method exec.

@Override
protected void exec() {
    DatasetGraphTDB dsg = getDatasetGraphTDB();
    NodeTable nodeTable = dsg.getTripleTable().getNodeTupleTable().getNodeTable();
    Iterator<String> iter = super.getPositional().iterator();
    if (!iter.hasNext()) {
        System.err.println("No node ids");
        return;
    }
    for (; iter.hasNext(); ) {
        String id = iter.next();
        try {
            long x = Long.parseLong(id);
            NodeId nodeId = new NodeId(x);
            Node n = nodeTable.getNodeForNodeId(nodeId);
            //System.out.printf("%s [%d] => %s\n", id, x, n) ;
            Hash h = new Hash(SystemTDB.LenNodeHash);
            NodeLib.setHash(h, n);
            String str = Bytes.asHex(h.getBytes());
            System.out.printf("%s %08d 0x%s # %s\n", id, x, str, n);
        } catch (Exception ex) {
            System.out.println("Failed to decode: " + id);
        }
    }
}
Also used : Node(org.apache.jena.graph.Node) NodeId(org.apache.jena.tdb.store.NodeId) Hash(org.apache.jena.tdb.store.Hash) NodeTable(org.apache.jena.tdb.store.nodetable.NodeTable) DatasetGraphTDB(org.apache.jena.tdb.store.DatasetGraphTDB)

Example 18 with NodeId

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

the class TestNodeId method nodeId_02.

@Test
public void nodeId_02() {
    NodeId nodeId = NodeId.create(-1L);
    assertEquals(-1L, nodeId.getId());
}
Also used : NodeId(org.apache.jena.tdb.store.NodeId) BaseTest(org.apache.jena.atlas.junit.BaseTest) Test(org.junit.Test)

Example 19 with NodeId

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

the class TestQuadFilter method createFilter.

/** Create a filter to exclude the graph http://example/g2 */
private static Predicate<Tuple<NodeId>> createFilter(Dataset ds) {
    DatasetGraphTDB dsg = (DatasetGraphTDB) (ds.asDatasetGraph());
    final NodeTable nodeTable = dsg.getQuadTable().getNodeTupleTable().getNodeTable();
    final NodeId target = nodeTable.getNodeIdForNode(NodeFactory.createURI(graphToHide));
    return item -> !(item.len() == 4 && item.get(0).equals(target));
}
Also used : AfterClass(org.junit.AfterClass) BeforeClass(org.junit.BeforeClass) NodeFactory(org.apache.jena.graph.NodeFactory) org.apache.jena.query(org.apache.jena.query) Predicate(java.util.function.Predicate) Test(org.junit.Test) SystemTDB(org.apache.jena.tdb.sys.SystemTDB) NodeId(org.apache.jena.tdb.store.NodeId) SSE(org.apache.jena.sparql.sse.SSE) DatasetGraphTDB(org.apache.jena.tdb.store.DatasetGraphTDB) BaseTest(org.apache.jena.atlas.junit.BaseTest) NodeTable(org.apache.jena.tdb.store.nodetable.NodeTable) Quad(org.apache.jena.sparql.core.Quad) TDBFactory(org.apache.jena.tdb.TDBFactory) Tuple(org.apache.jena.atlas.lib.tuple.Tuple) TDB(org.apache.jena.tdb.TDB) NodeId(org.apache.jena.tdb.store.NodeId) NodeTable(org.apache.jena.tdb.store.nodetable.NodeTable) DatasetGraphTDB(org.apache.jena.tdb.store.DatasetGraphTDB)

Example 20 with NodeId

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

the class AbstractTestNodeTable method writeNode.

protected static void writeNode(NodeTable nt, Node n) {
    NodeId nodeId = nt.getAllocateNodeId(n);
    assertNotNull(nodeId);
    assertNotEquals(NodeId.NodeDoesNotExist, nodeId);
    assertNotEquals(NodeId.NodeIdAny, nodeId);
    Node n2 = nt.getNodeForNodeId(nodeId);
    assertEquals(n, n2);
    NodeId nodeId2 = nt.getNodeIdForNode(n);
    assertEquals(nodeId, nodeId2);
}
Also used : Node(org.apache.jena.graph.Node) NodeId(org.apache.jena.tdb.store.NodeId)

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