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 2022/06/04 09:50:31 UTC
[jena] branch main updated: JENA-2332: Extract effective op for SERVICE
This is an automated email from the ASF dual-hosted git repository.
andy pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/jena.git
The following commit(s) were added to refs/heads/main by this push:
new c43849b474 JENA-2332: Extract effective op for SERVICE
new b947dd51eb Merge pull request #1364 from afs/jena-2332-join-service
c43849b474 is described below
commit c43849b474bd1746a4f2c8cc82dd0026d1be98eb
Author: Andy Seaborne <an...@apache.org>
AuthorDate: Fri Jun 3 21:29:27 2022 +0100
JENA-2332: Extract effective op for SERVICE
---
.../jena/sparql/engine/main/JoinClassifier.java | 5 +-
.../apache/jena/sparql/algebra/TestClassify.java | 120 +++++++++++----------
2 files changed, 67 insertions(+), 58 deletions(-)
diff --git a/jena-arq/src/main/java/org/apache/jena/sparql/engine/main/JoinClassifier.java b/jena-arq/src/main/java/org/apache/jena/sparql/engine/main/JoinClassifier.java
index 42dee58385..194654085a 100644
--- a/jena-arq/src/main/java/org/apache/jena/sparql/engine/main/JoinClassifier.java
+++ b/jena-arq/src/main/java/org/apache/jena/sparql/engine/main/JoinClassifier.java
@@ -212,9 +212,12 @@ public class JoinClassifier
op = ((OpExt)op).effectiveOp() ;
else if (safeModifier(op))
op = ((OpModifier)op).getSubOp() ;
- // JENA-1813, temporary fix.
+ // JENA-1813
else if (op instanceof OpGraph )
op = ((OpGraph)op).getSubOp() ;
+ // JENA-2332
+ else if (op instanceof OpService )
+ op = ((OpService)op).getSubOp() ;
else
return op;
}
diff --git a/jena-arq/src/test/java/org/apache/jena/sparql/algebra/TestClassify.java b/jena-arq/src/test/java/org/apache/jena/sparql/algebra/TestClassify.java
index c5af1f6fa7..fe55d00459 100644
--- a/jena-arq/src/test/java/org/apache/jena/sparql/algebra/TestClassify.java
+++ b/jena-arq/src/test/java/org/apache/jena/sparql/algebra/TestClassify.java
@@ -32,131 +32,131 @@ import org.junit.Test ;
public class TestClassify
{
- @Test public void testClassify_Join_01()
+ @Test public void testClassify_Join_01()
{ classifyJ("{?s :p :o . { ?s :p :o FILTER(true) } }", true) ; }
- @Test public void testClassify_Join_02()
+ @Test public void testClassify_Join_02()
{ classifyJ("{?s :p :o . { ?s :p :o FILTER(?s) } }", true) ; }
- @Test public void testClassify_Join_03()
+ @Test public void testClassify_Join_03()
{ classifyJ("{?s :p :o . { ?s :p ?o FILTER(?o) } }", true) ; }
// JENA-1167
// This safe; ?o is not an input to the filter block.
- @Test public void testClassify_Join_04()
+ @Test public void testClassify_Join_04()
{ classifyJ("{?s :p :o . { ?s :p :o FILTER(?o) } }", true) ; }
- @Test public void testClassify_Join_05()
+ @Test public void testClassify_Join_05()
{ classifyJ("{?s :p :o . { ?x :p :o FILTER(?s) } }", false) ; }
- @Test public void testClassify_Join_06()
+ @Test public void testClassify_Join_06()
{ classifyJ("{ { ?s :p :o FILTER(true) } ?s :p :o }", true) ; }
- @Test public void testClassify_Join_07()
+ @Test public void testClassify_Join_07()
{ classifyJ("{ { ?s :p :o FILTER(?s) } ?s :p :o }", true) ; }
- @Test public void testClassify_Join_08()
+ @Test public void testClassify_Join_08()
{ classifyJ("{ { ?s :p ?o FILTER(?o) } ?s :p :o }", true) ; }
- @Test public void testClassify_Join_09()
+ @Test public void testClassify_Join_09()
{ classifyJ("{ { ?s :p :o FILTER(?o) } ?s :p :o }", true) ; }
// Actually, this is safe IF executed left, then streamed to right.
- @Test public void testClassify_Join_10()
+ @Test public void testClassify_Join_10()
{ classifyJ("{ { ?x :p :o FILTER(?s) } ?s :p :o }", true) ; }
-
- // OPTIONAL nested inside {} so it is a join of the LHS and the {}-RHS.
+
+ // OPTIONAL nested inside {} so it is a join of the LHS and the {}-RHS.
// Not safe: ?s
// Other parts of RHS may restrict ?s to things that can't match the LHS.
- @Test public void testClassify_Join_11()
+ @Test public void testClassify_Join_11()
{ classifyJ("{?s :p :o . { OPTIONAL { ?s :p :o } } }", false) ; }
// Not safe: ?s
- @Test public void testClassify_Join_12()
+ @Test public void testClassify_Join_12()
{ classifyJ("{?s :p :o . { OPTIONAL { ?s :p :o FILTER(?s) } } }", false) ; }
- @Test public void testClassify_Join_13()
+ @Test public void testClassify_Join_13()
{ classifyJ("{?s :p :o . { ?x :p :o OPTIONAL { :s :p :o FILTER(?x) } } }", true) ; }
// See testClassify_Join_04()
- @Test public void testClassify_Join_14()
+ @Test public void testClassify_Join_14()
{ classifyJ("{?s :p :o . { OPTIONAL { :s :p :o FILTER(?o) } } }", true) ; }
- @Test public void testClassify_Join_14a()
+ @Test public void testClassify_Join_14a()
{ classifyJ("{?s :p :o . { OPTIONAL { :s :p ?o FILTER(?o) } } }", true) ; }
- @Test public void testClassify_Join_14b()
+ @Test public void testClassify_Join_14b()
{ classifyJ("{?s :p ?o . { OPTIONAL { :s :p :o FILTER(?o) } } }", false) ; }
-
- @Test public void testClassify_Join_15()
+
+ @Test public void testClassify_Join_15()
{ classifyJ("{?s :p :o . { OPTIONAL { ?x :p :o FILTER(?s) } } }", false) ; }
- @Test public void testClassify_Join_20()
+ @Test public void testClassify_Join_20()
{ classifyJ("{ {?s :p ?x } . { {} OPTIONAL { :s :p ?x } } }", false) ; }
-
+
// Assuming left-right execution, this is safe.
- @Test public void testClassify_Join_21()
+ @Test public void testClassify_Join_21()
{ classifyJ("{ { {} OPTIONAL { :s :p ?x } } {?s :p ?x } }", true) ; }
- @Test public void testClassify_Join_31()
+ @Test public void testClassify_Join_31()
{ classifyJ("{ ?x ?y ?z {SELECT ?s { ?s ?p ?o} } }", true) ; }
// JENA-1167 : Use of a filter variable not in the LHS
- @Test public void testClassify_Join_32()
+ @Test public void testClassify_Join_32()
{ classifyJ("{ GRAPH ?g { ?x ?y ?z } { FILTER (?a) } }", true) ; }
// Use of a filter variable from the LHS
- @Test public void testClassify_Join_33()
+ @Test public void testClassify_Join_33()
{ classifyJ("{ GRAPH ?g { ?x ?y ?z } { FILTER (?z) } }", false) ; }
// Use of a filter variable from the LHS but grounded in RHS
- @Test public void testClassify_Join_34()
+ @Test public void testClassify_Join_34()
{ classifyJ("{ GRAPH ?g { ?x ?y ?z } { ?a ?b ?z FILTER (?z) } }", true) ; }
// Use of a filter variable from the LHS but optional in RHS
- @Test public void testClassify_Join_35()
+ @Test public void testClassify_Join_35()
{ classifyJ("{ GRAPH ?g { ?x ?y ?z } { OPTIONAL{?a ?b ?z} FILTER (?z) } }", false) ; }
// The fix for JENA-1187 invalidates this test.
// @Test public void testClassify_Join_40()
// { classifyJ("{ ?x ?y ?z { ?x ?y ?z } UNION { ?x1 ?y1 ?z1 }}", true) ; }
- @Test public void testClassify_Join_41()
+ @Test public void testClassify_Join_41()
{ classifyJ("{ ?x ?y ?z { ?x1 ?y1 ?z1 BIND(?z+2 AS ?A) } UNION { ?x1 ?y1 ?z1 }}", false) ; }
- @Test public void testClassify_Join_42()
+ @Test public void testClassify_Join_42()
{ classifyJ("{ ?x ?y ?z { BIND(?z+2 AS ?A) } UNION { BIND(?z+2 AS ?B) }}", false) ; }
-
- @Test public void testClassify_Join_43()
+
+ @Test public void testClassify_Join_43()
{ classifyJ("{ ?x ?y ?z { LET(?A := ?z+2) } UNION { }}", false) ; }
-
- @Test public void testClassify_Join_44()
+
+ @Test public void testClassify_Join_44()
{ classifyJ("{ BIND(<x> AS ?typeX) { BIND(?typeX AS ?type) } }", false) ; }
- @Test public void testClassify_Join_45()
+ @Test public void testClassify_Join_45()
{ classifyJ("{ BIND(<x> AS ?typeX) { BIND(?typeX AS ?type) ?s ?p ?o FILTER(?o=?type) } }", false) ; }
-
+
// Unsafe - deep MINUS
// JENA-1021
- @Test public void testClassify_Join_50()
+ @Test public void testClassify_Join_50()
{ classifyJ("{ ?x ?y ?z { ?x1 ?y1 ?z1 MINUS { ?a ?b ?c } } UNION {} }", false) ; }
-
+
// JENA-1280
- @Test public void testClassify_Join_51() {
+ @Test public void testClassify_Join_51() {
String x1 = "{ ?s ?p ?o GRAPH ?g { ?s1 ?p ?o1 FILTER EXISTS { [] ?p ?unique } } }";
TestClassify.classifyJ(x1, true);
}
-
+
// JENA-1167, JENA-1280, JENA-1534
- @Test public void testClassify_Join_52() {
+ @Test public void testClassify_Join_52() {
String x1 = "{ ?s ?p ?V0 GRAPH ?g { ?s1 ?p ?o1 FILTER EXISTS { _:b0 ?p ?V1 } } }";
TestClassify.classifyJ(x1, true);
}
-
+
// JENA-1167, JENA-1280, JENA-1534
- @Test public void testClassify_Join_53() {
+ @Test public void testClassify_Join_53() {
String x1 = "{ ?s ?p ?V GRAPH ?g { ?s1 ?p ?o1 FILTER EXISTS { _:b0 ?p ?V } } }";
TestClassify.classifyJ(x1, false);
}
@@ -164,9 +164,15 @@ public class TestClassify
// JENA-1813
@Test public void testClassify_Join_54() {
String x1 = "{ ?s ?p ?V GRAPH ?g { SELECT (?w AS ?V) { ?t ?q ?w } GROUP BY ?w } }";
- TestClassify.classifyJ(x1, false);
+ TestClassify.classifyJ(x1, false);
+ }
+
+ // JENA-2332
+ @Test public void testClassify_Join_60() {
+ String x1 = "{ ?s ?p ?V SERVICE <test:g> { SELECT (?w AS ?V) { ?t ?q ?w } GROUP BY ?w } }";
+ TestClassify.classifyJ(x1, false);
}
-
+
public static void classifyJ(String pattern, boolean expected)
{
String qs1 = "PREFIX : <http://example/>\n" ;
@@ -181,22 +187,22 @@ public class TestClassify
System.out.println(query);
System.out.println(op);
}
-
+
assertEquals("Join: "+pattern, expected, nonLinear) ;
}
@Test public void testClassify_LeftJoin_01()
{ classifyLJ("{ ?s ?p ?o OPTIONAL { ?s1 ?p2 ?x} }", true) ; }
-
+
@Test public void testClassify_LeftJoin_02()
{ classifyLJ("{ ?s ?p ?o OPTIONAL { ?s1 ?p2 ?o3 OPTIONAL { ?s1 ?p2 ?x} } }", true) ; }
-
+
@Test public void testClassify_LeftJoin_03()
{ classifyLJ("{ ?s ?p ?x OPTIONAL { ?s1 ?p2 ?o3 OPTIONAL { ?s1 :p ?o3} } }", true) ; }
-
+
@Test public void testClassify_LeftJoin_04()
{ classifyLJ("{ ?s ?p ?x OPTIONAL { ?s1 ?p2 ?o3 OPTIONAL { ?s1 :p ?x} } }", false) ; }
-
+
@Test public void testClassify_LeftJoin_05()
{ classifyLJ("{ ?s ?p ?x OPTIONAL { ?s ?p ?x OPTIONAL { ?s ?p ?x } } }", true) ; }
@@ -209,37 +215,37 @@ public class TestClassify
// Can't linearize into a projection.
@Test public void testClassify_LeftJoin_10()
{ classifyLJ("{ ?s ?p ?x OPTIONAL { SELECT ?s { ?s ?p ?o } } }", false) ; }
-
+
/**
* Can linearize with BIND present provided mentioned vars are also on RHS
*/
@Test public void testClassify_LeftJoin_11()
{ classifyLJ("{ ?s ?p ?x OPTIONAL { ?s1 ?p2 ?x . BIND(?x AS ?test) } }", true) ; }
-
+
/**
* Can't linearize with BIND present if any mentioned vars are not on RHS
*/
@Test public void testClassify_LeftJoin_12()
{ classifyLJ("{ ?s ?p ?x OPTIONAL { ?s1 ?p2 ?x . BIND(?s AS ?test) } }", false) ; }
-
+
/**
* Can't linearize with BIND present if any mentioned vars are not on RHS
*/
@Test public void testClassify_LeftJoin_13()
{ classifyLJ("{ ?s ?p ?x OPTIONAL { ?s1 ?p2 ?x . BIND(CONCAT(?s, ?x) AS ?test) } }", false) ; }
-
+
/**
* Can't linearize with BIND present if any mentioned vars are not on RHS
*/
@Test public void testClassify_LeftJoin_14()
{ classifyLJ("{ ?s ?p ?x OPTIONAL { ?s1 ?p2 ?x . BIND(CONCAT(?s1, ?p1, ?p2, ?x) AS ?test) } }", false) ; }
-
+
/**
* Can't linearize with BIND present if any mentioned vars are not fixed on RHS
*/
@Test public void testClassify_LeftJoin_15()
{ classifyLJ("{ ?s ?p ?x OPTIONAL { BIND(?x AS ?test) OPTIONAL { ?x ?p1 ?o1 } } }", false) ; }
-
+
/**
* Test left join classification
* @param pattern WHERE clause for the query as a string
@@ -251,7 +257,7 @@ public class TestClassify
String qs = qs1+"SELECT * "+pattern;
Query query = QueryFactory.create(qs, Syntax.syntaxARQ) ;
Op op = Algebra.compile(query.getQueryPattern()) ;
-
+
if ( ! ( op instanceof OpLeftJoin ) )
fail("Not a leftjoin: "+pattern) ;