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 2013/04/17 16:08:40 UTC

svn commit: r1468922 - /jena/Scratch/AFS/Jena-Dev/trunk/src/dev/JenaNNN_FilterEquality.java

Author: andy
Date: Wed Apr 17 14:08:39 2013
New Revision: 1468922

URL: http://svn.apache.org/r1468922
Log:
dev sync

Modified:
    jena/Scratch/AFS/Jena-Dev/trunk/src/dev/JenaNNN_FilterEquality.java

Modified: jena/Scratch/AFS/Jena-Dev/trunk/src/dev/JenaNNN_FilterEquality.java
URL: http://svn.apache.org/viewvc/jena/Scratch/AFS/Jena-Dev/trunk/src/dev/JenaNNN_FilterEquality.java?rev=1468922&r1=1468921&r2=1468922&view=diff
==============================================================================
--- jena/Scratch/AFS/Jena-Dev/trunk/src/dev/JenaNNN_FilterEquality.java (original)
+++ jena/Scratch/AFS/Jena-Dev/trunk/src/dev/JenaNNN_FilterEquality.java Wed Apr 17 14:08:39 2013
@@ -39,18 +39,19 @@ public class JenaNNN_FilterEquality
     // remove assignment from projection?
     // No need! It's going to be a no-op!
     
-    // JENA-432 : Filter optimization messes up when a nested select is present in the same block
+    // [DONE] JENA-432 : Filter optimization messes up when a nested select is present in the same block
     // JENA-383 : The query optimizer generates a suboptimal query plan in case of nested optionals followed by a filter
-    // JENA-294 : TransformFilterEquality does not handle starting OPTIONAL well
+    // [DONE] JENA-294 : TransformFilterEquality does not handle starting OPTIONAL well
 
     // Unrelated
     // JENA-293 : Allow the filter placement optimziation to push FILTER though BIND.
+    //    Filter push throughs.
     // JENA-384 : SubstitueFilterOptimize :: Interaction of optimization (TransformFilterEquality) and initial binding
 
     
     public static void main(String... args) throws Exception 
     {
-        // Scoping.
+        // Scoping. Unsafe unless FILTER push down done.
         String qs1 = StrUtils.strjoinNL
             ( "PREFIX : <http://example/> SELECT * {"
               , "    OPTIONAL { ?x :q ?o }"
@@ -60,7 +61,7 @@ public class JenaNNN_FilterEquality
                 ) ;
         
 
-        // Scoping issues : works
+        // Scoping issues : safe to xform
         String qs2 = StrUtils.strjoinNL
             ( "PREFIX : <http://example/> SELECT * {"
               , "    ?x :p ?o2"
@@ -69,16 +70,20 @@ public class JenaNNN_FilterEquality
               , "}"
                 ) ;
 
-        // Scoping issues : unsafe works
+        // JENA-383
         String qs3 = StrUtils.strjoinNL
-            ( "PREFIX : <http://example/> SELECT * {"
-              , "    ?z :p ?o2"              
-              , "    OPTIONAL { ?x :q ?o }"     // ?x is optional.
-              , "    FILTER(?x = :x)"
-              , "}"
-                ) ;
-
-        String[] x = { qs1 } ;
+            ( "PREFIX ex: <http://example.org/test#>"
+            , "SELECT * {"
+            , "    ?var ex:p1 ?x."
+            , "    OPTIONAL {"
+            , "        ?x ex:p2 ?y."
+            , "        OPTIONAL { ?y ex:p3 ?z }"
+            , "    }"
+            , "    FILTER (?var = ex:i)"
+            , " }"
+            ) ;
+        
+        String[] x = { qs3 } ;
         for ( String qs : x )
         {
             Query query = QueryFactory.create(qs) ;
@@ -110,108 +115,108 @@ public class JenaNNN_FilterEquality
     private Transform t_placement   = new TransformFilterPlacement() ;
     private Transform t_expandOneOf = new TransformExpandOneOf() ;
     
-    // Scope of variable (optional, defined) cases 
-    // Related to JENA-294 part II
-    // Trailing fixed BGP. 
-    @Test public void test_OptEqualityScope_01() {
-        String qs = StrUtils.strjoinNL
-            ( "PREFIX : <http://example/> SELECT * {"
-              , "    OPTIONAL { ?x :q ?o }"
-              , "    FILTER(?x = :x)"
-              , "    ?x :p ?o2"
-              , "}"
-                ) ;
-        // Possible transformation:
-        // Safe to transform:  This (sequence) always defined ?x 
-        String ops = StrUtils.strjoinNL
-            ("(assign ((?x <http://example/x>))"
-            , "   (sequence"
-            , "       (conditional"
-            , "         (table unit)"
-            , "         (bgp (triple <http://example/x> <http://example/q> ?o)))"
-            , "       (bgp (triple <http://example/x> <http://example/p> ?o2))))"
-            ) ;
-        // Currently :
-        String ops1 = StrUtils.strjoinNL
-            ("(filter (= ?x <http://example/x>)"
-            ,"  (sequence"
-            ,"    (conditional"
-            ,"      (table unit)"
-            ,"      (bgp (triple ?x <http://example/q> ?o)) )"
-            ,"    (bgp (triple ?x <http://example/p> ?o2)) ))"
-            ) ;
-        
-        check(qs, ops1) ;
-    }
-
-    // JENA-294 part II
-    @Test public void test_OptEqualityScope_02() {
-        String qs = StrUtils.strjoinNL
-            ( "PREFIX : <http://example/> SELECT * {"
-              , "    ?x :p ?o2"
-              , "    OPTIONAL { ?x :q ?o }"
-              , "    FILTER(?x = :x)"
-              , "}"
-                ) ;
-        // Safe to transform:  ?x is fixed. 
-        String ops = StrUtils.strjoinNL
-            ( "(assign ((?x <http://example/x>))"
-            , "   (conditional"
-            , "     (bgp (triple <http://example/x> <http://example/p> ?o2))"
-            , "     (bgp (triple <http://example/x> <http://example/q> ?o))"
-            , "   ))"
-            ) ;
-        check(qs, ops) ;
-    }
-    
-    // JENA-294 part II
-    @Test public void test_OptEqualityScope_03() {
-        String qs = StrUtils.strjoinNL
-            ( "PREFIX : <http://example/> SELECT * {"
-              , "    ?z :p ?o2"
-              , "    OPTIONAL { ?x :q ?o }"
-              , "    FILTER(?x = :x)"
-              , "}"
-                ) ;
-        // Unsafe to transform:  ?x is optional. 
-        String ops = StrUtils.strjoinNL
-            ( "(filter (= ?x <http://example/x>)"
-            , "   (conditional"
-            , "     (bgp (triple ?z <http://example/p> ?o2))"
-            , "     (bgp (triple ?x <http://example/q> ?o))"
-            , "))"
-            ) ;
-        check(qs, ops) ;
-    }
-
-    // Scope of variable (optional, defined) cases 
-    @Test public void test_OptEqualityScope_04() {
-        String qs = StrUtils.strjoinNL
-            ( "PREFIX : <http://example/> SELECT * {"
-              , "    OPTIONAL { ?x :q ?o }"
-              , "    FILTER(?x = :x)"
-              , "}"
-                ) ;
-        // Unsafe to transform:  This may not defined ?x, then FILTER -> unbound -> error -> false
-        // But push down possible.
-        String ops = StrUtils.strjoinNL
-            ("(assign ((?x <http://example/x>))"
-            , "   (sequence"
-            , "       (conditional"
-            , "         (table unit)"
-            , "         (bgp (triple <http://example/x> <http://example/q> ?o)))"
-            , "       (bgp (triple <http://example/x> <http://example/p> ?o2))))"
-            ) ;
-        String ops1 = StrUtils.strjoinNL
-            ("(filter (= ?x <http://example/x>)"
-            ,"    (conditional"
-            ,"      (table unit)"
-            ,"      (assign ((?x <http://example/x>))"
-            ,"        (bgp (triple <http://example/x> <http://example/q> ?o)))))"
-            ) ;
-        
-        check(qs, ops1) ;
-    }
+//    // Scope of variable (optional, defined) cases 
+//    // Related to JENA-294 part II
+//    // Trailing fixed BGP. 
+//    @Test public void test_OptEqualityScope_01() {
+//        String qs = StrUtils.strjoinNL
+//            ( "PREFIX : <http://example/> SELECT * {"
+//              , "    OPTIONAL { ?x :q ?o }"
+//              , "    FILTER(?x = :x)"
+//              , "    ?x :p ?o2"
+//              , "}"
+//                ) ;
+//        // Possible transformation:
+//        // Safe to transform:  This (sequence) always defined ?x 
+//        String ops = StrUtils.strjoinNL
+//            ("(assign ((?x <http://example/x>))"
+//            , "   (sequence"
+//            , "       (conditional"
+//            , "         (table unit)"
+//            , "         (bgp (triple <http://example/x> <http://example/q> ?o)))"
+//            , "       (bgp (triple <http://example/x> <http://example/p> ?o2))))"
+//            ) ;
+//        // Currently :
+//        String ops1 = StrUtils.strjoinNL
+//            ("(filter (= ?x <http://example/x>)"
+//            ,"  (sequence"
+//            ,"    (conditional"
+//            ,"      (table unit)"
+//            ,"      (bgp (triple ?x <http://example/q> ?o)) )"
+//            ,"    (bgp (triple ?x <http://example/p> ?o2)) ))"
+//            ) ;
+//        
+//        check(qs, ops1) ;
+//    }
+//
+//    // JENA-294 part II
+//    @Test public void test_OptEqualityScope_02() {
+//        String qs = StrUtils.strjoinNL
+//            ( "PREFIX : <http://example/> SELECT * {"
+//              , "    ?x :p ?o2"
+//              , "    OPTIONAL { ?x :q ?o }"
+//              , "    FILTER(?x = :x)"
+//              , "}"
+//                ) ;
+//        // Safe to transform:  ?x is fixed. 
+//        String ops = StrUtils.strjoinNL
+//            ( "(assign ((?x <http://example/x>))"
+//            , "   (conditional"
+//            , "     (bgp (triple <http://example/x> <http://example/p> ?o2))"
+//            , "     (bgp (triple <http://example/x> <http://example/q> ?o))"
+//            , "   ))"
+//            ) ;
+//        check(qs, ops) ;
+//    }
+//    
+//    // JENA-294 part II
+//    @Test public void test_OptEqualityScope_03() {
+//        String qs = StrUtils.strjoinNL
+//            ( "PREFIX : <http://example/> SELECT * {"
+//              , "    ?z :p ?o2"
+//              , "    OPTIONAL { ?x :q ?o }"
+//              , "    FILTER(?x = :x)"
+//              , "}"
+//                ) ;
+//        // Unsafe to transform:  ?x is optional. 
+//        String ops = StrUtils.strjoinNL
+//            ( "(filter (= ?x <http://example/x>)"
+//            , "   (conditional"
+//            , "     (bgp (triple ?z <http://example/p> ?o2))"
+//            , "     (bgp (triple ?x <http://example/q> ?o))"
+//            , "))"
+//            ) ;
+//        check(qs, ops) ;
+//    }
+//
+//    // Scope of variable (optional, defined) cases 
+//    @Test public void test_OptEqualityScope_04() {
+//        String qs = StrUtils.strjoinNL
+//            ( "PREFIX : <http://example/> SELECT * {"
+//              , "    OPTIONAL { ?x :q ?o }"
+//              , "    FILTER(?x = :x)"
+//              , "}"
+//                ) ;
+//        // Unsafe to transform:  This may not defined ?x, then FILTER -> unbound -> error -> false
+//        // But push down possible.
+//        String ops = StrUtils.strjoinNL
+//            ("(assign ((?x <http://example/x>))"
+//            , "   (sequence"
+//            , "       (conditional"
+//            , "         (table unit)"
+//            , "         (bgp (triple <http://example/x> <http://example/q> ?o)))"
+//            , "       (bgp (triple <http://example/x> <http://example/p> ?o2))))"
+//            ) ;
+//        String ops1 = StrUtils.strjoinNL
+//            ("(filter (= ?x <http://example/x>)"
+//            ,"    (conditional"
+//            ,"      (table unit)"
+//            ,"      (assign ((?x <http://example/x>))"
+//            ,"        (bgp (triple <http://example/x> <http://example/q> ?o)))))"
+//            ) ;
+//        
+//        check(qs, ops1) ;
+//    }
     
     // JENA-383
     @Test public void test_OptEqualityScopingNested() {
@@ -240,144 +245,142 @@ public class JenaNNN_FilterEquality
     }
 
     
-    // JENA-432
-    @Test public void test_OptEqualitySubQuery_01() {
-        String qs = StrUtils.strjoinNL
-            ( "SELECT * {"
-            ,  "  ?test ?p1 ?o1."
-            ,  "  FILTER ( ?test = <http://localhost/t1> || ?test = <http://localhost/t2> )"
-            ,  "  OPTIONAL {"
-            ,  "    SELECT ?s1"
-            ,  "    { ?s1 ?p2 ?o2 }"
-            ,  "  }"
-            ,  "}" ) ;
-        String ops = StrUtils.strjoinNL
-            ( "(disjunction"
-            , "  (assign ((?test <http://localhost/t1>))"
-            , "      (conditional"
-            , "          (bgp (triple <http://localhost/t1> ?p1 ?o1))"
-            , "          (project (?s1)"
-            , "            (bgp (triple ?s1 ?/p2 ?/o2)))))"
-            , "      (assign ((?test <http://localhost/t2>))"
-            , "        (conditional"
-            , "          (bgp (triple <http://localhost/t2> ?p1 ?o1))"
-            , "          (project (?s1)"
-            , "            (bgp (triple ?s1 ?/p2 ?/o2))))))"
-            ) ;
-        String ops1 = StrUtils.strjoinNL
-            ( "(disjunction"
-            , "  (assign ((?test <http://localhost/t1>))"
-            , "      (leftjoin"
-            , "          (bgp (triple <http://localhost/t1> ?p1 ?o1))"
-            , "          (project (?s1)"
-            , "            (bgp (triple ?s1 ?/p2 ?/o2)))))"
-            , "      (assign ((?test <http://localhost/t2>))"
-            , "        (leftjoin"
-            , "          (bgp (triple <http://localhost/t2> ?p1 ?o1))"
-            , "          (project (?s1)"
-            , "            (bgp (triple ?s1 ?/p2 ?/o2))))))"
-            ) ;
-
-        check(qs, ops1) ;
-    }
-    
-    @Test public void test_OptSubQuery_01() {
-        String qs = StrUtils.strjoinNL
-            ( "SELECT *"
-            , "WHERE {"
-            , "    ?test ?p1 ?X." 
-            , "    { SELECT ?s1 ?test { ?test ?p2 ?o2 } }"
-            , "}") ; 
-        
-        String ops = StrUtils.strjoinNL
-            ("(sequence"
-            ,"  (bgp (triple ?test ?p1 ?X))"
-            ,"  (project (?s1 ?test)"
-            ,"    (bgp (triple ?test ?/p2 ?/o2))))"
-            ) ;
-        check(qs, ops) ;
-    }
-
-    @Test public void test_OptSubQuery_02() {
-        String qs = StrUtils.strjoinNL
-            ( "SELECT *"
-            , "WHERE {"
-            , "    ?test ?p1 ?X." 
-            , "    { SELECT ?s1 { ?test ?p2 ?o2 } }"
-            , "}") ; 
-        
-        String ops = StrUtils.strjoinNL
-            ("(sequence"
-            ,"  (bgp (triple ?test ?p1 ?X))"
-            ,"  (project (?s1)"
-            ,"    (bgp (triple ?test ?/p2 ?/o2))))"
-            ) ;
-        check(qs, ops) ;
-    }
-
-    // JENA-432
-    @Test public void test_OptEqualitySubQuery_03() {
-        String qs = StrUtils.strjoinNL
-            ( "SELECT *"
-            , "WHERE {"
-            , "    ?test ?p1 ?X." 
-            , "    FILTER ( ?test = <http://localhost/t1> )"
-            , "    { SELECT ?s1 ?test { ?test ?p2 ?o2 } }"
-            , "}") ; 
-        
-        String ops = StrUtils.strjoinNL
-            ("(filter (= ?test <http://localhost/t1>)"
-            ,"    (join"
-            ,"      (bgp (triple ?test ?p1 ?X))"
-            ,"      (project (?s1 ?test)"
-            ,"        (bgp (triple ?test ?/p2 ?/o2)))))"
-            ) ;
-        check(qs, ops) ;
-    }
-    
-    // JENA-432
-    @Test public void test_OptEqualitySubQuery_04() {
-        String qs = StrUtils.strjoinNL
-            ( "SELECT *"
-            , "WHERE {"
-            , "    ?test ?p1 ?X." 
-            , "    FILTER ( ?test = <http://localhost/t1> )"
-            , "    { SELECT ?s1 { ?test ?p2 ?o2 } }"
-            , "}") ;
-        String ops = StrUtils.strjoinNL
-            ( "  (assign ((?test <http://localhost/t1>))"
-            , "    (join"
-            , "       (bgp (triple <http://localhost/t1> ?p1 ?X))"
-            , "       (project (?s1)"
-            , "         (bgp (triple ?/test ?/p2 ?/o2))) ))"
-            ) ;
-        
-        check(qs, ops) ;
-    }
-    
-
-    
-    // JENA-383, simplified.
-    @Test public void test_OptEqualitySubQuery_05() {
-        String qs = StrUtils.strjoinNL
-            ( "PREFIX : <http://example/> SELECT * {"
-              , "    OPTIONAL { ?x :q ?o }"
-              , "    FILTER(?x = :x)"
-              , "    ?x :p ?o2"
-              , "}"
-                ) ;
-        String ops = StrUtils.strjoinNL
-            ( "(filter (= ?x <http://example/x>)"
-            , "  (sequence"
-            , "     (conditional"
-            , "        (table unit)"
-            , "        (bgp (triple ?x <http://example/q> ?o)))"
-            , "     (bgp (triple ?x <http://example/p> ?o2))"
-            , " ))" 
-            ) ;
-        check(qs, ops) ;
-    }
-
+//    // JENA-432 - Full
+//    @Test public void test_OptEqualitySubQuery_01() {
+//        String qs = StrUtils.strjoinNL
+//            ( "SELECT * {"
+//            ,  "  ?test ?p1 ?o1."
+//            ,  "  FILTER ( ?test = <http://localhost/t1> || ?test = <http://localhost/t2> )"
+//            ,  "  OPTIONAL {"
+//            ,  "    SELECT ?s1"
+//            ,  "    { ?s1 ?p2 ?o2 }"
+//            ,  "  }"
+//            ,  "}" ) ;
+//        String ops = StrUtils.strjoinNL
+//            ( "(disjunction"
+//            , "  (assign ((?test <http://localhost/t1>))"
+//            , "      (conditional"
+//            , "          (bgp (triple <http://localhost/t1> ?p1 ?o1))"
+//            , "          (project (?s1)"
+//            , "            (bgp (triple ?s1 ?/p2 ?/o2)))))"
+//            , "      (assign ((?test <http://localhost/t2>))"
+//            , "        (conditional"
+//            , "          (bgp (triple <http://localhost/t2> ?p1 ?o1))"
+//            , "          (project (?s1)"
+//            , "            (bgp (triple ?s1 ?/p2 ?/o2))))))"
+//            ) ;
+//        String ops1 = StrUtils.strjoinNL
+//            ( "(disjunction"
+//            , "  (assign ((?test <http://localhost/t1>))"
+//            , "      (leftjoin"
+//            , "          (bgp (triple <http://localhost/t1> ?p1 ?o1))"
+//            , "          (project (?s1)"
+//            , "            (bgp (triple ?s1 ?/p2 ?/o2)))))"
+//            , "      (assign ((?test <http://localhost/t2>))"
+//            , "        (leftjoin"
+//            , "          (bgp (triple <http://localhost/t2> ?p1 ?o1))"
+//            , "          (project (?s1)"
+//            , "            (bgp (triple ?s1 ?/p2 ?/o2))))))"
+//            ) ;
+//
+//        check(qs, ops1) ;
+//    }
+    
+//    @Test public void test_OptSubQuery_01() {
+//        String qs = StrUtils.strjoinNL
+//            ( "SELECT *"
+//            , "WHERE {"
+//            , "    ?test ?p1 ?X." 
+//            , "    { SELECT ?s1 ?test { ?test ?p2 ?o2 } }"
+//            , "}") ; 
+//        
+//        String ops = StrUtils.strjoinNL
+//            ("(sequence"
+//            ,"  (bgp (triple ?test ?p1 ?X))"
+//            ,"  (project (?s1 ?test)"
+//            ,"    (bgp (triple ?test ?/p2 ?/o2))))"
+//            ) ;
+//        check(qs, ops) ;
+//    }
+//
+//    @Test public void test_OptSubQuery_02() {
+//        String qs = StrUtils.strjoinNL
+//            ( "SELECT *"
+//            , "WHERE {"
+//            , "    ?test ?p1 ?X." 
+//            , "    { SELECT ?s1 { ?test ?p2 ?o2 } }"
+//            , "}") ; 
+//        
+//        String ops = StrUtils.strjoinNL
+//            ("(sequence"
+//            ,"  (bgp (triple ?test ?p1 ?X))"
+//            ,"  (project (?s1)"
+//            ,"    (bgp (triple ?/test ?/p2 ?/o2))))"
+//            ) ;
+//        check(qs, ops) ;
+//    }
+
+//    // Related to JENA-432
+//    @Test public void test_OptEqualitySubQuery_03() {
+//        String qs = StrUtils.strjoinNL
+//            ( "SELECT *"
+//            , "WHERE {"
+//            , "    ?test ?p1 ?X." 
+//            , "    FILTER ( ?test = <http://localhost/t1> )"
+//            , "    { SELECT ?s1 ?test { ?test ?p2 ?o2 } }"
+//            , "}") ; 
+//        
+//        String ops = StrUtils.strjoinNL
+//            ("(filter (= ?test <http://localhost/t1>)"
+//            ,"    (sequence"
+//            ,"      (bgp (triple ?test ?p1 ?X))"
+//            ,"      (project (?s1 ?test)"
+//            ,"        (bgp (triple ?test ?/p2 ?/o2)))))"
+//            ) ;
+//        check(qs, ops) ;
+//    }
+//    
+//    // Related to JENA-432
+//    @Test public void test_OptEqualitySubQuery_04() {
+//        String qs = StrUtils.strjoinNL
+//            ( "SELECT *"
+//            , "WHERE {"
+//            , "    ?test ?p1 ?X." 
+//            , "    FILTER ( ?test = <http://localhost/t1> )"
+//            , "    { SELECT ?s1 { ?test ?p2 ?o2 } }"
+//            , "}") ;
+//        String ops = StrUtils.strjoinNL
+//            ( "  (assign ((?test <http://localhost/t1>))"
+//            , "    (sequence"
+//            , "       (bgp (triple <http://localhost/t1> ?p1 ?X))"
+//            , "       (project (?s1)"
+//            , "         (bgp (triple ?/test ?/p2 ?/o2))) ))"
+//            ) ;
+//        
+//        check(qs, ops) ;
+//    }
+//    
+//    // JENA-383, simplified.
+//    @Test public void test_OptEqualitySubQuery_05() {
+//        String qs = StrUtils.strjoinNL
+//            ( "PREFIX : <http://example/> SELECT * {"
+//              , "    OPTIONAL { ?x :q ?o }"
+//              , "    FILTER(?x = :x)"
+//              , "    ?x :p ?o2"
+//              , "}"
+//                ) ;
+//        String ops = StrUtils.strjoinNL
+//            ( "(filter (= ?x <http://example/x>)"
+//            , "  (sequence"
+//            , "     (conditional"
+//            , "        (table unit)"
+//            , "        (bgp (triple ?x <http://example/q> ?o)))"
+//            , "     (bgp (triple ?x <http://example/p> ?o2))"
+//            , " ))" 
+//            ) ;
+//        check(qs, ops) ;
+//    }
+//