Search in sources :

Example 26 with NodeTable

use of org.apache.jena.tdb.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 = TupleLib.convertToQuads(nodeTable, iterMatches) ;
    Iterator<Quad> qIter = Iter.map(iterMatches, asQuad);
    return qIter;
}
Also used : Quad(org.apache.jena.sparql.core.Quad) NodeId(org.apache.jena.tdb.store.NodeId) NodeTable(org.apache.jena.tdb.store.nodetable.NodeTable) Tuple(org.apache.jena.atlas.lib.tuple.Tuple)

Example 27 with NodeTable

use of org.apache.jena.tdb.store.nodetable.NodeTable 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.getStoragePrefixes();
        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)

Aggregations

NodeTable (org.apache.jena.tdb.store.nodetable.NodeTable)27 NodeId (org.apache.jena.tdb.store.NodeId)12 Node (org.apache.jena.graph.Node)8 Tuple (org.apache.jena.atlas.lib.tuple.Tuple)5 NodeTupleTable (org.apache.jena.tdb.store.nodetupletable.NodeTupleTable)5 Triple (org.apache.jena.graph.Triple)4 Quad (org.apache.jena.sparql.core.Quad)4 Binding (org.apache.jena.sparql.engine.binding.Binding)4 Predicate (java.util.function.Predicate)3 BaseTest (org.apache.jena.atlas.junit.BaseTest)3 TDBException (org.apache.jena.tdb.TDBException)3 DatasetGraphTDB (org.apache.jena.tdb.store.DatasetGraphTDB)3 NodeTableTrans (org.apache.jena.tdb.transaction.NodeTableTrans)3 Transaction (org.apache.jena.tdb.transaction.Transaction)3 Test (org.junit.Test)3 Iterator (java.util.Iterator)2 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