jena-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a...@apache.org
Subject [10/18] jena git commit: JENA-1158: union default graph tests and clearup.
Date Sat, 09 Jul 2016 09:39:06 GMT
JENA-1158: union default graph tests and clearup.

Project: http://git-wip-us.apache.org/repos/asf/jena/repo
Commit: http://git-wip-us.apache.org/repos/asf/jena/commit/9ddfccac
Tree: http://git-wip-us.apache.org/repos/asf/jena/tree/9ddfccac
Diff: http://git-wip-us.apache.org/repos/asf/jena/diff/9ddfccac

Branch: refs/heads/master
Commit: 9ddfccac29b4d7dbc17c920035045846b38523cc
Parents: 145b713
Author: Andy Seaborne <andy@apache.org>
Authored: Fri Jul 8 18:05:38 2016 +0100
Committer: Andy Seaborne <andy@apache.org>
Committed: Fri Jul 8 18:05:38 2016 +0100

----------------------------------------------------------------------
 .../jena/sparql/core/DatasetGraphMap.java       |   8 +-
 .../jena/sparql/core/DatasetGraphMapLink.java   |   8 +-
 .../jena/sparql/engine/main/OpExecutor.java     |   4 -
 .../engine/main/iterator/QueryIterGraph.java    |   2 +-
 .../uniongraph/AbstractTestUnionTransform.java  |  95 --------
 .../algebra/uniongraph/Dev_TS_UnionGraph.java   |  35 ---
 .../algebra/uniongraph/TestUnionGraph.java      | 100 ---------
 .../uniongraph/TestUnionTransformQuads.java     |  34 ---
 .../uniongraph/TestUnionTransformTriples.java   |  33 ---
 .../org/apache/jena/sparql/core/TS_Core.java    |   2 +
 .../jena/sparql/core/TestSpecialGraphs.java     | 218 +++++++++++++++++++
 11 files changed, 235 insertions(+), 304 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/jena/blob/9ddfccac/jena-arq/src/main/java/org/apache/jena/sparql/core/DatasetGraphMap.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/main/java/org/apache/jena/sparql/core/DatasetGraphMap.java b/jena-arq/src/main/java/org/apache/jena/sparql/core/DatasetGraphMap.java
index 4679776..dc06ca7 100644
--- a/jena-arq/src/main/java/org/apache/jena/sparql/core/DatasetGraphMap.java
+++ b/jena-arq/src/main/java/org/apache/jena/sparql/core/DatasetGraphMap.java
@@ -32,6 +32,7 @@ import org.apache.jena.graph.Triple ;
 import org.apache.jena.query.ReadWrite ;
 import org.apache.jena.sparql.ARQException ;
 import org.apache.jena.sparql.core.DatasetGraphFactory.GraphMaker ;
+import org.apache.jena.sparql.graph.GraphUnionRead ;
 
 /** Implementation of a {@code DatasetGraph} as an extensible set of graphs.
  *  Subclasses need to manage any implicit graph creation.
@@ -136,6 +137,11 @@ public class DatasetGraphMap extends DatasetGraphTriplesQuads
 
     @Override
     public Graph getGraph(Node graphNode) {
+        if ( Quad.isUnionGraph(graphNode) ) 
+            return new GraphUnionRead(this) ;
+        if ( Quad.isDefaultGraph(graphNode))
+            return getDefaultGraph() ;
+        // Not a special case.
         Graph g = graphs.get(graphNode);
         if ( g == null ) {
             g = getGraphCreate();
@@ -147,7 +153,7 @@ public class DatasetGraphMap extends DatasetGraphTriplesQuads
 
     /** Called from getGraph when a nonexistent graph is asked for.
      * Return null for "nothing created as a graph".
-     * Sub classes reimplement this or pr  
+     * Sub classes can reimplement this.  
      */
     protected Graph getGraphCreate() { 
         Graph g = graphMaker.create() ;

http://git-wip-us.apache.org/repos/asf/jena/blob/9ddfccac/jena-arq/src/main/java/org/apache/jena/sparql/core/DatasetGraphMapLink.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/main/java/org/apache/jena/sparql/core/DatasetGraphMapLink.java b/jena-arq/src/main/java/org/apache/jena/sparql/core/DatasetGraphMapLink.java
index 4835aed..41f5169 100644
--- a/jena-arq/src/main/java/org/apache/jena/sparql/core/DatasetGraphMapLink.java
+++ b/jena-arq/src/main/java/org/apache/jena/sparql/core/DatasetGraphMapLink.java
@@ -26,6 +26,7 @@ import org.apache.jena.graph.Graph ;
 import org.apache.jena.graph.Node ;
 import org.apache.jena.query.ReadWrite ;
 import org.apache.jena.sparql.core.DatasetGraphFactory.GraphMaker ;
+import org.apache.jena.sparql.graph.GraphUnionRead ;
 
 /** Implementation of a DatasetGraph as an extensible set of graphs.
  *  <p>
@@ -138,11 +139,16 @@ public class DatasetGraphMapLink extends DatasetGraphCollection
 
     @Override
     public Graph getGraph(Node graphNode) {
+        if ( Quad.isUnionGraph(graphNode) ) 
+            return new GraphUnionRead(this) ;
+        if ( Quad.isDefaultGraph(graphNode))
+            return getDefaultGraph() ;
+        // Not a special case.
         Graph g = graphs.get(graphNode);
         if ( g == null ) {
             g = getGraphCreate();
             if ( g != null )
-                addGraph(graphNode, g);
+                graphs.put(graphNode, g);
         }
         return g;
     }

http://git-wip-us.apache.org/repos/asf/jena/blob/9ddfccac/jena-arq/src/main/java/org/apache/jena/sparql/engine/main/OpExecutor.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/main/java/org/apache/jena/sparql/engine/main/OpExecutor.java b/jena-arq/src/main/java/org/apache/jena/sparql/engine/main/OpExecutor.java
index d301a38..f97c5c1 100644
--- a/jena-arq/src/main/java/org/apache/jena/sparql/engine/main/OpExecutor.java
+++ b/jena-arq/src/main/java/org/apache/jena/sparql/engine/main/OpExecutor.java
@@ -24,7 +24,6 @@ import java.util.List ;
 import java.util.Set ;
 
 import org.apache.jena.atlas.iterator.Iter ;
-import org.apache.jena.atlas.logging.Log ;
 import org.apache.jena.graph.Node ;
 import org.apache.jena.query.ARQ ;
 import org.apache.jena.query.QueryExecException ;
@@ -152,9 +151,6 @@ public class OpExecutor
             return execute(subOp, input, cxt2) ;
         }
 
-        if ( Quad.isUnionGraph(gn) )
-            Log.warn(this, "Not implemented yet: union default graph in general OpExecutor")
;
-
         // Bad news -- if ( Lib.equals(gn, Quad.tripleInQuad) ) {}
         return null ;
     }

http://git-wip-us.apache.org/repos/asf/jena/blob/9ddfccac/jena-arq/src/main/java/org/apache/jena/sparql/engine/main/iterator/QueryIterGraph.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/main/java/org/apache/jena/sparql/engine/main/iterator/QueryIterGraph.java
b/jena-arq/src/main/java/org/apache/jena/sparql/engine/main/iterator/QueryIterGraph.java
index bd957f8..0d36902 100644
--- a/jena-arq/src/main/java/org/apache/jena/sparql/engine/main/iterator/QueryIterGraph.java
+++ b/jena-arq/src/main/java/org/apache/jena/sparql/engine/main/iterator/QueryIterGraph.java
@@ -82,7 +82,7 @@ public class QueryIterGraph extends QueryIterRepeatApply
 
     protected static Iterator<Node> makeSources(DatasetGraph data, Binding b, Node
graphVar) {
         Node n2 = resolve(b, graphVar) ;
-        if ( n2 != null && ! n2.isURI() )
+        if ( n2 != null && n2.isLiteral() ) 
             // Blank node or literal possible after resolving
             return Iter.nullIterator() ;
         

http://git-wip-us.apache.org/repos/asf/jena/blob/9ddfccac/jena-arq/src/test/java/org/apache/jena/sparql/algebra/uniongraph/AbstractTestUnionTransform.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/test/java/org/apache/jena/sparql/algebra/uniongraph/AbstractTestUnionTransform.java
b/jena-arq/src/test/java/org/apache/jena/sparql/algebra/uniongraph/AbstractTestUnionTransform.java
deleted file mode 100644
index 1fc50bf..0000000
--- a/jena-arq/src/test/java/org/apache/jena/sparql/algebra/uniongraph/AbstractTestUnionTransform.java
+++ /dev/null
@@ -1,95 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.jena.sparql.algebra.uniongraph;
-
-import java.util.List ;
-
-import org.apache.jena.atlas.iterator.Iter ;
-import org.apache.jena.atlas.junit.BaseTest ;
-import org.apache.jena.sparql.algebra.Algebra ;
-import org.apache.jena.sparql.algebra.Op ;
-import org.apache.jena.sparql.core.Quad ;
-import org.apache.jena.sparql.engine.QueryIterator ;
-import org.apache.jena.sparql.engine.binding.Binding ;
-import org.junit.Test ;
-
-public abstract class AbstractTestUnionTransform extends BaseTest
-{
-    // Tests of patterns over the implicit union of all named graphs.
-    // Two sets - for triples and for quads
-    
-    // TODO need multiple triple pattern BGPs. 
-    
-    @Test public void union_1()
-    {
-        List<Binding> results = exec("(bgp (?s ?p ?o))") ;
-        assertEquals(2, results.size()) ;
-    }
-    
-    @Test public void union_2()
-    {
-        List<Binding> results = exec("(bgp (<s2> ?p ?o))") ;
-        assertEquals(1, results.size()) ;
-    }
-    
-    @Test public void union_3()
-    {
-        List<Binding> results = exec("(graph <g1> (bgp (<s1> ?p ?o)))")
;
-        assertEquals(1, results.size()) ;
-    }
-
-    @Test public void union_4()
-    {
-        List<Binding> results = exec("(graph <g1> (bgp (<s2> ?p ?o)))")
;
-        assertEquals(0, results.size()) ;
-    }
-
-    @Test public void union_5()
-    {
-        List<Binding> results = exec("(graph <g2> (bgp (<s2> ?p ?o)))")
;
-        assertEquals(1, results.size()) ;
-    }
-
-    @Test public void union_6()
-    {
-        List<Binding> results = exec("(graph <"+Quad.defaultGraphIRI+"> (bgp
(<s2> ?p ?o)))") ;
-        assertEquals(0, results.size()) ;
-    }
-
-    @Test public void union_7()
-    {
-        List<Binding> results = exec("(graph <"+Quad.defaultGraphIRI+"> (bgp
(<x2> ?p ?o)))") ;
-        assertEquals(3, results.size()) ;
-    }
- 
-//    @Test public void union_7()
-//    {
-//        List<Binding> results = exec("(graph <"+Quad.defaultGraphNodeGenerated+">
(bgp (<s2> ?p ?o)))") ;
-//        assertEquals(1, results.size()) ;
-//    }
-    
-    private List<Binding> exec(String pattern)
-    {
-        Op op = op(pattern) ;
-        QueryIterator qIter = Algebra.exec(op, TestUnionGraph.dsg1) ;
-        return  Iter.toList(qIter) ;
-    }
-    
-    protected abstract Op op(String pattern) ;
-}

http://git-wip-us.apache.org/repos/asf/jena/blob/9ddfccac/jena-arq/src/test/java/org/apache/jena/sparql/algebra/uniongraph/Dev_TS_UnionGraph.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/test/java/org/apache/jena/sparql/algebra/uniongraph/Dev_TS_UnionGraph.java
b/jena-arq/src/test/java/org/apache/jena/sparql/algebra/uniongraph/Dev_TS_UnionGraph.java
deleted file mode 100644
index 6bffe16..0000000
--- a/jena-arq/src/test/java/org/apache/jena/sparql/algebra/uniongraph/Dev_TS_UnionGraph.java
+++ /dev/null
@@ -1,35 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.jena.sparql.algebra.uniongraph;
-
-import org.junit.runner.RunWith ;
-import org.junit.runners.Suite ;
-
-@RunWith(Suite.class)
-@Suite.SuiteClasses( {
-    TestUnionGraph.class
-    , TestUnionTransformTriples.class
-    , TestUnionTransformQuads.class
-})
-
-// Not active (hence does not get named TS_* because the POM names them for surefire tests)

-
-public class Dev_TS_UnionGraph
-{ }
-

http://git-wip-us.apache.org/repos/asf/jena/blob/9ddfccac/jena-arq/src/test/java/org/apache/jena/sparql/algebra/uniongraph/TestUnionGraph.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/test/java/org/apache/jena/sparql/algebra/uniongraph/TestUnionGraph.java
b/jena-arq/src/test/java/org/apache/jena/sparql/algebra/uniongraph/TestUnionGraph.java
deleted file mode 100644
index b54f5df..0000000
--- a/jena-arq/src/test/java/org/apache/jena/sparql/algebra/uniongraph/TestUnionGraph.java
+++ /dev/null
@@ -1,100 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.jena.sparql.algebra.uniongraph;
-
-import java.util.List ;
-
-import org.apache.jena.atlas.iterator.Iter ;
-import org.apache.jena.atlas.junit.BaseTest ;
-import org.apache.jena.atlas.lib.StrUtils ;
-import org.apache.jena.sparql.algebra.Algebra ;
-import org.apache.jena.sparql.algebra.Op ;
-import org.apache.jena.sparql.core.DatasetGraph ;
-import org.apache.jena.sparql.core.Quad ;
-import org.apache.jena.sparql.engine.QueryIterator ;
-import org.apache.jena.sparql.engine.binding.Binding ;
-import org.apache.jena.sparql.sse.SSE ;
-import org.apache.jena.sparql.sse.builders.BuilderGraph ;
-import org.junit.Test ;
-
-public class TestUnionGraph extends BaseTest
-{
-    static String x1 = StrUtils.strjoinNL("(dataset",
-                                         "  (graph (<s> <p> <o>) (<x>
<p> <o>) (<x2> <p> <o1>) (<x2> <p> <o3>) (<x2>
<p> <o4>))",
-                                         "  (graph <g1> (triple <s1> <p1>
<o1>))",
-                                         "  (graph <g2> (triple <s2> <p2>
<o2>))",
-                                         "  (graph <g3> (triple <s2> <p2>
<o2>))", // Duplicate triple
-                                         ")") ;
-    static DatasetGraph dsg1 = BuilderGraph.buildDataset(SSE.parse(x1)) ;
-
-    static String x2 = StrUtils.strjoinNL("(dataset",
-                                         "  (graph (<s> <p1> 10) (<s> <p1>
11) (<s> <p2> 20) )",
-                                         "  (graph <g1> (<s1> <p1> <z>)
(<z> <p2> 1) )",
-                                         "  (graph <g2> (<s1> <p1> <z>)
(<z> <p2> 2) )",
-                                         "  (graph <g3> (<s>  <p1> 10))",
-                                         ")") ;
-    
-    static DatasetGraph dsg2 = BuilderGraph.buildDataset(SSE.parse(x2)) ;
-
-    @Test
-    public void union_graph_triples_1() {
-        List<Binding> results = exec("(graph <" + Quad.unionGraph + "> (bgp (<s2>
?p ?o)))", false, dsg1) ;
-        assertEquals(1, results.size()) ;
-    }
-
-    @Test
-    public void union_graph_triples_2() {
-        List<Binding> results = exec("(graph <" + Quad.unionGraph + "> (bgp (<x2>
?p ?o)))", false, dsg1) ;
-        assertEquals(0, results.size()) ;
-    }
-
-    @Test
-    public void union_graph_quads_1() {
-        List<Binding> results = exec("(graph <" + Quad.unionGraph + "> (bgp (<s2>
?p ?o)))", true, dsg1) ;
-        assertEquals(1, results.size()) ;
-    }
-
-    @Test
-    public void union_graph_quads_2() {
-        List<Binding> results = exec("(graph <" + Quad.unionGraph + "> (bgp (<x2>
?p ?o)))", true, dsg1) ;
-        assertEquals(0, results.size()) ;
-    }
-
-    // Patterns
-    @Test
-    public void union_graph_triples_10() {
-        List<Binding> results = exec("(graph <" + Quad.unionGraph + "> (bgp (<s1>
?p ?z) (?z ?q ?o) ))", false, dsg2) ;
-        assertEquals(2, results.size()) ;
-    }
-
-    @Test
-    public void union_graph_quads_10() {
-        List<Binding> results = exec("(graph <" + Quad.unionGraph + "> (bgp (<s1>
?p ?z) (?z ?q ?o) ))", false, dsg2) ;
-        assertEquals(2, results.size()) ;
-    }
-
-    static private List<Binding> exec(String pattern, boolean applyQuad, DatasetGraph
dsg) {
-        Op op = SSE.parseOp(pattern) ;
-        if ( applyQuad )
-            op = Algebra.toQuadForm(op) ;
-        Op op2 = Algebra.unionDefaultGraph(op) ;
-        QueryIterator qIter = Algebra.exec(op, TestUnionGraph.dsg1) ;
-        return Iter.toList(qIter) ;
-    }
-}

http://git-wip-us.apache.org/repos/asf/jena/blob/9ddfccac/jena-arq/src/test/java/org/apache/jena/sparql/algebra/uniongraph/TestUnionTransformQuads.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/test/java/org/apache/jena/sparql/algebra/uniongraph/TestUnionTransformQuads.java
b/jena-arq/src/test/java/org/apache/jena/sparql/algebra/uniongraph/TestUnionTransformQuads.java
deleted file mode 100644
index 8477421..0000000
--- a/jena-arq/src/test/java/org/apache/jena/sparql/algebra/uniongraph/TestUnionTransformQuads.java
+++ /dev/null
@@ -1,34 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.jena.sparql.algebra.uniongraph;
-
-import org.apache.jena.sparql.algebra.Algebra ;
-import org.apache.jena.sparql.algebra.Op ;
-import org.apache.jena.sparql.sse.SSE ;
-
-public class TestUnionTransformQuads extends AbstractTestUnionTransform  
-{
-    @Override
-    protected Op op(String pattern) {
-        Op op = SSE.parseOp(pattern) ;
-        op = Algebra.toQuadForm(op) ;
-        Op op2 = Algebra.unionDefaultGraph(op) ;
-        return op2 ;
-    }
-}

http://git-wip-us.apache.org/repos/asf/jena/blob/9ddfccac/jena-arq/src/test/java/org/apache/jena/sparql/algebra/uniongraph/TestUnionTransformTriples.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/test/java/org/apache/jena/sparql/algebra/uniongraph/TestUnionTransformTriples.java
b/jena-arq/src/test/java/org/apache/jena/sparql/algebra/uniongraph/TestUnionTransformTriples.java
deleted file mode 100644
index 5506480..0000000
--- a/jena-arq/src/test/java/org/apache/jena/sparql/algebra/uniongraph/TestUnionTransformTriples.java
+++ /dev/null
@@ -1,33 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.jena.sparql.algebra.uniongraph;
-
-import org.apache.jena.sparql.algebra.Algebra ;
-import org.apache.jena.sparql.algebra.Op ;
-import org.apache.jena.sparql.sse.SSE ;
-
-public class TestUnionTransformTriples extends AbstractTestUnionTransform  
-{
-    @Override
-    protected Op op(String pattern) {
-        Op op = SSE.parseOp(pattern) ;
-        Op op2 = Algebra.unionDefaultGraph(op) ;
-        return op2 ;
-    }
-}

http://git-wip-us.apache.org/repos/asf/jena/blob/9ddfccac/jena-arq/src/test/java/org/apache/jena/sparql/core/TS_Core.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/test/java/org/apache/jena/sparql/core/TS_Core.java b/jena-arq/src/test/java/org/apache/jena/sparql/core/TS_Core.java
index e31fe46..e17aed9 100644
--- a/jena-arq/src/test/java/org/apache/jena/sparql/core/TS_Core.java
+++ b/jena-arq/src/test/java/org/apache/jena/sparql/core/TS_Core.java
@@ -40,6 +40,8 @@ import org.junit.runners.Suite ;
     , TestDatasetGraphBaseFind_Mem.class
     , TestDatasetGraphBaseFindPattern_General.class
     , TestDatasetGraphBaseFindPattern_Mem.class
+    
+    , TestSpecialGraphs.class
 })
 
 public class TS_Core

http://git-wip-us.apache.org/repos/asf/jena/blob/9ddfccac/jena-arq/src/test/java/org/apache/jena/sparql/core/TestSpecialGraphs.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/test/java/org/apache/jena/sparql/core/TestSpecialGraphs.java b/jena-arq/src/test/java/org/apache/jena/sparql/core/TestSpecialGraphs.java
new file mode 100644
index 0000000..613994f
--- /dev/null
+++ b/jena-arq/src/test/java/org/apache/jena/sparql/core/TestSpecialGraphs.java
@@ -0,0 +1,218 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.jena.sparql.core;
+
+import static org.apache.jena.sparql.core.TestSpecialGraphs.Mode.QUADS ;
+import static org.apache.jena.sparql.core.TestSpecialGraphs.Mode.TRIPLES ;
+import static org.junit.Assert.assertEquals ;
+
+import java.util.Arrays ;
+import java.util.Collection ;
+import java.util.List ;
+
+import org.apache.jena.atlas.iterator.Iter ;
+import org.apache.jena.atlas.lib.Creator ;
+import org.apache.jena.atlas.lib.StrUtils ;
+import org.apache.jena.sparql.algebra.Algebra ;
+import org.apache.jena.sparql.algebra.Op ;
+import org.apache.jena.sparql.core.DatasetGraph ;
+import org.apache.jena.sparql.core.DatasetGraphFactory ;
+import org.apache.jena.sparql.core.Quad ;
+import org.apache.jena.sparql.engine.QueryIterator ;
+import org.apache.jena.sparql.engine.binding.Binding ;
+import org.apache.jena.sparql.sse.SSE ;
+import org.apache.jena.sparql.sse.builders.BuilderGraph ;
+import org.junit.Test ;
+import org.junit.runner.RunWith ;
+import org.junit.runners.Parameterized ;
+import org.junit.runners.Parameterized.Parameters ;
+
+/** Test special graphs */
+@RunWith(Parameterized.class)
+public class TestSpecialGraphs {
+    @Parameters(name = "{index}: {0}")
+    public static Collection<Object[]> data() {
+        Creator<DatasetGraph> datasetGeneralMaker = ()-> DatasetGraphFactory.createGeneral()
; 
+        Creator<DatasetGraph> datasetTxnMemMaker  = ()-> DatasetGraphFactory.createTxnMem()
;
+        Creator<DatasetGraph> datasetMemMaker     = ()-> DatasetGraphFactory.create()
;
+        return Arrays.asList(new Object[][] {
+            { "General",  datasetGeneralMaker },
+            { "Plain",    datasetMemMaker} ,
+            { "TxnMem",   datasetTxnMemMaker}
+            });
+    }
+    
+    static enum Mode { TRIPLES, QUADS } 
+    
+    static String x1 = StrUtils.strjoinNL("(dataset",
+                                          "  (graph (<s> <p> <x>) (<x>
<p> <o>) (<x2> <p> <o1>) (<x2> <p> <o3>) (<x2>
<p> <o4>))",
+                                          "  (graph <g1> (<s1> <p1> <s1>)
(<s1> <p1> <s2>))",
+                                          "  (graph <g2> (triple <s2> <p2>
<o2>) (triple <s2> <p3> <o3>))",
+                                          "  (graph <g3> (triple <s2> <p2>
<o2>))", // Duplicate triple
+                                          ")") ;
+    private DatasetGraph dsg ;
+    
+    public TestSpecialGraphs(String label, Creator<DatasetGraph> maker) {
+        this.dsg = BuilderGraph.buildDataset(maker.create(), SSE.parse(x1)) ;
+    }
+
+    @Test
+    public void union_dft_1t() {
+        union_dft_1(TRIPLES) ;
+    }
+    
+    @Test
+    public void union_dft_1q() {
+        union_dft_1(QUADS) ;
+    }
+    
+    private void union_dft_1(Mode mode) {
+        Op op = op("(bgp (?s ?p ?o))", mode) ;
+        List<Binding> results = exec(op) ;
+        assertEquals(5, results.size()) ;
+        Op op2 = Algebra.unionDefaultGraph(op) ;
+        List<Binding> results2 = exec(op2) ;
+        assertEquals(4, results2.size()) ;
+    }
+    
+    @Test
+    public void graph_union_1t() {
+        List<Binding> results = exec("(graph <" + Quad.unionGraph.getURI() + ">
(bgp (<s2> ?p ?o)))", TRIPLES) ;
+        assertEquals(2, results.size()) ;
+    }
+
+    @Test
+    public void graph_union_1q() {
+        List<Binding> results = exec("(graph <" + Quad.unionGraph.getURI() + ">
(bgp (<s2> ?p ?o)))", QUADS) ;
+        assertEquals(2, results.size()) ;
+    }
+
+    @Test
+    public void graph_union_2t() {
+        List<Binding> results = exec("(graph <" + Quad.unionGraph.getURI() + ">
(bgp (<s1> ?p ?o) (?o ?q ?z)  ))", TRIPLES) ;
+        assertEquals(4, results.size()) ;
+    }
+
+    @Test
+    public void graph_union_2q() {
+        List<Binding> results = exec("(graph <" + Quad.unionGraph.getURI() + ">
(bgp (<s1> ?p ?o) (?o ?q ?z)  ))", QUADS) ;
+        assertEquals(4, results.size()) ;
+    }
+
+    @Test
+    public void graph_dft_1t() {
+        List<Binding> results = exec("(graph <" + Quad.defaultGraphIRI.getURI()
+ "> (bgp (<s2> ?p ?o)))", TRIPLES) ;
+        assertEquals(0, results.size()) ;
+    }
+
+    @Test
+    public void graph_dft_1q() {
+        List<Binding> results = exec("(graph <" + Quad.defaultGraphIRI.getURI()
+ "> (bgp (<s2> ?p ?o)))", QUADS) ;
+        assertEquals(0, results.size()) ;
+    }
+
+    @Test
+    public void graph_dft_2t() {
+        List<Binding> results = exec("(graph <" + Quad.defaultGraphIRI.getURI()
+ "> (bgp (<s> ?p ?o)))", TRIPLES) ;
+        assertEquals(1, results.size()) ;
+    }
+
+    @Test
+    public void graph_dft_2q() {
+        List<Binding> results = exec("(graph <" + Quad.defaultGraphIRI.getURI()
+ "> (bgp (<s> ?p ?o)))", QUADS) ;
+        assertEquals(1, results.size()) ;
+    }
+
+    @Test
+    public void graph_dft_3t() {
+        List<Binding> results = exec("(graph <" + Quad.defaultGraphIRI.getURI()
+ "> (bgp (?x ?p ?z) (?z ?q ?y) ))", TRIPLES) ;
+        assertEquals(1, results.size()) ;
+    }
+
+    @Test
+    public void graph_dft_3q() {
+        List<Binding> results = exec("(graph <" + Quad.defaultGraphIRI.getURI()
+ "> (bgp (?x ?p ?z) (?z ?q ?y) ))", QUADS) ;
+        assertEquals(1, results.size()) ;
+    }
+
+    @Test
+    public void graph_dftg_1t() {
+        List<Binding> results = exec("(graph <" + Quad.defaultGraphNodeGenerated.getURI()
+ "> (bgp (<s2> ?p ?o)))", TRIPLES) ;
+        assertEquals(0, results.size()) ;
+    }
+    
+    @Test
+    public void graph_dftg_2t() {
+        List<Binding> results = exec("(graph <" + Quad.defaultGraphNodeGenerated.getURI()
+ "> (bgp (<x2> ?p ?o)))", TRIPLES) ;
+        assertEquals(3, results.size()) ;
+    }
+    
+    @Test
+    public void graph_dftg_1q() {
+        List<Binding> results = exec("(graph <" + Quad.defaultGraphNodeGenerated.getURI()
+ "> (bgp (<s2> ?p ?o)))", QUADS) ;
+        assertEquals(0, results.size()) ;
+    }
+
+    @Test
+    public void graph_dftg_2q() {
+        List<Binding> results = exec("(graph <" + Quad.defaultGraphNodeGenerated.getURI()
+ "> (bgp (<x2> ?p ?o)))", QUADS) ;
+        assertEquals(3, results.size()) ;
+    }
+
+    @Test
+    public void direct_3t() {
+        List<Binding> results = exec("(graph <g1> (bgp (<s1> ?p ?o)))",
TRIPLES) ;
+        assertEquals(2, results.size()) ;
+    }
+
+    @Test
+    public void direct_3q() {
+        List<Binding> results = exec("(graph <g1> (bgp (<s1> ?p ?o)))",
QUADS) ;
+        assertEquals(2, results.size()) ;
+    }
+
+    @Test
+    public void direct_4() {
+        List<Binding> results = exec("(graph <g1> (bgp (<s2> ?p ?o)))",
TRIPLES) ;
+        assertEquals(0, results.size()) ;
+    }
+
+    @Test
+    public void direct_5() {
+        List<Binding> results = exec("(graph <g2> (bgp (<s2> ?p ?o)))",
TRIPLES) ;
+        assertEquals(2, results.size()) ;
+    }
+
+    private List<Binding> exec(String string, Mode mode) {
+        Op op = op(string, mode) ;
+        return exec(op) ;
+    }
+    
+    private List<Binding> exec(Op op) {
+        QueryIterator qIter = Algebra.exec(op, dsg) ;
+        return Iter.toList(qIter) ;
+    }
+
+    protected Op op(String pattern, Mode mode) {
+        Op op = SSE.parseOp(pattern) ;
+        if ( mode == Mode.QUADS )
+            op = Algebra.toQuadForm(op) ;
+        return op ;
+    }
+}


Mime
View raw message