Search in sources :

Example 36 with NodeId

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

the class dumpbpt method exec.

@Override
protected void exec() {
    List<String> tripleIndexes = Arrays.asList(Names.tripleIndexes);
    List<String> quadIndexes = Arrays.asList(Names.quadIndexes);
    Location loc = modLocation.getLocation();
    // The name is the order.
    for (String indexName : super.getPositional()) {
        String primary;
        if (indexName.length() == 3) {
            primary = Names.primaryIndexTriples;
        } else if (indexName.length() == 4) {
            primary = Names.primaryIndexQuads;
        } else {
            cmdError("Wrong length: " + indexName);
            primary = null;
        }
        int keySubLen = SystemTDB.SizeOfNodeId;
        int keyUnitLen = indexName.length();
        int keyLength = keySubLen * keyUnitLen;
        int valueLength = 0;
        RecordFactory rf = new RecordFactory(keyLength, valueLength);
        RangeIndex rIndex = IndexFactory.buildRangeIndex(loc, indexName, rf);
        BPlusTree bpt = (BPlusTree) rIndex;
        if (false) {
            System.out.println("---- Index structure");
            bpt.dump();
        }
        if (true) {
            System.out.println("---- Index contents");
            Iterator<Record> iter = bpt.iterator();
            if (!iter.hasNext())
                System.out.println("<<Empty>>");
            for (; iter.hasNext(); ) {
                Record r = iter.next();
                printRecord("", System.out, r, keyUnitLen);
            }
        }
        // Check.
        Iterator<Record> iterCheck = bpt.iterator();
        Record r1 = null;
        int i = 0;
        for (; iterCheck.hasNext(); ) {
            Record r2 = iterCheck.next();
            i++;
            if (r1 != null) {
                if (!Record.keyLT(r1, r2)) {
                    System.err.println("key error@ " + i);
                    printRecord("  ", System.err, r1, keyUnitLen);
                    printRecord("  ", System.err, r2, keyUnitLen);
                }
            }
            r1 = r2;
        }
        if (false) {
            // Dump in tuple order.
            TupleIndex tupleIndex = new TupleIndexRecord(primary.length(), new ColumnMap(primary, indexName), indexName, rIndex.getRecordFactory(), rIndex);
            if (true) {
                System.out.println("---- Tuple contents");
                Iterator<Tuple<NodeId>> iter2 = tupleIndex.all();
                if (!iter2.hasNext())
                    System.out.println("<<Empty>>");
                for (; iter2.hasNext(); ) {
                    Tuple<NodeId> row = iter2.next();
                    System.out.println(row);
                }
            }
        }
    }
}
Also used : ColumnMap(org.apache.jena.tdb.lib.ColumnMap) TupleIndexRecord(org.apache.jena.tdb.store.tupletable.TupleIndexRecord) RecordFactory(org.apache.jena.tdb.base.record.RecordFactory) NodeId(org.apache.jena.tdb.store.NodeId) Record(org.apache.jena.tdb.base.record.Record) TupleIndexRecord(org.apache.jena.tdb.store.tupletable.TupleIndexRecord) RangeIndex(org.apache.jena.tdb.index.RangeIndex) TupleIndex(org.apache.jena.tdb.store.tupletable.TupleIndex) BPlusTree(org.apache.jena.tdb.index.bplustree.BPlusTree) Tuple(org.apache.jena.atlas.lib.tuple.Tuple) Location(org.apache.jena.tdb.base.file.Location) ModLocation(tdb.cmdline.ModLocation)

Example 37 with NodeId

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

the class dumpnodetable method dump.

public static void dump(OutputStream w, NodeTable nodeTable) {
    // Better to hack the indexes?
    Iterator<Pair<NodeId, Node>> iter = nodeTable.all();
    long count = 0;
    try (IndentedWriter iw = new IndentedWriter(w)) {
        for (; iter.hasNext(); ) {
            Pair<NodeId, Node> pair = iter.next();
            iw.print(pair.car().toString());
            iw.print(" : ");
            // iw.print(pair.cdr()) ;
            Node n = pair.cdr();
            String $ = stringForNode(n);
            iw.print($);
            iw.println();
            count++;
        }
        iw.println();
        iw.printf("Total: " + count);
        iw.println();
        iw.flush();
    }
}
Also used : IndentedWriter(org.apache.jena.atlas.io.IndentedWriter) Node(org.apache.jena.graph.Node) NodeId(org.apache.jena.tdb.store.NodeId) Pair(org.apache.jena.atlas.lib.Pair)

Example 38 with NodeId

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

the class tdbgenindex method main.

public static void main(String... argv) {
    // Usage: srcLocation indexName dstLocation indexName
    if (argv.length != 4) {
        System.err.println("Usage: " + Lib.classShortName(tdbgenindex.class) + " srcLocation srcIndex dstLocation dstIndex");
        System.exit(1);
    }
    Location srcLoc = Location.create(argv[0]);
    String srcIndexName = argv[1];
    Location dstLoc = Location.create(argv[2]);
    String dstIndexName = argv[3];
    int readCacheSize = 0;
    int writeCacheSize = -1;
    if (srcIndexName.length() != dstIndexName.length()) {
        System.err.println("srcIndexName.length() != dstIndexName.length() " + srcIndexName + " :: " + dstIndexName);
        System.exit(1);
    }
    String primary;
    int dftKeyLength;
    int dftValueLength;
    if (srcIndexName.length() == 3) {
        primary = Names.primaryIndexTriples;
        dftKeyLength = SystemTDB.LenIndexTripleRecord;
        dftValueLength = 0;
    } else if (srcIndexName.length() == 4) {
        primary = Names.primaryIndexQuads;
        dftKeyLength = SystemTDB.LenIndexQuadRecord;
        dftValueLength = 0;
    } else {
        System.err.println("indexlength != 3 or 4");
        System.exit(1);
        primary = null;
        dftKeyLength = 0;
        dftValueLength = 0;
    }
    TupleIndex srcIdx = SetupTDB.makeTupleIndex(srcLoc, primary, srcIndexName, srcIndexName, dftKeyLength);
    TupleIndex dstIdx = SetupTDB.makeTupleIndex(dstLoc, primary, dstIndexName, dstIndexName, dftKeyLength);
    Iterator<Tuple<NodeId>> iter = srcIdx.all();
    for (; iter.hasNext(); ) {
        Tuple<NodeId> tuple = iter.next();
        dstIdx.add(tuple);
    }
    srcIdx.close();
    dstIdx.close();
}
Also used : NodeId(org.apache.jena.tdb.store.NodeId) TupleIndex(org.apache.jena.tdb.store.tupletable.TupleIndex) Tuple(org.apache.jena.atlas.lib.tuple.Tuple) Location(org.apache.jena.tdb.base.file.Location)

Example 39 with NodeId

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

the class SolverLib method convert.

/** Binding ==> BindingNodeId, given a NodeTable */
public static BindingNodeId convert(Binding binding, NodeTable nodeTable) {
    if (binding instanceof BindingTDB)
        return ((BindingTDB) binding).getBindingId();
    BindingNodeId b = new BindingNodeId(binding);
    // and copy over, getting NodeIds.
    Iterator<Var> vars = binding.vars();
    for (; vars.hasNext(); ) {
        Var v = vars.next();
        Node n = binding.get(v);
        if (n == null)
            // Can occur with BindingProject
            continue;
        // Rely on the node table cache for efficency - we will likely be
        // repeatedly looking up the same node in different bindings.
        NodeId id = nodeTable.getNodeIdForNode(n);
        // Even put in "does not exist" for a node now known not to be in the DB.
        b.put(v, id);
    }
    return b;
}
Also used : Var(org.apache.jena.sparql.core.Var) Node(org.apache.jena.graph.Node) NodeId(org.apache.jena.tdb.store.NodeId)

Example 40 with NodeId

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

the class StageMatchTuple method prepare.

/** Prepare a pattern (tuple of nodes), and an existing binding of NodeId, into NodeIds and Variables. 
     *  A variable in the pattern is replaced by its binding or null in the Nodeids.
     *  A variable that is not bound by the binding is placed in the var array.
     *  Return false if preparation detechs the pattern can not match. 
     */
public static boolean prepare(NodeTable nodeTable, Tuple<Node> patternTuple, BindingNodeId input, NodeId[] ids, Var[] var) {
    // we wish to abort if an unknown node is seen.
    for (int i = 0; i < patternTuple.len(); i++) {
        Node n = patternTuple.get(i);
        // Substitution and turning into NodeIds
        // Variables unsubstituted are null NodeIds
        NodeId nId = idFor(nodeTable, input, n);
        if (NodeId.isDoesNotExist(nId))
            return false;
        ids[i] = nId;
        if (nId == null)
            var[i] = asVar(n);
    }
    return true;
}
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