Search in sources :

Example 51 with Tuple

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

the class TestStats method statsForDftGraph.

private StatsResults statsForDftGraph() {
    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.tdb.store.NodeId) StatsCollectorNodeId(org.apache.jena.tdb.solver.stats.StatsCollectorNodeId) Tuple(org.apache.jena.atlas.lib.tuple.Tuple) StatsCollectorNodeId(org.apache.jena.tdb.solver.stats.StatsCollectorNodeId)

Example 52 with Tuple

use of org.apache.jena.atlas.lib.tuple.Tuple 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 = colMap.map(patternNaturalOrder);
    // Canonical form.
    int numSlots = 0;
    // Index of last leading pattern NodeId. Start less
    int leadingIdx = -2;
    // than numSlots-1
    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 setting leading key slots.
            leading = false;
            continue;
        }
        numSlots++;
        if (leading) {
            leadingIdx = i;
            Bytes.setLong(X.getId(), minRec.getKey(), i * SizeOfNodeId);
            Bytes.setLong(X.getId(), 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<>();
    }
    Iterator<Record> iter = null;
    if (leadingIdx < 0) {
        if (!fullScanAllowed)
            return null;
        // System.out.println("Full scan") ;
        // 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.
        Bytes.setLong(X.getId() + 1, maxRec.getKey(), leadingIdx * SizeOfNodeId);
        iter = index.iterator(minRec, maxRec);
    }
    Iterator<Tuple<NodeId>> tuples = Iter.map(iter, item -> TupleLib.tuple(item, colMap));
    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 = TupleIndex.scan(tuples, patternNaturalOrder);
    }
    return tuples;
}
Also used : TDBException(org.apache.jena.tdb.TDBException) SizeOfNodeId(org.apache.jena.tdb.sys.SystemTDB.SizeOfNodeId) NodeId(org.apache.jena.tdb.store.NodeId) Record(org.apache.jena.tdb.base.record.Record) Tuple(org.apache.jena.atlas.lib.tuple.Tuple)

Example 53 with Tuple

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

the class DebugTDB method dumpIndex.

public static void dumpIndex(TupleIndex idx) {
    Iterator<Tuple<NodeId>> iter = idx.all();
    while (iter.hasNext()) {
        Tuple<NodeId> tuple = iter.next();
        System.out.println(tuple);
    }
    if (false) {
        // Dump raw
        TupleIndexRecord tir = (TupleIndexRecord) idx;
        RangeIndex rIdx = tir.getRangeIndex();
        for (Record aRIdx : rIdx) {
            System.out.println(aRIdx);
        }
    }
}
Also used : TupleIndexRecord(org.apache.jena.tdb.store.tupletable.TupleIndexRecord) 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) Tuple(org.apache.jena.atlas.lib.tuple.Tuple)

Example 54 with Tuple

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

the class SolverRX method matchQuadPattern.

// Entry point from SolverLib.
/*package*/
static Iterator<BindingNodeId> matchQuadPattern(Iterator<BindingNodeId> chain, Node graphNode, Triple tPattern, NodeTupleTable nodeTupleTable, Tuple<Node> patternTuple, boolean anyGraph, Predicate<Tuple<NodeId>> filter, ExecutionContext execCxt) {
    if (DATAPATH) {
        if (!tripleHasEmbTripleWithVars(tPattern))
            // No RDF-star <<>> with variables.
            return StageMatchTuple.access(nodeTupleTable, chain, patternTuple, filter, anyGraph, execCxt);
    }
    // RDF-star <<>> with variables.
    // This path should work regardless.
    boolean isTriple = (patternTuple.len() == 3);
    NodeTable nodeTable = nodeTupleTable.getNodeTable();
    Function<BindingNodeId, Iterator<BindingNodeId>> step = bnid -> find(bnid, nodeTupleTable, graphNode, tPattern, anyGraph, filter, execCxt);
    return Iter.flatMap(chain, step);
}
Also used : Binding(org.apache.jena.sparql.engine.binding.Binding) Iterator(java.util.Iterator) Predicate(java.util.function.Predicate) TupleLib(org.apache.jena.tdb.lib.TupleLib) SolverLib.nodeTopLevel(org.apache.jena.sparql.engine.main.solver.SolverLib.nodeTopLevel) Triple(org.apache.jena.graph.Triple) SolverLibTDB.convFromBinding(org.apache.jena.tdb.solver.SolverLibTDB.convFromBinding) SolverLib.tripleHasEmbTripleWithVars(org.apache.jena.sparql.engine.main.solver.SolverLib.tripleHasEmbTripleWithVars) Function(java.util.function.Function) NodeTupleTable(org.apache.jena.tdb.store.nodetupletable.NodeTupleTable) NodeId(org.apache.jena.tdb.store.NodeId) SolverRX4(org.apache.jena.sparql.engine.main.solver.SolverRX4) NodeTable(org.apache.jena.tdb.store.nodetable.NodeTable) Substitute(org.apache.jena.sparql.core.Substitute) Node(org.apache.jena.graph.Node) Quad(org.apache.jena.sparql.core.Quad) TupleFactory(org.apache.jena.atlas.lib.tuple.TupleFactory) Iter(org.apache.jena.atlas.iterator.Iter) InternalErrorException(org.apache.jena.atlas.lib.InternalErrorException) Tuple(org.apache.jena.atlas.lib.tuple.Tuple) ExecutionContext(org.apache.jena.sparql.engine.ExecutionContext) BindingFactory(org.apache.jena.sparql.engine.binding.BindingFactory) Iterator(java.util.Iterator) NodeTable(org.apache.jena.tdb.store.nodetable.NodeTable)

Example 55 with Tuple

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

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