Search in sources :

Example 1 with NodeTable

use of org.apache.jena.tdb.store.nodetable.NodeTable in project jena by apache.

the class DatasetBuilderStd method makeNodeTable.

public NodeTable makeNodeTable(Location location, StoreParams params) {
    FileSet fsNodeToId = new FileSet(location, params.getIndexNode2Id());
    FileSet fsId2Node = new FileSet(location, params.getIndexId2Node());
    NodeTable nt = nodeTableBuilder.buildNodeTable(fsNodeToId, fsId2Node, params);
    return nt;
}
Also used : FileSet(org.apache.jena.tdb.base.file.FileSet) NodeTable(org.apache.jena.tdb.store.nodetable.NodeTable)

Example 2 with NodeTable

use of org.apache.jena.tdb.store.nodetable.NodeTable in project jena by apache.

the class SolverLib method execute.

// The worker.  Callers choose the NodeTupleTable.  
//     graphNode may be Node.ANY, meaning we should make triples unique.
//     graphNode may be null, meaning default graph
private static QueryIterator execute(NodeTupleTable nodeTupleTable, Node graphNode, BasicPattern pattern, QueryIterator input, Predicate<Tuple<NodeId>> filter, ExecutionContext execCxt) {
    if (Quad.isUnionGraph(graphNode))
        graphNode = Node.ANY;
    if (Quad.isDefaultGraph(graphNode))
        graphNode = null;
    List<Triple> triples = pattern.getList();
    boolean anyGraph = (graphNode == null ? false : (Node.ANY.equals(graphNode)));
    int tupleLen = nodeTupleTable.getTupleTable().getTupleLen();
    if (graphNode == null) {
        if (3 != tupleLen)
            throw new TDBException("SolverLib: Null graph node but tuples are of length " + tupleLen);
    } else {
        if (4 != tupleLen)
            throw new TDBException("SolverLib: Graph node specified but tuples are of length " + tupleLen);
    }
    // Convert from a QueryIterator (Bindings of Var/Node) to BindingNodeId
    NodeTable nodeTable = nodeTupleTable.getNodeTable();
    Iterator<BindingNodeId> chain = Iter.map(input, SolverLib.convFromBinding(nodeTable));
    List<Abortable> killList = new ArrayList<>();
    for (Triple triple : triples) {
        Tuple<Node> tuple = null;
        if (graphNode == null)
            // 3-tuples
            tuple = tuple(triple.getSubject(), triple.getPredicate(), triple.getObject());
        else
            // 4-tuples.
            tuple = tuple(graphNode, triple.getSubject(), triple.getPredicate(), triple.getObject());
        chain = solve(nodeTupleTable, tuple, anyGraph, chain, filter, execCxt);
        chain = makeAbortable(chain, killList);
    }
    // DEBUG POINT
    if (false) {
        if (chain.hasNext())
            chain = Iter.debug(chain);
        else
            System.out.println("No results");
    }
    // Timeout wrapper ****
    // QueryIterTDB gets called async.
    // Iter.abortable?
    // Or each iterator has a place to test.
    // or pass in a thing to test?
    // Need to make sure the bindings here point to parent.
    Iterator<Binding> iterBinding = convertToNodes(chain, nodeTable);
    // "killList" will be aborted on timeout.
    return new QueryIterTDB(iterBinding, killList, input, execCxt);
}
Also used : Binding(org.apache.jena.sparql.engine.binding.Binding) TDBException(org.apache.jena.tdb.TDBException) Node(org.apache.jena.graph.Node) Triple(org.apache.jena.graph.Triple) NodeTable(org.apache.jena.tdb.store.nodetable.NodeTable)

Example 3 with NodeTable

use of org.apache.jena.tdb.store.nodetable.NodeTable in project jena by apache.

the class SolverLib method convertToNodeIds.

public static Set<NodeId> convertToNodeIds(Collection<Node> nodes, DatasetGraphTDB dataset) {
    Set<NodeId> graphIds = new HashSet<>();
    NodeTable nt = dataset.getQuadTable().getNodeTupleTable().getNodeTable();
    for (Node n : nodes) graphIds.add(nt.getNodeIdForNode(n));
    return graphIds;
}
Also used : Node(org.apache.jena.graph.Node) NodeId(org.apache.jena.tdb.store.NodeId) NodeTable(org.apache.jena.tdb.store.nodetable.NodeTable)

Example 4 with NodeTable

use of org.apache.jena.tdb.store.nodetable.NodeTable in project jena by apache.

the class dumpnodetable method exec.

@Override
protected void exec() {
    List<String> tripleIndexes = Arrays.asList(Names.tripleIndexes);
    List<String> quadIndexes = Arrays.asList(Names.quadIndexes);
    Location loc = modLocation.getLocation();
    StoreConnection sConn = StoreConnection.make(loc);
    DatasetGraphTDB dsg = sConn.getBaseDataset();
    NodeTable nodeTable = dsg.getQuadTable().getNodeTupleTable().getNodeTable();
    dump(System.out, nodeTable);
}
Also used : StoreConnection(org.apache.jena.tdb.StoreConnection) NodeTable(org.apache.jena.tdb.store.nodetable.NodeTable) Location(org.apache.jena.tdb.base.file.Location) ModLocation(tdb.cmdline.ModLocation) DatasetGraphTDB(org.apache.jena.tdb.store.DatasetGraphTDB)

Example 5 with NodeTable

use of org.apache.jena.tdb.store.nodetable.NodeTable in project jena by apache.

the class AbstractTestNodeTable method testNode.

protected void testNode(Node n) {
    NodeTable nt = createEmptyNodeTable();
    writeNode(nt, n);
}
Also used : NodeTable(org.apache.jena.tdb.store.nodetable.NodeTable)

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