diff --git a/jena-arq/src/test/java/org/apache/jena/sparql/algebra/optimize/TestSemanticEquivalence.java b/jena-arq/src/test/java/org/apache/jena/sparql/algebra/optimize/TestSemanticEquivalence.java index 9e23cd775c4..7820a7e0264 100644 --- a/jena-arq/src/test/java/org/apache/jena/sparql/algebra/optimize/TestSemanticEquivalence.java +++ b/jena-arq/src/test/java/org/apache/jena/sparql/algebra/optimize/TestSemanticEquivalence.java @@ -71,10 +71,6 @@ public static void setup() { dsg.add(Quad.defaultGraphNodeGenerated, b, p2, o); dsg.add(Quad.defaultGraphNodeGenerated, c, p1, o); //dsg.add(Quad.defaultGraphNodeGenerated, a, pSelf, a); - - // Currently these optimizations are off by default - Assert.assertFalse(ARQ.isFalse(ARQ.optFilterImplicitJoin)); - Assert.assertFalse(ARQ.isFalse(ARQ.optImplicitLeftJoin)); } @AfterClass diff --git a/jena-arq/src/test/java/org/apache/jena/sparql/algebra/optimize/TestTransformFilters.java b/jena-arq/src/test/java/org/apache/jena/sparql/algebra/optimize/TestTransformFilters.java index e0d94749223..ce879e5ea5a 100644 --- a/jena-arq/src/test/java/org/apache/jena/sparql/algebra/optimize/TestTransformFilters.java +++ b/jena-arq/src/test/java/org/apache/jena/sparql/algebra/optimize/TestTransformFilters.java @@ -278,7 +278,7 @@ public Op transform(OpTable opTable) { @Test public void disjunction03() { testOp("(filter (|| (!= ?x ) (= ?x )) (bgp ( ?s ?p ?x)) )", t_disjunction, - // Note - reording of disjunction terms. + // Note - reordering of disjunction terms. "(disjunction ", "(assign ((?x )) (bgp ( ?s ?p )))", "(filter (!= ?x ) (bgp ( ?s ?p ?x)))", @@ -391,11 +391,21 @@ public void oneOf6() { "(assign ((?x ?y)) (bgp (?y ?p ?o)(?y ?p1 ?o1)))"); } + // Test no longer appropriate. + // LATERAL means the variables that are join-scope bound may have values at execution time. +// @Test public void implicitJoin02() { +// testOp( +// "(filter (= ?x ?y) (bgp (?x ?p ?o)))", +// t_implicitJoin, +// "(table empty)"); +// } + + // LATERAL safe - no transformation. @Test public void implicitJoin02() { testOp( "(filter (= ?x ?y) (bgp (?x ?p ?o)))", t_implicitJoin, - "(table empty)"); + "(filter (= ?x ?y) (bgp (?x ?p ?o)))"); } @Test public void implicitJoin03() { @@ -465,17 +475,28 @@ public void oneOf6() { (String[])null); } + // Test no longer appropriate. + // LATERAL means the variables that are join-scope bound may have values at execution time. +// @Test public void implictJoin11() { +// // Test case related to JENA-500 +// // Detect that the expression (= ?prebound ?y) is always 'error' because +// // ?prebound is undef. Therefore the whole thing can be removed as there +// // can be no solutions. +// testOp( +// "(filter (= ?prebound ?y) (extend ((?y (ex:someFunction ?x))) (table unit)))", +// t_implicitJoin, +// "(table empty)"); +// } + + // LATERAL safe - no "(table empty)" substitution. @Test public void implictJoin11() { - // Test case related to JENA-500 - // Detect that the expression (= ?prebound ?y) is always 'error' because - // ?prebound is undef. Therefore the whole thing can be removed as there - // can be no solutions. testOp( "(filter (= ?prebound ?y) (extend ((?y (ex:someFunction ?x))) (table unit)))", t_implicitJoin, - "(table empty)"); + "(filter (= ?prebound ?y) (extend ((?y (ex:someFunction ?x))) (table unit)))"); } + @Test public void implicitJoin12() { // Test case from JENA-692 // Implicit join should not apply to the whole union because the variables involved aren't fixed diff --git a/jena-arq/testing/ARQ/Lateral/data.ttl b/jena-arq/testing/ARQ/Lateral/data.ttl new file mode 100644 index 00000000000..16d7b5f33d1 --- /dev/null +++ b/jena-arq/testing/ARQ/Lateral/data.ttl @@ -0,0 +1,24 @@ +PREFIX : + +:s1 :p 1 . +:s1 :label "s1-one" . + +:s2 :p 2 . +:s2 :label "s2-one" . +:s2 :label "s2-two" . + +:s3 :p 3 . +:s3 :label "s3-one" . +:s3 :label "s3-two" . +:s3 :label "s3-three" . + +:x1 :q 1 . +:z1 :q 1 . + +:x0 :q "a" . +:z0 :q "b" . + + + + + diff --git a/jena-arq/testing/ARQ/Lateral/lateral-1.arq b/jena-arq/testing/ARQ/Lateral/lateral-1.arq new file mode 100644 index 00000000000..0a8a6931a18 --- /dev/null +++ b/jena-arq/testing/ARQ/Lateral/lateral-1.arq @@ -0,0 +1,6 @@ +PREFIX : + +SELECT ?s ?label { + ?s :p ?o + LATERAL { SELECT * { ?s :label ?label } LIMIT 2 } +} diff --git a/jena-arq/testing/ARQ/Lateral/lateral-1.srj b/jena-arq/testing/ARQ/Lateral/lateral-1.srj new file mode 100644 index 00000000000..5415a7a0398 --- /dev/null +++ b/jena-arq/testing/ARQ/Lateral/lateral-1.srj @@ -0,0 +1,28 @@ +{ "head": { + "vars": [ "s" , "label" ] + } , + "results": { + "bindings": [ + { + "s": { "type": "uri" , "value": "http://example/s3" } , + "label": { "type": "literal" , "value": "s3-three" } + } , + { + "s": { "type": "uri" , "value": "http://example/s3" } , + "label": { "type": "literal" , "value": "s3-two" } + } , + { + "s": { "type": "uri" , "value": "http://example/s1" } , + "label": { "type": "literal" , "value": "s1-one" } + } , + { + "s": { "type": "uri" , "value": "http://example/s2" } , + "label": { "type": "literal" , "value": "s2-one" } + } , + { + "s": { "type": "uri" , "value": "http://example/s2" } , + "label": { "type": "literal" , "value": "s2-two" } + } + ] + } +} diff --git a/jena-arq/testing/ARQ/Lateral/lateral-2.arq b/jena-arq/testing/ARQ/Lateral/lateral-2.arq new file mode 100644 index 00000000000..16719c12df4 --- /dev/null +++ b/jena-arq/testing/ARQ/Lateral/lateral-2.arq @@ -0,0 +1,5 @@ +PREFIX : + +SELECT * { + LATERAL { ?s :label ?label } +} diff --git a/jena-arq/testing/ARQ/Lateral/lateral-2.srj b/jena-arq/testing/ARQ/Lateral/lateral-2.srj new file mode 100644 index 00000000000..b5ad458a9a2 --- /dev/null +++ b/jena-arq/testing/ARQ/Lateral/lateral-2.srj @@ -0,0 +1,32 @@ +{ "head": { + "vars": [ "s" , "label" ] + } , + "results": { + "bindings": [ + { + "s": { "type": "uri" , "value": "http://example/s3" } , + "label": { "type": "literal" , "value": "s3-three" } + } , + { + "s": { "type": "uri" , "value": "http://example/s3" } , + "label": { "type": "literal" , "value": "s3-two" } + } , + { + "s": { "type": "uri" , "value": "http://example/s1" } , + "label": { "type": "literal" , "value": "s1-one" } + } , + { + "s": { "type": "uri" , "value": "http://example/s2" } , + "label": { "type": "literal" , "value": "s2-one" } + } , + { + "s": { "type": "uri" , "value": "http://example/s2" } , + "label": { "type": "literal" , "value": "s2-two" } + } , + { + "s": { "type": "uri" , "value": "http://example/s3" } , + "label": { "type": "literal" , "value": "s3-one" } + } + ] + } +} diff --git a/jena-arq/testing/ARQ/Lateral/lateral-3.arq b/jena-arq/testing/ARQ/Lateral/lateral-3.arq new file mode 100644 index 00000000000..2be2ab1bd34 --- /dev/null +++ b/jena-arq/testing/ARQ/Lateral/lateral-3.arq @@ -0,0 +1,10 @@ +PREFIX : + +SELECT * { + ?s :q ?z . + + LATERAL { ?x :q ?v . + FILTER( ?x != ?s) + FILTER( ?v = ?z ) + } +} diff --git a/jena-arq/testing/ARQ/Lateral/lateral-3.srj b/jena-arq/testing/ARQ/Lateral/lateral-3.srj new file mode 100644 index 00000000000..ef4a7d9919e --- /dev/null +++ b/jena-arq/testing/ARQ/Lateral/lateral-3.srj @@ -0,0 +1,20 @@ +{ "head": { + "vars": [ "s" , "z" , "x" , "v" ] + } , + "results": { + "bindings": [ + { + "s": { "type": "uri" , "value": "http://example/z1" } , + "z": { "type": "literal" , "datatype": "http://www.w3.org/2001/XMLSchema#integer" , "value": "1" } , + "x": { "type": "uri" , "value": "http://example/x1" } , + "v": { "type": "literal" , "datatype": "http://www.w3.org/2001/XMLSchema#integer" , "value": "1" } + } , + { + "s": { "type": "uri" , "value": "http://example/x1" } , + "z": { "type": "literal" , "datatype": "http://www.w3.org/2001/XMLSchema#integer" , "value": "1" } , + "x": { "type": "uri" , "value": "http://example/z1" } , + "v": { "type": "literal" , "datatype": "http://www.w3.org/2001/XMLSchema#integer" , "value": "1" } + } + ] + } +} diff --git a/jena-arq/testing/ARQ/Lateral/lateral-4.arq b/jena-arq/testing/ARQ/Lateral/lateral-4.arq new file mode 100644 index 00000000000..5a09b2f10b6 --- /dev/null +++ b/jena-arq/testing/ARQ/Lateral/lateral-4.arq @@ -0,0 +1,7 @@ +PREFIX : + +SELECT * { + ?s :p ?o . + ## ?s : in-scope + LATERAL { SELECT ?s ?label { ?s :p ?label } } +} \ No newline at end of file diff --git a/jena-arq/testing/ARQ/Lateral/lateral-4.srj b/jena-arq/testing/ARQ/Lateral/lateral-4.srj new file mode 100644 index 00000000000..c1a232ea2eb --- /dev/null +++ b/jena-arq/testing/ARQ/Lateral/lateral-4.srj @@ -0,0 +1,23 @@ +{ "head": { + "vars": [ "s" , "o" , "label" ] + } , + "results": { + "bindings": [ + { + "s": { "type": "uri" , "value": "http://example/s3" } , + "o": { "type": "literal" , "datatype": "http://www.w3.org/2001/XMLSchema#integer" , "value": "3" } , + "label": { "type": "literal" , "datatype": "http://www.w3.org/2001/XMLSchema#integer" , "value": "3" } + } , + { + "s": { "type": "uri" , "value": "http://example/s1" } , + "o": { "type": "literal" , "datatype": "http://www.w3.org/2001/XMLSchema#integer" , "value": "1" } , + "label": { "type": "literal" , "datatype": "http://www.w3.org/2001/XMLSchema#integer" , "value": "1" } + } , + { + "s": { "type": "uri" , "value": "http://example/s2" } , + "o": { "type": "literal" , "datatype": "http://www.w3.org/2001/XMLSchema#integer" , "value": "2" } , + "label": { "type": "literal" , "datatype": "http://www.w3.org/2001/XMLSchema#integer" , "value": "2" } + } + ] + } +} diff --git a/jena-arq/testing/ARQ/Lateral/lateral-5.arq b/jena-arq/testing/ARQ/Lateral/lateral-5.arq new file mode 100644 index 00000000000..5228c0ca3c2 --- /dev/null +++ b/jena-arq/testing/ARQ/Lateral/lateral-5.arq @@ -0,0 +1,7 @@ +PREFIX : + +SELECT * { + ?s :p ?o . + ## ?s : different scope + LATERAL { SELECT ?label { ?s :p ?label } } +} \ No newline at end of file diff --git a/jena-arq/testing/ARQ/Lateral/lateral-5.srj b/jena-arq/testing/ARQ/Lateral/lateral-5.srj new file mode 100644 index 00000000000..dfb8b6b3983 --- /dev/null +++ b/jena-arq/testing/ARQ/Lateral/lateral-5.srj @@ -0,0 +1,53 @@ +{ "head": { + "vars": [ "s" , "o" , "label" ] + } , + "results": { + "bindings": [ + { + "s": { "type": "uri" , "value": "http://example/s3" } , + "o": { "type": "literal" , "datatype": "http://www.w3.org/2001/XMLSchema#integer" , "value": "3" } , + "label": { "type": "literal" , "datatype": "http://www.w3.org/2001/XMLSchema#integer" , "value": "3" } + } , + { + "s": { "type": "uri" , "value": "http://example/s3" } , + "o": { "type": "literal" , "datatype": "http://www.w3.org/2001/XMLSchema#integer" , "value": "3" } , + "label": { "type": "literal" , "datatype": "http://www.w3.org/2001/XMLSchema#integer" , "value": "1" } + } , + { + "s": { "type": "uri" , "value": "http://example/s3" } , + "o": { "type": "literal" , "datatype": "http://www.w3.org/2001/XMLSchema#integer" , "value": "3" } , + "label": { "type": "literal" , "datatype": "http://www.w3.org/2001/XMLSchema#integer" , "value": "2" } + } , + { + "s": { "type": "uri" , "value": "http://example/s1" } , + "o": { "type": "literal" , "datatype": "http://www.w3.org/2001/XMLSchema#integer" , "value": "1" } , + "label": { "type": "literal" , "datatype": "http://www.w3.org/2001/XMLSchema#integer" , "value": "3" } + } , + { + "s": { "type": "uri" , "value": "http://example/s1" } , + "o": { "type": "literal" , "datatype": "http://www.w3.org/2001/XMLSchema#integer" , "value": "1" } , + "label": { "type": "literal" , "datatype": "http://www.w3.org/2001/XMLSchema#integer" , "value": "1" } + } , + { + "s": { "type": "uri" , "value": "http://example/s1" } , + "o": { "type": "literal" , "datatype": "http://www.w3.org/2001/XMLSchema#integer" , "value": "1" } , + "label": { "type": "literal" , "datatype": "http://www.w3.org/2001/XMLSchema#integer" , "value": "2" } + } , + { + "s": { "type": "uri" , "value": "http://example/s2" } , + "o": { "type": "literal" , "datatype": "http://www.w3.org/2001/XMLSchema#integer" , "value": "2" } , + "label": { "type": "literal" , "datatype": "http://www.w3.org/2001/XMLSchema#integer" , "value": "3" } + } , + { + "s": { "type": "uri" , "value": "http://example/s2" } , + "o": { "type": "literal" , "datatype": "http://www.w3.org/2001/XMLSchema#integer" , "value": "2" } , + "label": { "type": "literal" , "datatype": "http://www.w3.org/2001/XMLSchema#integer" , "value": "1" } + } , + { + "s": { "type": "uri" , "value": "http://example/s2" } , + "o": { "type": "literal" , "datatype": "http://www.w3.org/2001/XMLSchema#integer" , "value": "2" } , + "label": { "type": "literal" , "datatype": "http://www.w3.org/2001/XMLSchema#integer" , "value": "2" } + } + ] + } +} diff --git a/jena-arq/testing/ARQ/Lateral/manifest.ttl b/jena-arq/testing/ARQ/Lateral/manifest.ttl new file mode 100644 index 00000000000..ed658810860 --- /dev/null +++ b/jena-arq/testing/ARQ/Lateral/manifest.ttl @@ -0,0 +1,97 @@ +# 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. + +PREFIX rdf: +PREFIX rdfs: +PREFIX mf: +PREFIX qt: +PREFIX ut: +PREFIX dawgt: +PREFIX test: +PREFIX xsd: + +PREFIX dct: +PREFIX xsd: +PREFIX foaf: +PREFIX skos: + +<#manifest> rdf:type mf:Manifest ; + rdfs:label "SPARQL-star Evaluation Tests" ; + skos:prefLabel "LATERAL"@en; + dct:licence ; + mf:entries ( + <#lateral-1> + <#lateral-2> + <#lateral-3> + <#lateral-4> + <#lateral-5> + ). + +<#lateral-1> rdf:type mf:QueryEvaluationTest ; + mf:name "LATERAL - LIMIT 2" ; + mf:action [ + qt:query ; + qt:data + ] ; + mf:result + . + +<#lateral-2> rdf:type mf:QueryEvaluationTest ; + mf:name "LATERAL - only pattern" ; + mf:action [ + qt:query ; + qt:data + ] ; + mf:result + . + +<#lateral-3> rdf:type mf:QueryEvaluationTest ; + mf:name "LATERAL - filter scope" ; + mf:action [ + qt:query ; + qt:data + ] ; + mf:result + . + +<#lateral-4> rdf:type mf:QueryEvaluationTest ; + mf:name "LATERAL - nested scope" ; + mf:action [ + qt:query ; + qt:data + ] ; + mf:result + . + +<#lateral-5> rdf:type mf:QueryEvaluationTest ; + mf:name "LATERAL - nested scope - hidden variable" ; + mf:action [ + qt:query ; + qt:data + ] ; + mf:result + . + + +## ?x :q ?z . LATERAL { ?s :q ?o FILTER (?z = ?o) } + +# No! +## ?s :p ?o . LATERAL { SELECT ?label { ?s :p ?label } } + +## bad +## ?s :p ?o . LATERAL { BIND(123 AS ?o) } +## ?s :p ?o . LATERAL { VALUES ?o ( 456 ) } +## ?s :p ?o . LATERAL { SELECT (789 AS ?s) {} } + diff --git a/jena-arq/testing/ARQ/RDF-star/Notes.txt b/jena-arq/testing/ARQ/RDF-star/Notes.txt deleted file mode 100644 index aaf858c286b..00000000000 --- a/jena-arq/testing/ARQ/RDF-star/Notes.txt +++ /dev/null @@ -1,12 +0,0 @@ -==== RDF Star tests - -cg/ -- community group tests - nt/, turtle/, trig/, sparql/ - -Copy of tests from -https://github.com/w3c/rdf-star/tree/main/tests - -Removed: - **/manifest.jsonld - **/index.html - **/manifest.htm \ No newline at end of file