jena-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a...@apache.org
Subject svn commit: r1467700 - in /jena/trunk/jena-arq/src: main/java/com/hp/hpl/jena/sparql/algebra/optimize/ main/java/com/hp/hpl/jena/sparql/engine/main/ test/java/com/hp/hpl/jena/sparql/algebra/
Date Sat, 13 Apr 2013 20:30:21 GMT
Author: andy
Date: Sat Apr 13 20:30:20 2013
New Revision: 1467700

URL: http://svn.apache.org/r1467700
Log:
Fix filter/equlaity transform.
Better join and leftjoin classification for optimzation.

Modified:
    jena/trunk/jena-arq/src/main/java/com/hp/hpl/jena/sparql/algebra/optimize/TransformFilterEquality.java
    jena/trunk/jena-arq/src/main/java/com/hp/hpl/jena/sparql/engine/main/JoinClassifier.java
    jena/trunk/jena-arq/src/main/java/com/hp/hpl/jena/sparql/engine/main/LeftJoinClassifier.java
    jena/trunk/jena-arq/src/test/java/com/hp/hpl/jena/sparql/algebra/TestClassify.java

Modified: jena/trunk/jena-arq/src/main/java/com/hp/hpl/jena/sparql/algebra/optimize/TransformFilterEquality.java
URL: http://svn.apache.org/viewvc/jena/trunk/jena-arq/src/main/java/com/hp/hpl/jena/sparql/algebra/optimize/TransformFilterEquality.java?rev=1467700&r1=1467699&r2=1467700&view=diff
==============================================================================
--- jena/trunk/jena-arq/src/main/java/com/hp/hpl/jena/sparql/algebra/optimize/TransformFilterEquality.java
(original)
+++ jena/trunk/jena-arq/src/main/java/com/hp/hpl/jena/sparql/algebra/optimize/TransformFilterEquality.java
Sat Apr 13 20:30:20 2013
@@ -18,12 +18,13 @@
 
 package com.hp.hpl.jena.sparql.algebra.optimize;
 
+import static org.apache.jena.atlas.lib.CollectionUtils.disjoint ;
+
 import java.util.ArrayList ;
 import java.util.Collection ;
 import java.util.List ;
 import java.util.Set ;
 
-import static org.apache.jena.atlas.lib.CollectionUtils.disjoint ;
 import org.apache.jena.atlas.lib.Pair ;
 
 import com.hp.hpl.jena.query.ARQ ;
@@ -33,6 +34,7 @@ import com.hp.hpl.jena.sparql.algebra.Tr
 import com.hp.hpl.jena.sparql.algebra.op.* ;
 import com.hp.hpl.jena.sparql.core.Substitute ;
 import com.hp.hpl.jena.sparql.core.Var ;
+import com.hp.hpl.jena.sparql.core.VarExprList ;
 import com.hp.hpl.jena.sparql.expr.* ;
 
 public class TransformFilterEquality extends TransformCopy
@@ -174,16 +176,17 @@ public class TransformFilterEquality ext
 
     private static boolean safeToTransform(Collection<Var> varsEquality, Op op)
     {
+        // Structure as a visitor?
         if ( op instanceof OpBGP || op instanceof OpQuadPattern )
             return true ;
         
         if ( op instanceof OpFilter )
         {
             OpFilter opf = (OpFilter)op ;
-            
-            Collection<Var> fvars = opf.getExprs().getVarsMentioned() ;
-            if ( ! disjoint(fvars, varsEquality) )
-                return false ;
+            // Expressions are always safe transform by substitution.
+//            Collection<Var> fvars = opf.getExprs().getVarsMentioned() ;
+//            if ( ! disjoint(fvars, varsEquality) )
+//                return false ;
             return safeToTransform(varsEquality, opf.getSubOp()) ;
         }
         
@@ -224,7 +227,7 @@ public class TransformFilterEquality ext
             // Needs more investigation.
             
             Op opLeft = opleftjoin.getLeft() ;
-            Set<Var> varsLeft = OpVars.patternVars(opLeft) ;
+            Set<Var> varsLeft = OpVars.visibleVars(opLeft) ;
             if ( varsLeft.containsAll(varsEquality) )
                 return true ;
             return false ;
@@ -236,17 +239,56 @@ public class TransformFilterEquality ext
             return safeToTransform(varsEquality, opg.getSubOp()) ;
         }
         
+        // Subquery - assume scope rewriting has already been applied.  
+        if ( op instanceof OpModifier )
+        {
+            // ORDER BY?
+            OpModifier opMod = (OpModifier)op ;
+            if ( opMod instanceof OpProject )
+            {
+                OpProject opProject = (OpProject)op ;
+                // Writing "SELECT ?var" for "?var" -> a value would need AS-ification.
+                for ( Var v : opProject.getVars() )
+                {
+                    if ( varsEquality.contains(v) )
+                        return false ;
+                }
+            }
+            return safeToTransform(varsEquality, opMod.getSubOp()) ;
+        }
+                
+        if ( op instanceof OpGroup )
+        {
+            OpGroup opGroup = (OpGroup)op ;
+            VarExprList varExprList = opGroup.getGroupVars() ;
+            return safeToTransform(varsEquality, varExprList) && 
+                   safeToTransform(varsEquality, opGroup.getSubOp()) ;
+        }
+
+        // Op1 - OpGroup
+        // Op1 - OpOrder
+        // Op1 - OpAssign, OpExtend
+        // Op1 - OpFilter - done.
+        // Op1 - OpLabel - easy
+        // Op1 - OpService - no.
+        
         return false ;
     }
     
+    private static boolean safeToTransform(Collection<Var> varsEquality, VarExprList
varsExprList)
+    {
+        // If the named variable is used, unsafe to rewrite.
+        return disjoint(varsExprList.getVars(), varsEquality) ;
+    }
+    
     // -- A special case
 
     private static boolean testSpecialCaseUnused(Op op, List<Pair<Var, NodeValue>>
equalities, ExprList remaining)
     {
         // If the op does not contain the var at all, for some equality
-        // then the filter expression wil/ be "eval unbound" i.e. false.
+        // then the filter expression will be "eval unbound" i.e. false.
         // We can return empty table.
-        Set<Var> patternVars = OpVars.patternVars(op) ;
+        Set<Var> patternVars = OpVars.visibleVars(op) ;
         for ( Pair<Var, NodeValue> p : equalities )
         {
             if ( ! patternVars.contains(p.getLeft()))

Modified: jena/trunk/jena-arq/src/main/java/com/hp/hpl/jena/sparql/engine/main/JoinClassifier.java
URL: http://svn.apache.org/viewvc/jena/trunk/jena-arq/src/main/java/com/hp/hpl/jena/sparql/engine/main/JoinClassifier.java?rev=1467700&r1=1467699&r2=1467700&view=diff
==============================================================================
--- jena/trunk/jena-arq/src/main/java/com/hp/hpl/jena/sparql/engine/main/JoinClassifier.java
(original)
+++ jena/trunk/jena-arq/src/main/java/com/hp/hpl/jena/sparql/engine/main/JoinClassifier.java
Sat Apr 13 20:30:20 2013
@@ -23,11 +23,7 @@ import java.util.Set ;
 import org.apache.jena.atlas.lib.SetUtils ;
 
 import com.hp.hpl.jena.sparql.algebra.Op ;
-import com.hp.hpl.jena.sparql.algebra.op.OpDiff ;
-import com.hp.hpl.jena.sparql.algebra.op.OpExt ;
-import com.hp.hpl.jena.sparql.algebra.op.OpJoin ;
-import com.hp.hpl.jena.sparql.algebra.op.OpMinus ;
-import com.hp.hpl.jena.sparql.algebra.op.OpModifier ;
+import com.hp.hpl.jena.sparql.algebra.op.* ;
 import com.hp.hpl.jena.sparql.core.Var ;
 
 public class JoinClassifier
@@ -44,11 +40,7 @@ public class JoinClassifier
     {
         left = effectiveOp(left) ;
         right = effectiveOp(right) ;
-
-        // Old: Subquery with modifier. Substitution does not apply.
-        // Renaming should make this work.
-        // With SELECT *, it's as if the subquery were just the pattern.
-
+        
         if (right instanceof OpModifier) return false ;
         if (right instanceof OpDiff) return false ;
         if (right instanceof OpMinus) return false ;

Modified: jena/trunk/jena-arq/src/main/java/com/hp/hpl/jena/sparql/engine/main/LeftJoinClassifier.java
URL: http://svn.apache.org/viewvc/jena/trunk/jena-arq/src/main/java/com/hp/hpl/jena/sparql/engine/main/LeftJoinClassifier.java?rev=1467700&r1=1467699&r2=1467700&view=diff
==============================================================================
--- jena/trunk/jena-arq/src/main/java/com/hp/hpl/jena/sparql/engine/main/LeftJoinClassifier.java
(original)
+++ jena/trunk/jena-arq/src/main/java/com/hp/hpl/jena/sparql/engine/main/LeftJoinClassifier.java
Sat Apr 13 20:30:20 2013
@@ -58,8 +58,7 @@ public class LeftJoinClassifier
         if ( right instanceof OpModifier )
             return false ;
         
-        Set<Var> leftVars = OpVars.patternVars(left) ;
-        
+        Set<Var> leftVars = OpVars.visibleVars(left) ;
         VarFinder vf = new VarFinder(right) ;
         
         Set<Var> optRight = vf.getOpt() ;
@@ -77,7 +76,7 @@ public class LeftJoinClassifier
     {
         Op left = JoinClassifier.effectiveOp(op.getLeft()) ;
         Op right = JoinClassifier.effectiveOp(op.getRight()) ;
-        Set<Var> leftVars = OpVars.patternVars(left) ;
+        Set<Var> leftVars = OpVars.visibleVars(left) ;
         Set<Var> optRight = VarFinder.optDefined(right) ;
 
         return SetUtils.intersection(leftVars, optRight) ;

Modified: jena/trunk/jena-arq/src/test/java/com/hp/hpl/jena/sparql/algebra/TestClassify.java
URL: http://svn.apache.org/viewvc/jena/trunk/jena-arq/src/test/java/com/hp/hpl/jena/sparql/algebra/TestClassify.java?rev=1467700&r1=1467699&r2=1467700&view=diff
==============================================================================
--- jena/trunk/jena-arq/src/test/java/com/hp/hpl/jena/sparql/algebra/TestClassify.java (original)
+++ jena/trunk/jena-arq/src/test/java/com/hp/hpl/jena/sparql/algebra/TestClassify.java Sat
Apr 13 20:30:20 2013
@@ -99,11 +99,7 @@ public class TestClassify extends TestCa
     @Test public void testClassify_Join_21() 
     { classifyJ("{ { {} OPTIONAL { :s :p ?x } } {?s :p ?x } }", true) ; }
 
-    // Not a join by adjacent BGP flattening. 
-//    @Test public void testClassify_Join_30() 
-//    { classifyJ("{ ?x ?y ?z {SELECT * { ?s ?p ?o} } }", true) ; }
-    
-    // Subselect with modifier is handled without linearization
+    // Will become true.
     @Test public void testClassify_Join_31() 
     { classifyJ("{ ?x ?y ?z {SELECT ?s { ?s ?p ?o} } }", false) ; }
 
@@ -170,6 +166,7 @@ public class TestClassify extends TestCa
     @Test public void testClassify_LeftJoin_07()
     { classifyLJ("{ ?s ?p ?x OPTIONAL { ?s ?p ?x1 OPTIONAL { ?s ?p ?x2 FILTER(?x) } } }",
false)  ; }
 
+    // Can't lineraize into a projection.
     @Test public void testClassify_LeftJoin_10()
     { classifyLJ("{ ?s ?p ?x OPTIONAL { SELECT ?s { ?s ?p ?o } } }", false)  ; }
         



Mime
View raw message