Search in sources :

Example 71 with Tuple

use of org.apache.jena.atlas.lib.tuple.Tuple in project jena by apache.

the class TestStats method statsForDftGraph.

private StatsResults statsForDftGraph() {
    // StatsCollectorNodeId writes nodes for rdf:type (this is not good).
    return Txn.calculateWrite(dsg, () -> {
        Iterator<Tuple<NodeId>> iter = triples.findAll();
        StatsCollectorNodeId stats = new StatsCollectorNodeId(nt);
        for (; iter.hasNext(); ) {
            Tuple<NodeId> t = iter.next();
            stats.record(null, t.get(0), t.get(1), t.get(2));
        }
        return stats.results();
    });
}
Also used : NodeId(org.apache.jena.tdb2.store.NodeId) StatsCollectorNodeId(org.apache.jena.tdb2.solver.stats.StatsCollectorNodeId) Tuple(org.apache.jena.atlas.lib.tuple.Tuple) StatsCollectorNodeId(org.apache.jena.tdb2.solver.stats.StatsCollectorNodeId)

Example 72 with Tuple

use of org.apache.jena.atlas.lib.tuple.Tuple in project jena by apache.

the class TestStats method statsForGraph.

private StatsResults statsForGraph(NodeId gid) {
    // StatsCollectorNodeId writes nodes for rdf:type (this is not good).
    return Txn.calculateWrite(dsg, () -> {
        Iterator<Tuple<NodeId>> iter = quads.find(gid, null, null, null);
        StatsCollectorNodeId stats = new StatsCollectorNodeId(nt);
        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 : NodeId(org.apache.jena.tdb2.store.NodeId) StatsCollectorNodeId(org.apache.jena.tdb2.solver.stats.StatsCollectorNodeId) Tuple(org.apache.jena.atlas.lib.tuple.Tuple) StatsCollectorNodeId(org.apache.jena.tdb2.solver.stats.StatsCollectorNodeId)

Example 73 with Tuple

use of org.apache.jena.atlas.lib.tuple.Tuple 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 if (Objects.equals(indexName, Names.indexNode2Id)) {
            primary = Names.indexNode2Id;
        } else {
            cmdError("Wrong length: " + indexName);
            primary = null;
        }
        // prefix2id
        // prefixIdx : GPU
        int keySubLen = SystemTDB.SizeOfNodeId;
        int keyUnitLen = indexName.length();
        int keyLength = keySubLen * keyUnitLen;
        int valueLength = 0;
        // Node table indexes.
        if (Objects.equals(indexName, Names.indexNode2Id) || Objects.equals(indexName, Names.prefixNode2Id)) {
            keySubLen = SystemTDB.LenNodeHash;
            keyUnitLen = 1;
            keyLength = SystemTDB.LenNodeHash;
            valueLength = SystemTDB.SizeOfNodeId;
        }
        // Prefixes
        if (Objects.equals(indexName, Names.indexPrefix)) {
            primary = Names.primaryIndexPrefix;
        }
        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 74 with Tuple

use of org.apache.jena.atlas.lib.tuple.Tuple 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 75 with Tuple

use of org.apache.jena.atlas.lib.tuple.Tuple in project jena by apache.

the class ExQuadFilter method createFilter.

/**
 * Create a filter to exclude the graph http://example/g2
 */
private static Predicate<Tuple<NodeId>> createFilter(Dataset ds) {
    // Filtering operates at a very low level:
    // Need to know the internal identifier for the graph name.
    final NodeId target = TDBInternal.getNodeId(ds, NodeFactory.createURI(graphToHide));
    System.out.println("Hide graph: " + graphToHide + " --> " + target);
    // Filter for accept/reject as quad as being visible.
    // Return true for "accept", false for "reject"
    Predicate<Tuple<NodeId>> filter = item -> {
        // System.err.println(item) ;
        if (item.len() == 4 && item.get(0).equals(target)) {
            // System.out.println("Reject: "+item) ;
            return false;
        }
        // System.out.println("Accept: "+item) ;
        return true;
    };
    return filter;
}
Also used : SystemTDB(org.apache.jena.tdb.sys.SystemTDB) NodeId(org.apache.jena.tdb.store.NodeId) TDBInternal(org.apache.jena.tdb.sys.TDBInternal) SSE(org.apache.jena.sparql.sse.SSE) NodeFactory(org.apache.jena.graph.NodeFactory) org.apache.jena.query(org.apache.jena.query) DatasetGraph(org.apache.jena.sparql.core.DatasetGraph) Quad(org.apache.jena.sparql.core.Quad) Predicate(java.util.function.Predicate) 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) Tuple(org.apache.jena.atlas.lib.tuple.Tuple)

Aggregations

Tuple (org.apache.jena.atlas.lib.tuple.Tuple)75 NodeId (org.apache.jena.tdb.store.NodeId)35 Node (org.apache.jena.graph.Node)22 TupleIndex (org.apache.jena.tdb.store.tupletable.TupleIndex)19 Test (org.junit.Test)19 BaseTest (org.apache.jena.atlas.junit.BaseTest)17 Quad (org.apache.jena.sparql.core.Quad)13 NodeId (org.apache.jena.tdb2.store.NodeId)10 Predicate (java.util.function.Predicate)8 Triple (org.apache.jena.graph.Triple)7 Iterator (java.util.Iterator)6 Binding (org.apache.jena.sparql.engine.binding.Binding)6 ArrayList (java.util.ArrayList)5 Iter (org.apache.jena.atlas.iterator.Iter)5 NodeTable (org.apache.jena.tdb.store.nodetable.NodeTable)5 NodeTupleTable (org.apache.jena.tdb.store.nodetupletable.NodeTupleTable)5 NodeTable (org.apache.jena.tdb2.store.nodetable.NodeTable)5 Function (java.util.function.Function)4 InternalErrorException (org.apache.jena.atlas.lib.InternalErrorException)4 TupleFactory (org.apache.jena.atlas.lib.tuple.TupleFactory)4