Search in sources :

Example 6 with NodeTupleTable

use of org.apache.jena.tdb2.store.nodetupletable.NodeTupleTable in project jena by apache.

the class SolverLibTDB method testForGraphName.

/**
 * Find whether a specific graph name is in the quads table.
 */
static QueryIterator testForGraphName(DatasetGraphTDB ds, Node graphNode, QueryIterator input, Predicate<Tuple<NodeId>> filter, ExecutionContext execCxt) {
    NodeId nid = TDBInternal.getNodeId(ds, graphNode);
    boolean exists = !NodeId.isDoesNotExist(nid);
    if (exists) {
        // Node exists but is it used in the quad position?
        NodeTupleTable ntt = ds.getQuadTable().getNodeTupleTable();
        // Don't worry about abortable - this iterator should be fast
        // (with normal indexing - at least one G???).
        // Either it finds a starting point, or it doesn't.  We are only
        // interested in the first .hasNext.
        Iterator<Tuple<NodeId>> iter1 = ntt.find(nid, NodeId.NodeIdAny, NodeId.NodeIdAny, NodeId.NodeIdAny);
        if (filter != null)
            iter1 = Iter.filter(iter1, filter);
        exists = iter1.hasNext();
    }
    if (exists)
        return input;
    else {
        input.close();
        return QueryIterNullIterator.create(execCxt);
    }
}
Also used : NodeTupleTable(org.apache.jena.tdb2.store.nodetupletable.NodeTupleTable) NodeId(org.apache.jena.tdb2.store.NodeId) Tuple(org.apache.jena.atlas.lib.tuple.Tuple)

Example 7 with NodeTupleTable

use of org.apache.jena.tdb2.store.nodetupletable.NodeTupleTable in project jena by apache.

the class TDB2StorageBuilder method buildPrefixTable.

private StoragePrefixesTDB buildPrefixTable(NodeTable prefixNodes) {
    String primary = params.getPrimaryIndexPrefix();
    String[] indexes = params.getPrefixIndexes();
    TupleIndex[] prefixIndexes = makeTupleIndexes(primary, indexes);
    if (prefixIndexes.length != 1)
        error(log, "Wrong number of triple table tuples indexes: " + prefixIndexes.length);
    // No cache - the prefix mapping is a cache
    // NodeTable prefixNodes = makeNodeTable(location, pnNode2Id, pnId2Node, -1, -1, -1);
    NodeTupleTable prefixTable = new NodeTupleTableConcrete(primary.length(), prefixIndexes, prefixNodes);
    StoragePrefixesTDB x = new StoragePrefixesTDB(txnSystem, prefixTable);
    // DatasetPrefixesTDB prefixes = new DatasetPrefixesTDB(prefixTable);
    log.debug("Prefixes: " + primary + " :: " + String.join(",", indexes));
    return x;
}
Also used : NodeTupleTable(org.apache.jena.tdb2.store.nodetupletable.NodeTupleTable) NodeTupleTableConcrete(org.apache.jena.tdb2.store.nodetupletable.NodeTupleTableConcrete) TupleIndex(org.apache.jena.tdb2.store.tupletable.TupleIndex)

Example 8 with NodeTupleTable

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

Example 9 with NodeTupleTable

use of org.apache.jena.tdb2.store.nodetupletable.NodeTupleTable in project jena by apache.

the class DatasetGraphTDB method listGraphNodes.

@Override
public Iterator<Node> listGraphNodes() {
    checkNotClosed();
    NodeTupleTable quads = getQuadTable().getNodeTupleTable();
    Iterator<Tuple<NodeId>> x = quads.findAll();
    // XXX Future: Ensure we scan a G??? index and use distinctAdjacent.
    // See TupleTable.chooseScanAllIndex
    Iterator<NodeId> z = Iter.iter(x).map(t -> t.get(0)).distinct();
    Iterator<Node> r = NodeLib.nodes(quads.getNodeTable(), z);
    return r;
}
Also used : DatasetGraphStorage(org.apache.jena.dboe.storage.system.DatasetGraphStorage) Iterator(java.util.Iterator) ReorderTransformation(org.apache.jena.sparql.engine.optimizer.reorder.ReorderTransformation) StoragePrefixes(org.apache.jena.dboe.storage.StoragePrefixes) TDBException(org.apache.jena.tdb2.TDBException) NodeTupleTable(org.apache.jena.tdb2.store.nodetupletable.NodeTupleTable) Graph(org.apache.jena.graph.Graph) StoreParams(org.apache.jena.tdb2.params.StoreParams) Location(org.apache.jena.dboe.base.file.Location) Node(org.apache.jena.graph.Node) Quad(org.apache.jena.sparql.core.Quad) NodeLib(org.apache.jena.tdb2.lib.NodeLib) Iter(org.apache.jena.atlas.iterator.Iter) Tuple(org.apache.jena.atlas.lib.tuple.Tuple) TransactionalSystem(org.apache.jena.dboe.transaction.txn.TransactionalSystem) NodeTupleTable(org.apache.jena.tdb2.store.nodetupletable.NodeTupleTable) Node(org.apache.jena.graph.Node) Tuple(org.apache.jena.atlas.lib.tuple.Tuple)

Example 10 with NodeTupleTable

use of org.apache.jena.tdb2.store.nodetupletable.NodeTupleTable in project jena by apache.

the class DataToTuplesInline method startBulk.

@Override
public void startBulk() {
    coordinator = CoLib.newCoordinator();
    CoLib.add(coordinator, nodeTable);
    // Prefixes
    NodeTupleTable p = prefixes.getNodeTupleTable();
    CoLib.add(coordinator, p.getNodeTable());
    CoLib.add(coordinator, p.getTupleTable().getIndexes());
    CoLib.start(coordinator);
    transaction = coordinator.begin(TxnType.WRITE);
}
Also used : NodeTupleTable(org.apache.jena.tdb2.store.nodetupletable.NodeTupleTable)

Aggregations

NodeTupleTable (org.apache.jena.tdb2.store.nodetupletable.NodeTupleTable)8 Tuple (org.apache.jena.atlas.lib.tuple.Tuple)6 NodeId (org.apache.jena.tdb2.store.NodeId)5 NodeTable (org.apache.jena.tdb2.store.nodetable.NodeTable)5 Node (org.apache.jena.graph.Node)4 Quad (org.apache.jena.sparql.core.Quad)4 Iterator (java.util.Iterator)3 Iter (org.apache.jena.atlas.iterator.Iter)3 Triple (org.apache.jena.graph.Triple)3 Binding (org.apache.jena.sparql.engine.binding.Binding)3 Function (java.util.function.Function)2 Predicate (java.util.function.Predicate)2 InternalErrorException (org.apache.jena.atlas.lib.InternalErrorException)2 TupleFactory (org.apache.jena.atlas.lib.tuple.TupleFactory)2 Substitute (org.apache.jena.sparql.core.Substitute)2 ExecutionContext (org.apache.jena.sparql.engine.ExecutionContext)2 BindingFactory (org.apache.jena.sparql.engine.binding.BindingFactory)2 SolverLib.nodeTopLevel (org.apache.jena.sparql.engine.main.solver.SolverLib.nodeTopLevel)2 SolverLib.tripleHasEmbTripleWithVars (org.apache.jena.sparql.engine.main.solver.SolverLib.tripleHasEmbTripleWithVars)2 SolverRX4 (org.apache.jena.sparql.engine.main.solver.SolverRX4)2