Github user afs commented on a diff in the pull request:

    https://github.com/apache/jena/pull/396#discussion_r181468935
  
    --- Diff: 
jena-db/jena-tdb2/src/main/java/org/apache/jena/tdb2/solver/stats/StatsCollectorNodeId.java
 ---
    @@ -18,39 +18,39 @@
     
     package org.apache.jena.tdb2.solver.stats;
     
    -import java.util.HashMap ;
    -import java.util.Map ;
    +import java.util.HashMap;
    +import java.util.Map;
     
    -import org.apache.jena.graph.Node ;
    -import org.apache.jena.sparql.graph.NodeConst ;
    +import org.apache.jena.graph.Node;
    +import org.apache.jena.sparql.graph.NodeConst;
     import org.apache.jena.tdb2.store.NodeId;
     import org.apache.jena.tdb2.store.nodetable.NodeTable;
     
     /** Statistics collector, aggregates based on NodeId */
    -public class StatsCollectorNodeId extends StatsCollectorBase<NodeId>
    -{
    -    private NodeTable nodeTable ;
    -    
    -    public StatsCollectorNodeId(NodeTable nodeTable)
    -    {
    -        super(findRDFType(nodeTable)) ;
    -        this.nodeTable = nodeTable ;
    +public class StatsCollectorNodeId extends StatsCollectorBase<NodeId> {
    +    private NodeTable nodeTable;
    +
    +    public StatsCollectorNodeId(NodeTable nodeTable) {
    +        super(findRDFType(nodeTable));
    +        this.nodeTable = nodeTable;
         }
    -    
    -    private static NodeId findRDFType(NodeTable nodeTable2)
    -    {
    -        return nodeTable2.getAllocateNodeId(NodeConst.nodeRDFType) ;
    +
    +    private static NodeId findRDFType(NodeTable nodeTable) {
    +        // It may not exist.
    +        NodeId nodeId = nodeTable.getNodeIdForNode(NodeConst.nodeRDFType);
    +        if ( NodeId.isDoesNotExist(nodeId) )
    --- End diff --
    
    Yes, that's right.  The stats engine gathers details for `rdf:type` 
specially so it needs to know the trigger for that. `StatsCollectorBase` is a 
generic and works on an index scan, no touching the node table for every tuple 
of a triple/quad. Here, it's a `NodeId`. if it isn't in the node table, it is 
not in the data.
    
    As it was, it tried to update the node table to add the `rdf:type`, but it 
is in a read transaction so `NodeTable.getAllocateNodeId` fails.



---

Reply via email to