jena-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rve...@apache.org
Subject [2/7] jena git commit: Add additional test cases for inlining (JENA-780)
Date Wed, 08 Jul 2015 14:12:00 GMT
Add additional test cases for inlining (JENA-780)

Adds some more test cases which checks behaviour with inlining through
projections which is possible if the assignment is projected and we're
in a stack of unary operators


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

Branch: refs/heads/jena2
Commit: a18864815440586daeb7470154d6a2a6efb4827e
Parents: 166b31f
Author: Rob Vesse <rvesse@apache.org>
Authored: Tue Jul 7 17:47:08 2015 +0100
Committer: Rob Vesse <rvesse@apache.org>
Committed: Tue Jul 7 17:47:08 2015 +0100

----------------------------------------------------------------------
 .../optimize/TransformRemoveAssignment.java     | 16 ++++++
 .../TestTransformEliminateAssignments.java      | 52 ++++++++++++++++++++
 2 files changed, 68 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/jena/blob/a1886481/jena-arq/src/main/java/com/hp/hpl/jena/sparql/algebra/optimize/TransformRemoveAssignment.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/main/java/com/hp/hpl/jena/sparql/algebra/optimize/TransformRemoveAssignment.java
b/jena-arq/src/main/java/com/hp/hpl/jena/sparql/algebra/optimize/TransformRemoveAssignment.java
index 88bd048..855ec10 100644
--- a/jena-arq/src/main/java/com/hp/hpl/jena/sparql/algebra/optimize/TransformRemoveAssignment.java
+++ b/jena-arq/src/main/java/com/hp/hpl/jena/sparql/algebra/optimize/TransformRemoveAssignment.java
@@ -18,11 +18,14 @@
 
 package com.hp.hpl.jena.sparql.algebra.optimize;
 
+import java.util.List;
+
 import com.hp.hpl.jena.sparql.algebra.Op;
 import com.hp.hpl.jena.sparql.algebra.TransformCopy;
 import com.hp.hpl.jena.sparql.algebra.op.OpAssign;
 import com.hp.hpl.jena.sparql.algebra.op.OpExtend;
 import com.hp.hpl.jena.sparql.algebra.op.OpExtendAssign;
+import com.hp.hpl.jena.sparql.algebra.op.OpProject;
 import com.hp.hpl.jena.sparql.core.Var;
 import com.hp.hpl.jena.sparql.core.VarExprList;
 import com.hp.hpl.jena.sparql.expr.Expr;
@@ -113,4 +116,17 @@ public class TransformRemoveAssignment extends TransformCopy {
         }
     }
 
+    public Op transform(OpProject opProject, Op subOp) {
+        if (!opProject.getVars().contains(this.var))
+            return super.transform(opProject, subOp);
+        
+        List<Var> newVars = opProject.getVars();
+        newVars.remove(this.var);
+        if (newVars.size() > 0) {
+            return new OpProject(subOp, newVars);
+        } else {
+            return subOp;
+        }
+    }
+
 }

http://git-wip-us.apache.org/repos/asf/jena/blob/a1886481/jena-arq/src/test/java/com/hp/hpl/jena/sparql/algebra/optimize/TestTransformEliminateAssignments.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/test/java/com/hp/hpl/jena/sparql/algebra/optimize/TestTransformEliminateAssignments.java
b/jena-arq/src/test/java/com/hp/hpl/jena/sparql/algebra/optimize/TestTransformEliminateAssignments.java
index 4f3a1a4..ed96785 100644
--- a/jena-arq/src/test/java/com/hp/hpl/jena/sparql/algebra/optimize/TestTransformEliminateAssignments.java
+++ b/jena-arq/src/test/java/com/hp/hpl/jena/sparql/algebra/optimize/TestTransformEliminateAssignments.java
@@ -440,6 +440,58 @@ public class TestTransformEliminateAssignments {
     }
 
     @Test
+    public void through_project_01() {
+        // We can inline out through a project by also eliminating the variable
+        // from the project
+        //@formatter:off
+        test(StrUtils.strjoinNL("(project (?y)",
+                                "  (filter (exprlist ?x)",
+                                "    (project (?x)",
+                                "      (extend (?x true)",
+                                "        (table unit)))))"),
+            "(project (?y)",
+            "  (filter true",
+            "    (table unit)))");
+        //@formatter:on
+    }
+
+    @Test
+    public void through_project_02() {
+        // We can inline out through a project by also eliminating the variable
+        // from the project
+        //@formatter:off
+        test(StrUtils.strjoinNL("(project (?y)",
+                                "  (filter (exprlist ?x)",
+                                "    (project (?x ?y)",
+                                "      (extend (?x true)",
+                                "        (bgp (triple ?y <urn:pred> <urn:obj>))))))"),
+            "(project (?y)",
+            "  (filter true",
+            "    (project (?y)",
+            "      (bgp (triple ?y <urn:pred> <urn:obj>)))))");
+        //@formatter:on
+    }
+
+    @Test
+    public void through_project_03() {
+        // We can't inline out through a project if the assignment is not
+        // projected
+        // However we can still eliminate it from the inner projection if that
+        // would render it unused
+        //@formatter:off
+        test(StrUtils.strjoinNL("(project (?y)",
+                                "  (filter (exprlist ?x)",
+                                "    (project (?y)",
+                                "      (extend (?x true)",
+                                "        (table unit)))))"),
+             "(project (?y)",
+             "  (filter (exprlist ?x)",
+             "    (project (?y)",
+             "      (table unit))))");
+        //@formatter:on
+    }
+
+    @Test
     public void no_merge_01() {
         // We should not merge extends
         //@formatter:off


Mime
View raw message