Search in sources :

Example 1 with DatasetGraphTDB

use of org.apache.jena.tdb2.store.DatasetGraphTDB in project jena by apache.

the class ModTDBDataset method createDataset.

@Override
public Dataset createDataset() {
    if (inMemFile != null) {
        Dataset ds = TDB2Factory.createDataset();
        RDFDataMgr.read(ds, inMemFile);
        return ds;
    }
    if (modAssembler.getAssemblerFile() != null) {
        Dataset thing = null;
        // (which may go wrong later if TDB2 directly is needed).
        try {
            thing = (Dataset) AssemblerUtils.build(modAssembler.getAssemblerFile(), VocabTDB2.tDatasetTDB);
            if (thing != null) {
                DatasetGraph dsg = thing.asDatasetGraph();
                if (!(dsg instanceof DatasetGraphSwitchable) && !(dsg instanceof DatasetGraphTDB))
                    Log.warn(this, "Unexpected: Not a TDB2 dataset for type DatasetTDB2");
            }
            if (thing == null)
                // Should use assembler inheritance but how do we assert
                // the subclass relationship in a program?
                thing = (Dataset) AssemblerUtils.build(modAssembler.getAssemblerFile(), DatasetAssemblerVocab.tDataset);
        } catch (JenaException ex) {
            throw ex;
        } catch (Exception ex) {
            throw new CmdException("Error creating", ex);
        }
        return thing;
    }
    if (modAssembler.getLocation() == null)
        throw new CmdException("No assembler file nor location provided");
    // No assembler - use location to find a database.
    Dataset ds = TDB2Factory.connectDataset(modAssembler.getLocation());
    return ds;
}
Also used : JenaException(org.apache.jena.shared.JenaException) CmdException(org.apache.jena.cmd.CmdException) ModDataset(arq.cmdline.ModDataset) DatasetGraphSwitchable(org.apache.jena.tdb2.store.DatasetGraphSwitchable) CmdException(org.apache.jena.cmd.CmdException) JenaException(org.apache.jena.shared.JenaException) DatasetGraph(org.apache.jena.sparql.core.DatasetGraph) DatasetGraphTDB(org.apache.jena.tdb2.store.DatasetGraphTDB)

Example 2 with DatasetGraphTDB

use of org.apache.jena.tdb2.store.DatasetGraphTDB in project jena by apache.

the class tdbstats method stats$.

private static StatsResults stats$(DatasetGraphTDB dsg, Node gn) {
    NodeTable nt = dsg.getTripleTable().getNodeTupleTable().getNodeTable();
    StatsCollectorNodeId stats = new StatsCollectorNodeId(nt);
    if (gn == null) {
        Iterator<Tuple<NodeId>> iter = dsg.getTripleTable().getNodeTupleTable().findAll();
        for (; iter.hasNext(); ) {
            Tuple<NodeId> t = iter.next();
            stats.record(null, t.get(0), t.get(1), t.get(2));
        }
    } else {
        // If the union graph, then we need to scan all quads but with uniqueness.
        boolean unionGraph = Quad.isUnionGraph(gn);
        NodeId gnid = null;
        if (!unionGraph) {
            gnid = nt.getNodeIdForNode(gn);
            if (NodeId.isDoesNotExist(gnid))
                Log.warn(tdbstats.class, "No such graph: " + gn);
        }
        NodeTupleTable ntt = dsg.getQuadTable().getNodeTupleTable();
        Iterator<Tuple<NodeId>> iter = unionGraph ? SolverLibTDB.unionGraph(ntt) : ntt.find(gnid, null, null, null);
        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 : NodeTupleTable(org.apache.jena.tdb2.store.nodetupletable.NodeTupleTable) NodeId(org.apache.jena.tdb2.store.NodeId) StatsCollectorNodeId(org.apache.jena.tdb2.solver.stats.StatsCollectorNodeId) NodeTable(org.apache.jena.tdb2.store.nodetable.NodeTable) Tuple(org.apache.jena.atlas.lib.tuple.Tuple) StatsCollectorNodeId(org.apache.jena.tdb2.solver.stats.StatsCollectorNodeId)

Example 3 with DatasetGraphTDB

use of org.apache.jena.tdb2.store.DatasetGraphTDB in project jena by apache.

the class SolverLibTDB method convertToNodeIds.

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.tdb2.store.NodeId) NodeTable(org.apache.jena.tdb2.store.nodetable.NodeTable)

Example 4 with DatasetGraphTDB

use of org.apache.jena.tdb2.store.DatasetGraphTDB in project jena by apache.

the class SolverLibTDB method graphNames.

/**
 * Find all the graph names in the quads table.
 */
static QueryIterator graphNames(DatasetGraphTDB ds, Node graphNode, QueryIterator input, Predicate<Tuple<NodeId>> filter, ExecutionContext execCxt) {
    List<Abortable> killList = new ArrayList<>();
    Iterator<Tuple<NodeId>> iter1 = ds.getQuadTable().getNodeTupleTable().find(NodeId.NodeIdAny, NodeId.NodeIdAny, NodeId.NodeIdAny, NodeId.NodeIdAny);
    if (filter != null)
        iter1 = Iter.filter(iter1, filter);
    Iterator<NodeId> iter2 = Iter.map(iter1, t -> t.get(0));
    // Project is cheap - don't brother wrapping iter1
    iter2 = makeAbortable(iter2, killList);
    Iterator<NodeId> iter3 = Iter.distinct(iter2);
    iter3 = makeAbortable(iter3, killList);
    Iterator<Node> iter4 = NodeLib.nodes(ds.getQuadTable().getNodeTupleTable().getNodeTable(), iter3);
    final Var var = Var.alloc(graphNode);
    Iterator<Binding> iterBinding = Iter.map(iter4, node -> BindingFactory.binding(var, node));
    return new QueryIterAbortable(iterBinding, killList, input, execCxt);
}
Also used : Binding(org.apache.jena.sparql.engine.binding.Binding) QueryIterAbortable(org.apache.jena.sparql.engine.iterator.QueryIterAbortable) Var(org.apache.jena.sparql.core.Var) Node(org.apache.jena.graph.Node) QueryIterAbortable(org.apache.jena.sparql.engine.iterator.QueryIterAbortable) SolverLib.makeAbortable(org.apache.jena.sparql.engine.main.solver.SolverLib.makeAbortable) Abortable(org.apache.jena.sparql.engine.iterator.Abortable) NodeId(org.apache.jena.tdb2.store.NodeId) Tuple(org.apache.jena.atlas.lib.tuple.Tuple)

Example 5 with DatasetGraphTDB

use of org.apache.jena.tdb2.store.DatasetGraphTDB 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)

Aggregations

DatasetGraphTDB (org.apache.jena.tdb2.store.DatasetGraphTDB)19 Location (org.apache.jena.dboe.base.file.Location)10 Node (org.apache.jena.graph.Node)8 DatasetGraph (org.apache.jena.sparql.core.DatasetGraph)8 DatasetGraphSwitchable (org.apache.jena.tdb2.store.DatasetGraphSwitchable)8 Test (org.junit.Test)8 NodeId (org.apache.jena.tdb2.store.NodeId)7 NodeTable (org.apache.jena.tdb2.store.nodetable.NodeTable)7 Tuple (org.apache.jena.atlas.lib.tuple.Tuple)6 StoreConnection (org.apache.jena.tdb2.sys.StoreConnection)4 ConfigTest (org.apache.jena.tdb2.ConfigTest)3 TDBException (org.apache.jena.tdb2.TDBException)3 BufferChannel (org.apache.jena.dboe.base.file.BufferChannel)2 FileSet (org.apache.jena.dboe.base.file.FileSet)2 Record (org.apache.jena.dboe.base.record.Record)2 RecordFactory (org.apache.jena.dboe.base.record.RecordFactory)2 BPlusTree (org.apache.jena.dboe.trans.bplustree.BPlusTree)2 Graph (org.apache.jena.graph.Graph)2 NodeTupleTable (org.apache.jena.tdb2.store.nodetupletable.NodeTupleTable)2 ModDataset (arq.cmdline.ModDataset)1