jena-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a...@apache.org
Subject jena git commit: JENA-963 : The case of OPTIONAL {{ }}
Date Mon, 22 Jun 2015 21:03:31 GMT
Repository: jena
Updated Branches:
  refs/heads/master 3033e4408 -> c6bf61d90


JENA-963 : The case of OPTIONAL {{ }}

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

Branch: refs/heads/master
Commit: c6bf61d90b8f542d1fa186d045057141a8bf1e13
Parents: 3033e44
Author: Andy Seaborne <andy@apache.org>
Authored: Mon Jun 22 22:03:16 2015 +0100
Committer: Andy Seaborne <andy@apache.org>
Committed: Mon Jun 22 22:03:16 2015 +0100

----------------------------------------------------------------------
 .../apache/jena/sparql/algebra/OpAsQuery.java    | 19 +++++++++++++++++++
 .../jena/sparql/algebra/TestOpAsQuery.java       |  9 ++++++++-
 2 files changed, 27 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/jena/blob/c6bf61d9/jena-arq/src/main/java/org/apache/jena/sparql/algebra/OpAsQuery.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/main/java/org/apache/jena/sparql/algebra/OpAsQuery.java b/jena-arq/src/main/java/org/apache/jena/sparql/algebra/OpAsQuery.java
index 0d8cc1d..6e0c104 100644
--- a/jena-arq/src/main/java/org/apache/jena/sparql/algebra/OpAsQuery.java
+++ b/jena-arq/src/main/java/org/apache/jena/sparql/algebra/OpAsQuery.java
@@ -573,6 +573,25 @@ public class OpAsQuery {
         public void visit(OpLeftJoin opLeftJoin) {
             Element eLeft = asElement(opLeftJoin.getLeft()) ;
             ElementGroup eRight = asElementGroup(opLeftJoin.getRight()) ;
+            
+            // If the RHS is (filter) we need to protect it from becoming
+            // part of the expr for the LeftJoin.
+            // OPTIONAL {{ ?s ?p ?o FILTER (?o>34) }} is not the same as
+            // OPTIONAL { ?s ?p ?o FILTER (?o>34) }
+            
+            boolean mustProtect = false ;
+            for ( Element el : eRight.getElements() ) {
+                if ( el instanceof ElementFilter ) {
+                    mustProtect = true ;
+                    break ;
+                }
+            }
+                
+            if ( mustProtect ) {
+                ElementGroup eRight2 = new ElementGroup() ;
+                eRight2.addElement(eRight);
+                eRight = eRight2 ;
+            }
 
             if ( opLeftJoin.getExprs() != null ) {
                 for ( Expr expr : opLeftJoin.getExprs() ) {

http://git-wip-us.apache.org/repos/asf/jena/blob/c6bf61d9/jena-arq/src/test/java/org/apache/jena/sparql/algebra/TestOpAsQuery.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/test/java/org/apache/jena/sparql/algebra/TestOpAsQuery.java b/jena-arq/src/test/java/org/apache/jena/sparql/algebra/TestOpAsQuery.java
index 671b2ee..2c3fc8b 100644
--- a/jena-arq/src/test/java/org/apache/jena/sparql/algebra/TestOpAsQuery.java
+++ b/jena-arq/src/test/java/org/apache/jena/sparql/algebra/TestOpAsQuery.java
@@ -38,13 +38,20 @@ import org.junit.Test ;
  */
 public class TestOpAsQuery {
 
-    // basic stuff
+    // Basic stuff
     @Test public void testBasic01() { test$RoundTripQuery("SELECT * { }") ; }
     @Test public void testBasic02() { test$RoundTripQuery("SELECT * { ?s ?p ?o }") ; }
     @Test public void testBasic03() { test$RoundTripQuery("SELECT * { ?s ?p ?o FILTER(?o
> 5) }") ; }
     @Test public void testBasic04() { test$RoundTripQuery("SELECT ?s { ?s ?p ?o FILTER(?o
> 5) }") ; }
     @Test public void testBasic05() { test$RoundTripQuery("SELECT ?s (?o + 5 AS ?B) { ?s
?p ?o }") ; }
     
+    @Test public void testOptional01() 
+    { test$RoundTripQuery("SELECT * WHERE { ?s ?p ?o OPTIONAL { ?s ?q ?z FILTER (?foo) }
}") ; }
+    
+    // Double {{...}} matter here in SPARQL.
+    @Test public void testOptional02() 
+    { test$RoundTripQuery("SELECT * WHERE { ?s ?p ?o OPTIONAL { { ?s ?q ?z FILTER (?foo)
} } }") ; }
+    
     /**
      * Test of asQuery method, of class OpAsQuery.
      */


Mime
View raw message