jena-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a...@apache.org
Subject svn commit: r1506692 - in /jena/trunk/jena-tdb/src: main/java/com/hp/hpl/jena/tdb/solver/ main/java/com/hp/hpl/jena/tdb/sys/ test/java/com/hp/hpl/jena/tdb/store/
Date Wed, 24 Jul 2013 20:18:42 GMT
Author: andy
Date: Wed Jul 24 20:18:42 2013
New Revision: 1506692

URL: http://svn.apache.org/r1506692
Log:
JENA-492
Carry out different tests for whether "GRAPH ?g" or "GRAPH <uri>"

Modified:
    jena/trunk/jena-tdb/src/main/java/com/hp/hpl/jena/tdb/solver/OpExecutorTDB.java
    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/sys/TDBInternal.java
    jena/trunk/jena-tdb/src/test/java/com/hp/hpl/jena/tdb/store/Test_SPARQL_TDB.java

Modified: jena/trunk/jena-tdb/src/main/java/com/hp/hpl/jena/tdb/solver/OpExecutorTDB.java
URL: http://svn.apache.org/viewvc/jena/trunk/jena-tdb/src/main/java/com/hp/hpl/jena/tdb/solver/OpExecutorTDB.java?rev=1506692&r1=1506691&r2=1506692&view=diff
==============================================================================
--- jena/trunk/jena-tdb/src/main/java/com/hp/hpl/jena/tdb/solver/OpExecutorTDB.java (original)
+++ jena/trunk/jena-tdb/src/main/java/com/hp/hpl/jena/tdb/solver/OpExecutorTDB.java Wed Jul
24 20:18:42 2013
@@ -33,6 +33,7 @@ import com.hp.hpl.jena.sparql.algebra.op
 import com.hp.hpl.jena.sparql.core.BasicPattern ;
 import com.hp.hpl.jena.sparql.core.Quad ;
 import com.hp.hpl.jena.sparql.core.Substitute ;
+import com.hp.hpl.jena.sparql.core.Var ;
 import com.hp.hpl.jena.sparql.engine.ExecutionContext ;
 import com.hp.hpl.jena.sparql.engine.QueryIterator ;
 import com.hp.hpl.jena.sparql.engine.iterator.QueryIterPeek ;
@@ -337,9 +338,13 @@ public class OpExecutorTDB extends OpExe
     { 
         DatasetGraphTDB ds = (DatasetGraphTDB)execCxt.getDataset() ;
         Filter<Tuple<NodeId>> filter = QC2.getFilter(execCxt.getContext()) ;
-        return SolverLib.graphNames(ds, dsNames.getGraphNode(), input, filter, execCxt) ;
+        Node gn = dsNames.getGraphNode() ;
+        if ( Var.isVar(gn) )
+            return SolverLib.graphNames(ds, dsNames.getGraphNode(), input, filter, execCxt)
;
+        else
+            return SolverLib.testForGraphName(ds, dsNames.getGraphNode(), input, filter,
execCxt) ;
     }
-    
+
     // ---- OpExecute factories and plain executor.
     
     private static OpExecutorFactory plainFactory = new OpExecutorPlainFactoryTDB() ;

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=1506692&r1=1506691&r2=1506692&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 Wed Jul 24
20:18:42 2013
@@ -37,6 +37,7 @@ import com.hp.hpl.jena.sparql.engine.Que
 import com.hp.hpl.jena.sparql.engine.binding.Binding ;
 import com.hp.hpl.jena.sparql.engine.binding.BindingFactory ;
 import com.hp.hpl.jena.sparql.engine.binding.BindingMap ;
+import com.hp.hpl.jena.sparql.engine.iterator.QueryIterNullIterator ;
 import com.hp.hpl.jena.tdb.TDBException ;
 import com.hp.hpl.jena.tdb.lib.NodeLib ;
 import com.hp.hpl.jena.tdb.nodetable.NodeTable ;
@@ -44,6 +45,7 @@ import com.hp.hpl.jena.tdb.nodetable.Nod
 import com.hp.hpl.jena.tdb.store.DatasetGraphTDB ;
 import com.hp.hpl.jena.tdb.store.GraphTDB ;
 import com.hp.hpl.jena.tdb.store.NodeId ;
+import com.hp.hpl.jena.tdb.sys.TDBInternal ;
 
 /** Utilities used within the TDB BGP solver : local TDB store */
 public class SolverLib
@@ -278,35 +280,55 @@ public class SolverLib
             }
         } ;
     }
+    
+    /** Find whether a specific graph name is in the quads table. */
+    public static QueryIterator testForGraphName(DatasetGraphTDB ds, Node graphNode, QueryIterator
input,
+                                                 Filter<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() ;
+            Iterator<Tuple<NodeId>> iter1 = ntt.find(nid, NodeId.NodeIdAny, NodeId.NodeIdAny,
NodeId.NodeIdAny) ;
+            if ( filter != null )
+                iter1 = Iter.filter(iter1, filter) ;
+            exists = iter1.hasNext() ;
+        }
 
-    /** Find all the graph names in the quads table. */ 
-    public static QueryIterator graphNames(DatasetGraphTDB ds, Node graphNode,
-                                           QueryIterator input, Filter<Tuple<NodeId>>
filter,
-                                           ExecutionContext execCxt)
-    {
+        if ( exists )
+            return input ;
+        else {
+            input.close() ;
+            return QueryIterNullIterator.create(execCxt) ;
+        }
+    }
+
+    /** Find all the graph names in the quads table. */
+    public static QueryIterator graphNames(DatasetGraphTDB ds, Node graphNode, QueryIterator
input,
+                                           Filter<Tuple<NodeId>> filter, ExecutionContext
execCxt) {
         List<Abortable> killList = new ArrayList<Abortable>() ;
-        Iterator<Tuple<NodeId>> iter1 = ds.getQuadTable().getNodeTupleTable().find(NodeId.NodeIdAny,
NodeId.NodeIdAny, NodeId.NodeIdAny, NodeId.NodeIdAny) ;
+        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 = Tuple.project(0, iter1) ;
-        // Project is cheap - don't brother wrapping iter1 
+        // 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) ;
-        Transform<Node, Binding> bindGraphName = new Transform<Node, Binding>(){
+        Transform<Node, Binding> bindGraphName = new Transform<Node, Binding>()
{
             @Override
-            public Binding convert(Node node)
-            {
+            public Binding convert(Node node) {
                 return BindingFactory.binding(var, node) ;
             }
         } ;
-        
+
         Iterator<Binding> iterBinding = Iter.map(iter4, bindGraphName) ;
         // Not abortable.
         return new QueryIterTDB(iterBinding, killList, input, execCxt) ;

Modified: jena/trunk/jena-tdb/src/main/java/com/hp/hpl/jena/tdb/sys/TDBInternal.java
URL: http://svn.apache.org/viewvc/jena/trunk/jena-tdb/src/main/java/com/hp/hpl/jena/tdb/sys/TDBInternal.java?rev=1506692&r1=1506691&r2=1506692&view=diff
==============================================================================
--- jena/trunk/jena-tdb/src/main/java/com/hp/hpl/jena/tdb/sys/TDBInternal.java (original)
+++ jena/trunk/jena-tdb/src/main/java/com/hp/hpl/jena/tdb/sys/TDBInternal.java Wed Jul 24
20:18:42 2013
@@ -49,13 +49,22 @@ public class TDBInternal
     public static NodeId getNodeId(DatasetGraph ds, Node node)
     {
         DatasetGraphTDB dsg = getDatasetGraphTDB(ds) ;
+        return getNodeId(dsg, node) ;
+    }
+    
+    /** Return the NodeId for a node.
+     * Returns NodeId.NodeDoesNotExist when the node is not found. 
+     * Returns null when not a TDB-backed dataset.
+     */
+    public static NodeId getNodeId(DatasetGraphTDB dsg, Node node)
+    {
         if ( dsg == null )
             return null ;
         NodeTable nodeTable = dsg.getQuadTable().getNodeTupleTable().getNodeTable() ;
         NodeId nodeId = nodeTable.getNodeIdForNode(node) ;
         return nodeId ;
     }
-    
+
     /** Return the node for a NodeId (if any).
      *  Returns null if the NodeId does not exist in the dataset. 
      */
@@ -70,6 +79,14 @@ public class TDBInternal
     public static Node getNode(DatasetGraph ds, NodeId nodeId)
     {
         DatasetGraphTDB dsg = getDatasetGraphTDB(ds) ;
+        return getNode(dsg, nodeId) ;
+    }
+
+    /** Return the node for a NodeId (if any).
+     *  Returns null if the NodeId does not exist in the dataset. 
+     */
+    public static Node getNode(DatasetGraphTDB dsg, NodeId nodeId)
+    {
         if ( dsg == null )
             return null ;
         NodeTable nodeTable = dsg.getQuadTable().getNodeTupleTable().getNodeTable() ;

Modified: jena/trunk/jena-tdb/src/test/java/com/hp/hpl/jena/tdb/store/Test_SPARQL_TDB.java
URL: http://svn.apache.org/viewvc/jena/trunk/jena-tdb/src/test/java/com/hp/hpl/jena/tdb/store/Test_SPARQL_TDB.java?rev=1506692&r1=1506691&r2=1506692&view=diff
==============================================================================
--- jena/trunk/jena-tdb/src/test/java/com/hp/hpl/jena/tdb/store/Test_SPARQL_TDB.java (original)
+++ jena/trunk/jena-tdb/src/test/java/com/hp/hpl/jena/tdb/store/Test_SPARQL_TDB.java Wed Jul
24 20:18:42 2013
@@ -99,7 +99,7 @@ public class Test_SPARQL_TDB extends Bas
     
     @Test public void sparql4()
     {
-        // Requires OpDatasetNames 
+        // OpDatasetNames 
         Dataset dataset = create() ;
         
         String graphName = "http://example/" ;
@@ -115,6 +115,36 @@ public class Test_SPARQL_TDB extends Bas
         assertEquals(1, n) ;
     }
     
+    @Test public void sparql5()
+    {
+        Dataset dataset = create() ;
+        
+        String graphName = "http://example/" ;
+        Triple triple = SSE.parseTriple("(<x> <y> 123)") ;
+        Graph g2 = dataset.asDatasetGraph().getGraph(NodeFactory.createURI(graphName)) ;
+        // Graphs only exists if they have a triple in them
+        g2.add(triple) ;
+        
+        Query query = QueryFactory.create("ASK { GRAPH <"+graphName+"> {} }") ;
+        boolean b = QueryExecutionFactory.create(query, dataset).execAsk() ;
+        assertEquals(true, b) ;
+    }
+    
+    @Test public void sparql6()
+    {
+        Dataset dataset = create() ;
+        
+        String graphName = "http://example/" ;
+        Triple triple = SSE.parseTriple("(<http://example/x> <http://example/y>
123)") ;
+        Graph g2 = dataset.asDatasetGraph().getGraph(NodeFactory.createURI(graphName)) ;
+        // Graphs only exists if they have a triple in them
+        g2.add(triple) ;
+        
+        Query query = QueryFactory.create("ASK { GRAPH <http://example/x> {} }") ;
+        boolean b = QueryExecutionFactory.create(query, dataset).execAsk() ;
+        assertEquals(false, b) ;
+    }
+
     // Test transactions effective.
     
     @Test public void sparql_txn_1()



Mime
View raw message