jena-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a...@apache.org
Subject [2/5] jena git commit: JENA-1049: Implement remaining Ops
Date Sat, 03 Oct 2015 17:11:56 GMT
JENA-1049: Implement remaining Ops

Because of inner selects, all optimziation ops can also be present in
the form being classified, and hence passed to VarFinder.

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

Branch: refs/heads/master
Commit: 4dbae033d54c15c12a9ce389ff20ec097e8416ef
Parents: 4c9cda4
Author: Andy Seaborne <andy@apache.org>
Authored: Sat Oct 3 10:33:59 2015 +0100
Committer: Andy Seaborne <andy@apache.org>
Committed: Sat Oct 3 10:33:59 2015 +0100

----------------------------------------------------------------------
 .../jena/sparql/engine/main/VarFinder.java      | 44 ++++++++++--------
 .../sparql/algebra/optimize/TestOptimizer.java  | 49 +++++++++++++++++++-
 2 files changed, 71 insertions(+), 22 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/jena/blob/4dbae033/jena-arq/src/main/java/org/apache/jena/sparql/engine/main/VarFinder.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/main/java/org/apache/jena/sparql/engine/main/VarFinder.java b/jena-arq/src/main/java/org/apache/jena/sparql/engine/main/VarFinder.java
index 9e60fae..a65b73c 100644
--- a/jena-arq/src/main/java/org/apache/jena/sparql/engine/main/VarFinder.java
+++ b/jena-arq/src/main/java/org/apache/jena/sparql/engine/main/VarFinder.java
@@ -30,7 +30,6 @@ import java.util.Map ;
 import java.util.Map.Entry ;
 import java.util.Set ;
 
-import org.apache.jena.atlas.lib.NotImplemented ;
 import org.apache.jena.sparql.algebra.Op ;
 import org.apache.jena.sparql.algebra.OpVisitor ;
 import org.apache.jena.sparql.algebra.op.* ;
@@ -164,15 +163,24 @@ public class VarFinder
 
         @Override
         public void visit(OpMinus opMinus) {
-            mergeVars(opMinus.getLeft()) ;
-            VarUsageVisitor usage = VarUsageVisitor.apply(opMinus.getRight());
+            mergeMinusDiff(opMinus.getLeft(), opMinus.getRight()) ;
+        }
+
+        @Override
+        public void visit(OpDiff opDiff) { 
+            mergeMinusDiff(opDiff.getLeft(), opDiff.getRight()) ;
+        }
+        
+        private void mergeMinusDiff(Op left, Op right) {
+            mergeVars(left) ;
+            VarUsageVisitor usage = VarUsageVisitor.apply(right);
             // Everything in the right side is really a filter.  
             filterMentions.addAll(usage.defines) ;
             filterMentions.addAll(usage.optDefines) ;
             filterMentions.addAll(usage.filterMentions) ;
             filterMentions.addAll(usage.assignMentions) ;
         }
-        
+
         @Override
         public void visit(OpConditional opLeftJoin) {
             leftJoin(opLeftJoin.getLeft(), opLeftJoin.getRight(), null);
@@ -292,6 +300,12 @@ public class VarFinder
         public void visit(OpList opList)            { mergeVars(opList.getSubOp()) ; }
         
         @Override
+        public void visit(OpService opService)      { mergeVars(opService.getSubOp()) ; }
+        
+        @Override
+        public void visit(OpTopN opTop)             { mergeVars(opTop.getSubOp()) ; }
+        
+        @Override
         public void visit(OpOrder opOrder) { 
             mergeVars(opOrder.getSubOp()) ;
             opOrder.getConditions().forEach(sc-> {
@@ -314,22 +328,12 @@ public class VarFinder
             addVar(defines, dsNames.getGraphNode()) ;
         }
 
-        // Not implemented: with checking. 
-
-        private void no() { 
-            throw new NotImplemented() ;
-        }
-        
         @Override
-        public void visit(OpProcedure opProc) { no() ; }
-
-        @Override
-        public void visit(OpService opService) { no(); }
-
-        @Override
-        public void visit(OpDiff opDiff) { no(); }
-        
-        @Override
-        public void visit(OpTopN opTop) { no(); }
+        public void visit(OpProcedure opProc) { 
+            for ( Expr expr :  opProc.getArgs() ) {
+                Set<Var> vars = expr.getVarsMentioned() ;
+                defines.addAll(vars) ;
+            }
+        }
     }
 }

http://git-wip-us.apache.org/repos/asf/jena/blob/4dbae033/jena-arq/src/test/java/org/apache/jena/sparql/algebra/optimize/TestOptimizer.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/test/java/org/apache/jena/sparql/algebra/optimize/TestOptimizer.java
b/jena-arq/src/test/java/org/apache/jena/sparql/algebra/optimize/TestOptimizer.java
index 947bbe4..b8656d0 100644
--- a/jena-arq/src/test/java/org/apache/jena/sparql/algebra/optimize/TestOptimizer.java
+++ b/jena-arq/src/test/java/org/apache/jena/sparql/algebra/optimize/TestOptimizer.java
@@ -24,7 +24,6 @@ import org.apache.jena.sparql.algebra.Op ;
 import org.apache.jena.sparql.algebra.op.OpAssign ;
 import org.apache.jena.sparql.algebra.op.OpExtend ;
 import org.apache.jena.sparql.algebra.op.OpTable ;
-import org.apache.jena.sparql.algebra.optimize.TransformExtendCombine ;
 import org.apache.jena.sparql.core.Var ;
 import org.apache.jena.sparql.core.VarExprList ;
 import org.apache.jena.sparql.expr.ExprVar ;
@@ -292,7 +291,7 @@ public class TestOptimizer extends AbstractTestTransform
         // JENA-809 : check no changes to input.
         String x = "(project (?x) (extend ((?bar 2)) (extend ((?foo 1)) (table unit))))"
;
         String y = "(project (?x) (extend ((?foo 1) (?bar 2)) (table unit)))" ;
-        AbstractTestTransform.checkAlgebra(x, new TransformExtendCombine(), y);
+        checkAlgebra(x, new TransformExtendCombine(), y);
     }
 
         
@@ -362,5 +361,51 @@ public class TestOptimizer extends AbstractTestTransform
         AbstractTestTransform.checkAlgebra(x, new TransformExtendCombine(), y);
     }
 
+    // Nested
+/*
+ *    String qs = StrUtils.strjoinNL
+            ("select *",  
+             "where {",  
+             "  { select * { ?id ?p ?label } order by ?label limit 5 }",  
+             "  OPTIONAL { OPTIONAL { ?s ?p ?label }}",   
+             "}"
+                );    
+ */
+    // Derived from JENA-1041 (inner TopN)
+    @Test public void subselect_01() {
+        String qs = StrUtils.strjoinNL
+            ("select *",  
+             "where {",  
+             "  { select * { ?id ?p ?label } order by ?label limit 5 }",  
+             "  ?s ?p ?label",   
+             "}"
+                );
+        String expected = StrUtils.strjoinNL
+            ("(sequence"
+            ,"  (top (5 ?label)"
+            ,"    (bgp (triple ?id ?p ?label)))"
+            ,"  (bgp (triple ?s ?p ?label)))") ;
+        check(qs, expected) ;
+    }
+    
+    // Derived from JENA-1041 (inner TopN)
+    @Test public void subselect_02() {
+        // Has a blocking optional pattern for the join strategy.
+        String qs = StrUtils.strjoinNL
+            ("select *",  
+             "where {",  
+             "  { select * { ?id ?p ?label } order by ?label limit 5 }",  
+             "  OPTIONAL { OPTIONAL { ?s ?p ?label }}",   
+             "}"
+                );
+        String expected = StrUtils.strjoinNL
+            ("(leftjoin"
+            ,"  (top (5 ?label)"
+            ,"    (bgp (triple ?id ?p ?label)))"
+            ,"  (conditional"
+            ,"    (table unit)"
+            ,"    (bgp (triple ?s ?p ?label))))") ;
+        check(qs, expected) ;
+    }
 
 }


Mime
View raw message