You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jena.apache.org by an...@apache.org on 2013/04/22 14:05:09 UTC
svn commit: r1470467 - in /jena/trunk/jena-tdb/src/main/java:
com/hp/hpl/jena/tdb/solver/SolverLib.java
com/hp/hpl/jena/tdb/solver/StageMatchTuple.java tdb/tdbstats.java
Author: andy
Date: Mon Apr 22 12:05:08 2013
New Revision: 1470467
URL: http://svn.apache.org/r1470467
Log:
JENA-443
tdbstats needs to handle the union graph case specially
Modified:
jena/trunk/jena-tdb/src/main/java/com/hp/hpl/jena/tdb/solver/SolverLib.java
jena/trunk/jena-tdb/src/main/java/com/hp/hpl/jena/tdb/solver/StageMatchTuple.java
jena/trunk/jena-tdb/src/main/java/tdb/tdbstats.java
Modified: jena/trunk/jena-tdb/src/main/java/com/hp/hpl/jena/tdb/solver/SolverLib.java
URL: http://svn.apache.org/viewvc/jena/trunk/jena-tdb/src/main/java/com/hp/hpl/jena/tdb/solver/SolverLib.java?rev=1470467&r1=1470466&r2=1470467&view=diff
==============================================================================
--- jena/trunk/jena-tdb/src/main/java/com/hp/hpl/jena/tdb/solver/SolverLib.java (original)
+++ jena/trunk/jena-tdb/src/main/java/com/hp/hpl/jena/tdb/solver/SolverLib.java Mon Apr 22 12:05:08 2013
@@ -22,10 +22,7 @@ import static com.hp.hpl.jena.tdb.lib.Li
import java.util.* ;
-import org.apache.jena.atlas.iterator.Filter ;
-import org.apache.jena.atlas.iterator.Iter ;
-import org.apache.jena.atlas.iterator.IteratorWrapper ;
-import org.apache.jena.atlas.iterator.Transform ;
+import org.apache.jena.atlas.iterator.* ;
import org.apache.jena.atlas.lib.Tuple ;
import org.slf4j.Logger ;
import org.slf4j.LoggerFactory ;
@@ -328,6 +325,27 @@ public class SolverLib
graphIds.add(nt.getNodeIdForNode(n)) ;
return graphIds ;
}
+
+ public static Iterator<Tuple<NodeId>> unionGraph(NodeTupleTable ntt)
+ {
+ Iterator<Tuple<NodeId>> iter = ntt.find((NodeId)null, null, null, null) ;
+ iter = Iter.operate(iter, quadsToAnyTriples) ;
+ //iterMatches = Iter.distinct(iterMatches) ;
+
+ // This depends on the way indexes are choose and
+ // the indexing pattern. It assumes that the index
+ // chosen ends in G so same triples are adjacent
+ // in a union query.
+ /// See TupleTable.scanAllIndex that ensures this.
+ iter = Iter.distinctAdjacent(iter) ;
+ return iter ;
+ }
+ // -- Mutating "transform in place"
+ private static Action<Tuple<NodeId>> quadsToAnyTriples = new Action<Tuple<NodeId>>(){
+ @Override
+ public void apply(Tuple<NodeId> item)
+ { item.tuple()[0] = NodeId.NodeIdAny ; }
+ } ;
}
Modified: jena/trunk/jena-tdb/src/main/java/com/hp/hpl/jena/tdb/solver/StageMatchTuple.java
URL: http://svn.apache.org/viewvc/jena/trunk/jena-tdb/src/main/java/com/hp/hpl/jena/tdb/solver/StageMatchTuple.java?rev=1470467&r1=1470466&r2=1470467&view=diff
==============================================================================
--- jena/trunk/jena-tdb/src/main/java/com/hp/hpl/jena/tdb/solver/StageMatchTuple.java (original)
+++ jena/trunk/jena-tdb/src/main/java/com/hp/hpl/jena/tdb/solver/StageMatchTuple.java Mon Apr 22 12:05:08 2013
@@ -56,7 +56,7 @@ public class StageMatchTuple extends Rep
this.anyGraphs = anyGraphs ;
}
- /** Prepare a pattern (tuple of nodes), and an existing binding of NodeId, into NodesIds and Variables.
+ /** Prepare a pattern (tuple of nodes), and an existing binding of NodeId, into NodeIds and Variables.
* A variable in the pattern is replaced by its binding or null in the Nodeids.
* A variable that is not bound by the binding is placed in the var array.
*/
@@ -88,7 +88,7 @@ public class StageMatchTuple extends Rep
prepare(nodeTupleTable.getNodeTable(), patternTuple, input, ids, var) ;
- Iterator<Tuple<NodeId>> iterMatches = nodeTupleTable.find(Tuple.create(ids)) ;
+ Iterator<Tuple<NodeId>> iterMatches = nodeTupleTable.find(Tuple.create(ids)) ;
// ** Allow a triple or quad filter here.
if ( filter != null )
@@ -102,7 +102,7 @@ public class StageMatchTuple extends Rep
// Assumes that tuples are not shared.
if ( anyGraphs )
{
- iterMatches = Iter.operate(iterMatches, quadsToTriples) ;
+ iterMatches = Iter.operate(iterMatches, quadsToAnyTriples) ;
// If any slots were set, then the index would be ???G and we can use distinctAdjacent.
// If all slots are unset, the index is probably GSPO (SPOG would be better in this one case).
// This is a safe, if potentially costly, choice.
@@ -135,7 +135,7 @@ public class StageMatchTuple extends Rep
if ( v == null )
continue ;
NodeId id = tuple.get(i) ;
- if ( reject(output, v,id) )
+ if ( reject(output, v, id) )
return null ;
output.put(v, id) ;
}
@@ -146,13 +146,7 @@ public class StageMatchTuple extends Rep
return Iter.iter(iterMatches).map(binder).removeNulls() ;
}
- // -- Mutating "transform in place"
- private static Action<Tuple<NodeId>> quadsToTriples = new Action<Tuple<NodeId>>(){
- @Override
- public void apply(Tuple<NodeId> item)
- { item.tuple()[0] = NodeId.NodeIdAny ; }
- } ;
-
+
// -- Copying
private static Transform<Tuple<NodeId>,Tuple<NodeId>> projectToTriples = new Transform<Tuple<NodeId>,Tuple<NodeId>>(){
@Override
@@ -212,4 +206,11 @@ public class StageMatchTuple extends Rep
// May return NodeId.NodeDoesNotExist which must not be null.
return nodeTable.getNodeIdForNode(node) ;
}
+
+ // -- Mutating "transform in place"
+ private static Action<Tuple<NodeId>> quadsToAnyTriples = new Action<Tuple<NodeId>>(){
+ @Override
+ public void apply(Tuple<NodeId> item)
+ { item.tuple()[0] = NodeId.NodeIdAny ; }
+ } ;
}
Modified: jena/trunk/jena-tdb/src/main/java/tdb/tdbstats.java
URL: http://svn.apache.org/viewvc/jena/trunk/jena-tdb/src/main/java/tdb/tdbstats.java?rev=1470467&r1=1470466&r2=1470467&view=diff
==============================================================================
--- jena/trunk/jena-tdb/src/main/java/tdb/tdbstats.java (original)
+++ jena/trunk/jena-tdb/src/main/java/tdb/tdbstats.java Mon Apr 22 12:05:08 2013
@@ -21,11 +21,15 @@ package tdb;
import java.util.Iterator ;
import org.apache.jena.atlas.lib.Tuple ;
+import org.apache.jena.atlas.logging.Log ;
import tdb.cmdline.CmdTDB ;
import tdb.cmdline.CmdTDBGraph ;
import com.hp.hpl.jena.graph.Node ;
+import com.hp.hpl.jena.sparql.core.Quad ;
import com.hp.hpl.jena.tdb.nodetable.NodeTable ;
+import com.hp.hpl.jena.tdb.nodetable.NodeTupleTable ;
+import com.hp.hpl.jena.tdb.solver.SolverLib ;
import com.hp.hpl.jena.tdb.solver.stats.Stats ;
import com.hp.hpl.jena.tdb.solver.stats.StatsCollectorNodeId ;
import com.hp.hpl.jena.tdb.solver.stats.StatsResults ;
@@ -65,14 +69,21 @@ public class tdbstats extends CmdTDBGrap
Tuple<NodeId> t = iter.next() ;
stats.record(null, t.get(0), t.get(1), t.get(2)) ;
}
- }
- else
- {
- NodeId gnid = nt.getNodeIdForNode(gn) ;
- if ( gnid == null )
- {}
- Iterator<Tuple<NodeId>> iter = dsg.getQuadTable().getNodeTupleTable().find(gnid, null, null, null) ;
-
+ } 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
+ ? SolverLib.unionGraph(ntt)
+ : ntt.find(gnid, null, null, null) ;
for ( ; iter.hasNext(); )
{
Tuple<NodeId> t = iter.next() ;