Search in sources :

Example 51 with NodeId

use of org.apache.jena.tdb2.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 dataset) {
    return Txn.calculateRead(dataset, () -> {
        DatasetGraphTDB dsg = TDBInternal.getDatasetGraphTDB(dataset);
        final NodeTable nodeTable = dsg.getQuadTable().getNodeTupleTable().getNodeTable();
        final NodeId target = nodeTable.getNodeIdForNode(NodeFactory.createURI(graphToHide));
        // Check g slot. Exclude graphToHide
        return item -> !(item.len() == 4 && item.get(0).equals(target));
    });
}
Also used : SystemTDB(org.apache.jena.tdb2.sys.SystemTDB) NodeFactory(org.apache.jena.graph.NodeFactory) org.apache.jena.query(org.apache.jena.query) DatasetGraph(org.apache.jena.sparql.core.DatasetGraph) Predicate(java.util.function.Predicate) TDBInternal(org.apache.jena.tdb2.sys.TDBInternal) TDB2Factory(org.apache.jena.tdb2.TDB2Factory) Test(org.junit.Test) TDB2(org.apache.jena.tdb2.TDB2) NodeTable(org.apache.jena.tdb2.store.nodetable.NodeTable) SSE(org.apache.jena.sparql.sse.SSE) Txn(org.apache.jena.system.Txn) Quad(org.apache.jena.sparql.core.Quad) Tuple(org.apache.jena.atlas.lib.tuple.Tuple) Assert.assertEquals(org.junit.Assert.assertEquals) NodeTable(org.apache.jena.tdb2.store.nodetable.NodeTable)

Example 52 with NodeId

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

the class TestNodeIdInline method testNoInline.

private void testNoInline(String x) {
    Node n = NodeFactoryExtra.parseNode(x);
    NodeId nodeId = NodeId.inline(n);
    assertNull("Converted NodeId but expected no inline form: " + x, nodeId);
}
Also used : Node(org.apache.jena.graph.Node) NodeId(org.apache.jena.tdb2.store.NodeId)

Example 53 with NodeId

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

the class ProcIngestDataX method getDatasetGraph.

private static DatasetGraph getDatasetGraph(String location) {
    Location loc = Location.create(location);
    // Ensure reset
    DatasetGraph dsg0 = DatabaseMgr.connectDatasetGraph(location);
    TDBInternal.expel(dsg0);
    StoreParams storeParams = StoreParams.getDftStoreParams();
    if (true) {
        storeParams = StoreParams.builder(storeParams).node2NodeIdCacheSize(10_000_000).build();
    }
    DatasetGraph dsg = DatabaseConnection.connectCreate(loc, storeParams).getDatasetGraph();
    StoreParams storeParamsActual = TDBInternal.getDatasetGraphTDB(dsg).getStoreParams();
    // FmtLog.info(LOG, "NodeId to Node cache size: %,d", storeParamsActual.getNodeId2NodeCacheSize());
    return dsg;
}
Also used : StoreParams(org.apache.jena.tdb2.params.StoreParams) Location(org.apache.jena.dboe.base.file.Location) DatasetGraph(org.apache.jena.sparql.core.DatasetGraph)

Example 54 with NodeId

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

the class NodeTableLib method printNodeTable.

/**
 * Print the main node table - development helper
 */
public static void printNodeTable(DatasetGraph dsg, long limit) {
    dsg.executeRead(() -> {
        DatasetGraphTDB dsgtdb = TDBInternal.getDatasetGraphTDB(dsg);
        NodeTable nodeTable = dsgtdb.getTripleTable().getNodeTupleTable().getNodeTable();
        int x = 0;
        for (var iter = nodeTable.all(); iter.hasNext(); ) {
            var pair = iter.next();
            x++;
            if (x > limit)
                return;
            NodeId nid = pair.getLeft();
            Node n = pair.getRight();
            System.out.printf("%s %s\n", nid, NodeFmtLib.strNT(n));
        }
        // long x = Iter.count(nodeTable.all());
        System.out.println("Node table length: " + x);
    });
}
Also used : Node(org.apache.jena.graph.Node) NodeId(org.apache.jena.tdb2.store.NodeId) NodeTable(org.apache.jena.tdb2.store.nodetable.NodeTable) DatasetGraphTDB(org.apache.jena.tdb2.store.DatasetGraphTDB)

Example 55 with NodeId

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

the class TupleIndexRecord method findWorker.

private Iterator<Tuple<NodeId>> findWorker(Tuple<NodeId> patternNaturalOrder, boolean partialScanAllowed, boolean fullScanAllowed) {
    if (Check) {
        if (tupleLength != patternNaturalOrder.len())
            throw new TDBException(String.format("Mismatch: tuple length %d / index for length %d", patternNaturalOrder.len(), tupleLength));
    }
    // Convert to index order.
    Tuple<NodeId> pattern = tupleMap.map(patternNaturalOrder);
    // Canonical form.
    int numSlots = 0;
    // Index of last leading pattern NodeId.  Start less than numSlots-1
    int leadingIdx = -2;
    boolean leading = true;
    // Records.
    Record minRec = factory.createKeyOnly();
    Record maxRec = factory.createKeyOnly();
    // Set the prefixes.
    for (int i = 0; i < pattern.len(); i++) {
        NodeId X = pattern.get(i);
        if (NodeId.isAny(X)) {
            X = null;
            // No longer seting leading key slots.
            leading = false;
            continue;
        }
        // if ( NodeId.isDoesNotExist(X) )
        // return Iter.nullIterator();
        numSlots++;
        if (leading) {
            leadingIdx = i;
            NodeIdFactory.set(X, minRec.getKey(), i * SizeOfNodeId);
            NodeIdFactory.set(X, maxRec.getKey(), i * SizeOfNodeId);
        }
    }
    // Is it a simple existence test?
    if (numSlots == pattern.len()) {
        if (index.contains(minRec))
            return new SingletonIterator<>(pattern);
        else
            return new NullIterator<>();
    }
    if (true) {
        Iterator<Tuple<NodeId>> tuples;
        if (leadingIdx < 0) {
            if (!fullScanAllowed)
                return null;
            // Full scan necessary
            tuples = index.iterator(null, null, recordMapper);
        } else {
            // Adjust the maxRec.
            NodeId X = pattern.get(leadingIdx);
            // Set the max Record to the leading NodeIds, +1.
            // Example, SP? inclusive to S(P+1)? exclusive where ? is zero.
            NodeIdFactory.setNext(X, maxRec.getKey(), leadingIdx * SizeOfNodeId);
            tuples = index.iterator(minRec, maxRec, recordMapper);
        }
        if (leadingIdx < numSlots - 1) {
            if (!partialScanAllowed)
                return null;
            // Didn't match all defined slots in request.
            // Partial or full scan needed.
            // pattern.unmap(colMap);
            tuples = scan(tuples, patternNaturalOrder);
        }
        return tuples;
    }
    Iterator<Record> iter = null;
    if (leadingIdx < 0) {
        if (!fullScanAllowed)
            return null;
        // Full scan necessary
        iter = index.iterator();
    } else {
        // Adjust the maxRec.
        NodeId X = pattern.get(leadingIdx);
        // Set the max Record to the leading NodeIds, +1.
        // Example, SP? inclusive to S(P+1)? exclusive where ? is zero.
        NodeIdFactory.setNext(X, maxRec.getKey(), leadingIdx * SizeOfNodeId);
        iter = index.iterator(minRec, maxRec);
    }
    Iterator<Tuple<NodeId>> tuples = Iter.map(iter, item -> TupleLib.tuple(item, tupleMap));
    if (leadingIdx < numSlots - 1) {
        if (!partialScanAllowed)
            return null;
        // Didn't match all defined slots in request.
        // Partial or full scan needed.
        // pattern.unmap(colMap);
        tuples = scan(tuples, patternNaturalOrder);
    }
    return tuples;
}
Also used : TDBException(org.apache.jena.tdb2.TDBException) SizeOfNodeId(org.apache.jena.tdb2.sys.SystemTDB.SizeOfNodeId) NodeId(org.apache.jena.tdb2.store.NodeId) Record(org.apache.jena.dboe.base.record.Record) 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