jena-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a...@apache.org
Subject svn commit: r1141591 - in /incubator/jena/Jena2/ARQ/trunk: src-dev/dev/DevARQ.java src-dev/reports/ReportFilterEquality.java src/com/hp/hpl/jena/sparql/algebra/optimize/TransformFilterEquality.java src/com/hp/hpl/jena/sparql/expr/ExprVars.java
Date Thu, 30 Jun 2011 16:02:42 GMT
Author: andy
Date: Thu Jun 30 16:02:41 2011
New Revision: 1141591

URL: http://svn.apache.org/viewvc?rev=1141591&view=rev
Log:
JENA-79

Added:
    incubator/jena/Jena2/ARQ/trunk/src-dev/reports/ReportFilterEquality.java   (with props)
Modified:
    incubator/jena/Jena2/ARQ/trunk/src-dev/dev/DevARQ.java
    incubator/jena/Jena2/ARQ/trunk/src/com/hp/hpl/jena/sparql/algebra/optimize/TransformFilterEquality.java
    incubator/jena/Jena2/ARQ/trunk/src/com/hp/hpl/jena/sparql/expr/ExprVars.java

Modified: incubator/jena/Jena2/ARQ/trunk/src-dev/dev/DevARQ.java
URL: http://svn.apache.org/viewvc/incubator/jena/Jena2/ARQ/trunk/src-dev/dev/DevARQ.java?rev=1141591&r1=1141590&r2=1141591&view=diff
==============================================================================
--- incubator/jena/Jena2/ARQ/trunk/src-dev/dev/DevARQ.java (original)
+++ incubator/jena/Jena2/ARQ/trunk/src-dev/dev/DevARQ.java Thu Jun 30 16:02:41 2011
@@ -2,7 +2,9 @@ package dev ;
 
 public class DevARQ
 {
-    // FILTER(?x=?y) optimization - at least FILTER(sameTerm(?x,?y)) 
+    // FILTER(?x=?y) optimization - at least FILTER(sameTerm(?x,?y))
+    // FILTER(?x=<x> && ...) does not push down on the ?x=<x>
+    
     
     // QueryEngineHTTP - content negotiation, Apache httpClient.
     

Added: incubator/jena/Jena2/ARQ/trunk/src-dev/reports/ReportFilterEquality.java
URL: http://svn.apache.org/viewvc/incubator/jena/Jena2/ARQ/trunk/src-dev/reports/ReportFilterEquality.java?rev=1141591&view=auto
==============================================================================
--- incubator/jena/Jena2/ARQ/trunk/src-dev/reports/ReportFilterEquality.java (added)
+++ incubator/jena/Jena2/ARQ/trunk/src-dev/reports/ReportFilterEquality.java Thu Jun 30 16:02:41
2011
@@ -0,0 +1,79 @@
+/*
+ * (c) Copyright 2011 Epimorphics Ltd.
+ * All rights reserved.
+ * [See end of file]
+ */
+
+package reports;
+
+import org.openjena.atlas.lib.StrUtils ;
+
+import com.hp.hpl.jena.graph.Graph ;
+import com.hp.hpl.jena.graph.Triple ;
+import com.hp.hpl.jena.query.Query ;
+import com.hp.hpl.jena.query.QueryExecution ;
+import com.hp.hpl.jena.query.QueryExecutionFactory ;
+import com.hp.hpl.jena.query.QueryFactory ;
+import com.hp.hpl.jena.query.ResultSet ;
+import com.hp.hpl.jena.query.ResultSetFormatter ;
+import com.hp.hpl.jena.rdf.model.Model ;
+import com.hp.hpl.jena.rdf.model.ModelFactory ;
+import com.hp.hpl.jena.sparql.algebra.Algebra ;
+import com.hp.hpl.jena.sparql.algebra.Op ;
+import com.hp.hpl.jena.sparql.sse.SSE ;
+import com.hp.hpl.jena.sparql.util.graph.GraphFactory ;
+
+public class ReportFilterEquality
+{
+    public static void main(String...argv)
+    {
+        String qs = StrUtils.strjoinNL(
+                           "PREFIX ex: <http://example.com/ns#>" ,
+                           "SELECT ?x WHERE {" ,
+                           "    ?s a ?c" ,
+                           "    OPTIONAL { ?s ex:property ?x }" ,
+                           "    FILTER (?c = ex:v)",
+                           "}") ;
+        Query query = QueryFactory.create(qs) ;
+        
+        Op op = Algebra.compile(query) ;
+        Op op2 = Algebra.optimize(op) ;
+        System.out.println(op) ;
+        System.out.println(op2) ;
+        
+        Graph g = GraphFactory.createGraphMem() ;
+        Triple t = SSE.parseTriple("(<x> rdf:type <T>)") ;
+        g.add(t) ;
+        Model m = ModelFactory.createModelForGraph(g) ;
+        QueryExecution qExec = QueryExecutionFactory.create(query, m) ;
+        ResultSet rs = qExec.execSelect() ;
+        ResultSetFormatter.out(rs) ;
+    }
+}
+
+/*
+ * (c) Copyright 2011 Epimorphics Ltd.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. The name of the author may not be used to endorse or promote products
+ *    derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
\ No newline at end of file

Propchange: incubator/jena/Jena2/ARQ/trunk/src-dev/reports/ReportFilterEquality.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: incubator/jena/Jena2/ARQ/trunk/src/com/hp/hpl/jena/sparql/algebra/optimize/TransformFilterEquality.java
URL: http://svn.apache.org/viewvc/incubator/jena/Jena2/ARQ/trunk/src/com/hp/hpl/jena/sparql/algebra/optimize/TransformFilterEquality.java?rev=1141591&r1=1141590&r2=1141591&view=diff
==============================================================================
--- incubator/jena/Jena2/ARQ/trunk/src/com/hp/hpl/jena/sparql/algebra/optimize/TransformFilterEquality.java
(original)
+++ incubator/jena/Jena2/ARQ/trunk/src/com/hp/hpl/jena/sparql/algebra/optimize/TransformFilterEquality.java
Thu Jun 30 16:02:41 2011
@@ -27,6 +27,7 @@ import com.hp.hpl.jena.sparql.expr.Expr 
 import com.hp.hpl.jena.sparql.expr.ExprFunction2 ;
 import com.hp.hpl.jena.sparql.expr.ExprList ;
 import com.hp.hpl.jena.sparql.expr.ExprVar ;
+import com.hp.hpl.jena.sparql.expr.ExprVars ;
 import com.hp.hpl.jena.sparql.expr.NodeValue ;
 
 public class TransformFilterEquality extends TransformCopy
@@ -49,10 +50,11 @@ public class TransformFilterEquality ext
     @Override
     public Op transform(OpFilter opFilter, Op subOp)
     { 
-        if ( ! safeToTransform(subOp) )
+        ExprList exprs = opFilter.getExprs() ;
+
+        if ( ! safeToTransform(exprs, subOp) )
             return super.transform(opFilter, subOp) ;
         
-        ExprList exprs = opFilter.getExprs() ;
         Op op = subOp ;
         // Variables set
         Set<Var> patternVars = OpVars.patternVars(op) ;
@@ -86,15 +88,34 @@ public class TransformFilterEquality ext
         return op2 ;
     }
     
-    private static boolean safeToTransform(Op op)
+    private static boolean safeToTransform(Expr expr, Op op)
+    {
+        return safeToTransform(new ExprList(expr), op) ;
+    }
+    
+    private static boolean safeToTransform(ExprList exprs, Op op)
     {
         if ( op instanceof OpBGP || op instanceof OpQuadPattern ) return true ;
-        if ( op instanceof OpConditional || op instanceof OpSequence ) return true ;
+        if ( op instanceof OpSequence ) return true ;
+
+        // Not safe unless filter is on the RHS. 
+        if ( op instanceof OpConditional )
+        {
+            OpConditional opCond = (OpConditional)op ;
+            Op opLeft = opCond.getLeft() ;
+            
+            Set<Var> x = OpVars.patternVars(opLeft) ;
+            Set<Var> y = ExprVars.getVarsMentioned(exprs) ;
+            if ( x.containsAll(y) )
+                return true ;
+            return false ;
+        }
         
         if ( op instanceof OpGraph )
         {
+            // ???
             OpGraph opg = (OpGraph)op ;
-            return safeToTransform(opg.getSubOp()) ;
+            return safeToTransform(exprs, opg.getSubOp()) ;
         }
         
         return false ;
@@ -104,7 +125,7 @@ public class TransformFilterEquality ext
     /** Return null for "no change" */
     public static Op processFilter(Expr e, Op subOp)
     {
-        if ( ! safeToTransform(subOp) )
+        if ( ! safeToTransform(e, subOp) )
             return null ;
         return processFilterWorker(e, subOp, null) ;
     }

Modified: incubator/jena/Jena2/ARQ/trunk/src/com/hp/hpl/jena/sparql/expr/ExprVars.java
URL: http://svn.apache.org/viewvc/incubator/jena/Jena2/ARQ/trunk/src/com/hp/hpl/jena/sparql/expr/ExprVars.java?rev=1141591&r1=1141590&r2=1141591&view=diff
==============================================================================
--- incubator/jena/Jena2/ARQ/trunk/src/com/hp/hpl/jena/sparql/expr/ExprVars.java (original)
+++ incubator/jena/Jena2/ARQ/trunk/src/com/hp/hpl/jena/sparql/expr/ExprVars.java Thu Jun 30
16:02:41 2011
@@ -23,7 +23,15 @@ public class ExprVars
         varsMentioned(acc, expr) ;
         return acc ;
     }
-    
+
+    public static Set<Var> getVarsMentioned(ExprList exprs)
+    {
+        Set<Var> acc = new HashSet<Var>() ;
+        for ( Expr expr : exprs )
+            varsMentioned(acc, expr) ;    
+        return acc ;
+    }
+
     public static void varsMentioned(Collection<Var> acc, Expr expr)
     {
         ExprVars.Action<Var> action =



Mime
View raw message