jena-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a...@apache.org
Subject svn commit: r1511698 - in /jena/trunk/jena-arq/src: main/java/com/hp/hpl/jena/sparql/graph/NodeTransformLib.java main/java/com/hp/hpl/jena/sparql/graph/NodeTransformOp.java test/java/com/hp/hpl/jena/sparql/algebra/optimize/TestVarRename.java
Date Thu, 08 Aug 2013 11:17:45 GMT
Author: andy
Date: Thu Aug  8 11:17:45 2013
New Revision: 1511698

URL: http://svn.apache.org/r1511698
Log:
JENA-502
Rewrite variables in tables (needed when doing a rename for nested SELECTs).

Modified:
    jena/trunk/jena-arq/src/main/java/com/hp/hpl/jena/sparql/graph/NodeTransformLib.java
    jena/trunk/jena-arq/src/main/java/com/hp/hpl/jena/sparql/graph/NodeTransformOp.java
    jena/trunk/jena-arq/src/test/java/com/hp/hpl/jena/sparql/algebra/optimize/TestVarRename.java

Modified: jena/trunk/jena-arq/src/main/java/com/hp/hpl/jena/sparql/graph/NodeTransformLib.java
URL: http://svn.apache.org/viewvc/jena/trunk/jena-arq/src/main/java/com/hp/hpl/jena/sparql/graph/NodeTransformLib.java?rev=1511698&r1=1511697&r2=1511698&view=diff
==============================================================================
--- jena/trunk/jena-arq/src/main/java/com/hp/hpl/jena/sparql/graph/NodeTransformLib.java (original)
+++ jena/trunk/jena-arq/src/main/java/com/hp/hpl/jena/sparql/graph/NodeTransformLib.java Thu
Aug  8 11:17:45 2013
@@ -19,21 +19,28 @@
 package com.hp.hpl.jena.sparql.graph;
 
 import java.util.ArrayList ;
+import java.util.Iterator ;
 import java.util.List ;
 
+import org.apache.jena.atlas.iterator.Iter ;
 import static org.apache.jena.atlas.lib.Lib.equal ;
 
 import com.hp.hpl.jena.graph.Node ;
 import com.hp.hpl.jena.graph.Triple ;
 import com.hp.hpl.jena.query.SortCondition ;
 import com.hp.hpl.jena.sparql.algebra.Op ;
+import com.hp.hpl.jena.sparql.algebra.Table ;
 import com.hp.hpl.jena.sparql.algebra.Transform ;
 import com.hp.hpl.jena.sparql.algebra.Transformer ;
+import com.hp.hpl.jena.sparql.algebra.table.TableData ;
 import com.hp.hpl.jena.sparql.core.BasicPattern ;
 import com.hp.hpl.jena.sparql.core.Quad ;
 import com.hp.hpl.jena.sparql.core.QuadPattern ;
 import com.hp.hpl.jena.sparql.core.Var ;
 import com.hp.hpl.jena.sparql.core.VarExprList ;
+import com.hp.hpl.jena.sparql.engine.binding.Binding ;
+import com.hp.hpl.jena.sparql.engine.binding.BindingFactory ;
+import com.hp.hpl.jena.sparql.engine.binding.BindingMap ;
 import com.hp.hpl.jena.sparql.expr.Expr ;
 import com.hp.hpl.jena.sparql.expr.ExprList ;
 
@@ -122,6 +129,31 @@ public class NodeTransformLib
             return quad ;
         return new Quad(g,s,p,o) ;
     }
+    
+    public static Table transform(Table table, NodeTransform transform) {
+        // Non-streaming rewrite 
+        List<Var> vars = transformVars(transform, table.getVars()) ;
+        Iterator<Binding> iter = table.rows() ; 
+        List<Binding> newRows = new ArrayList<Binding>() ;
+        for ( ; iter.hasNext() ; ) { 
+            Binding b = iter.next() ;
+            Binding b2 = transform(b, transform) ;
+            newRows.add(b2) ;
+        }
+        return new TableData(vars, newRows) ;
+    }
+    
+    public static Binding transform(Binding b, NodeTransform transform) {
+        BindingMap b2 = BindingFactory.create() ;
+        List<Var> vars = Iter.toList(b.vars()) ;
+        for ( Var v : vars ) {
+            Var v2 = (Var)transform.convert(v) ;
+            b2.add(v2, b.get(v));
+        }
+        return b2 ;
+    }
+
+
 
     /** Do a node->node conversion of a List&lt;Quad&gt; - return original List&lt;Quad&gt;
for "no change" */
     public static List<Quad> transformQuads(NodeTransform nodeTransform, List<Quad>
quads)

Modified: jena/trunk/jena-arq/src/main/java/com/hp/hpl/jena/sparql/graph/NodeTransformOp.java
URL: http://svn.apache.org/viewvc/jena/trunk/jena-arq/src/main/java/com/hp/hpl/jena/sparql/graph/NodeTransformOp.java?rev=1511698&r1=1511697&r2=1511698&view=diff
==============================================================================
--- jena/trunk/jena-arq/src/main/java/com/hp/hpl/jena/sparql/graph/NodeTransformOp.java (original)
+++ jena/trunk/jena-arq/src/main/java/com/hp/hpl/jena/sparql/graph/NodeTransformOp.java Thu
Aug  8 11:17:45 2013
@@ -25,8 +25,10 @@ import com.hp.hpl.jena.graph.Node ;
 import com.hp.hpl.jena.graph.Triple ;
 import com.hp.hpl.jena.query.SortCondition ;
 import com.hp.hpl.jena.sparql.algebra.Op ;
+import com.hp.hpl.jena.sparql.algebra.Table ;
 import com.hp.hpl.jena.sparql.algebra.TransformCopy ;
 import com.hp.hpl.jena.sparql.algebra.op.* ;
+import com.hp.hpl.jena.sparql.algebra.table.TableUnit ;
 import com.hp.hpl.jena.sparql.core.BasicPattern ;
 import com.hp.hpl.jena.sparql.core.TriplePath ;
 import com.hp.hpl.jena.sparql.core.Var ;
@@ -136,7 +138,15 @@ class NodeTransformOp extends TransformC
     {
         if ( opTable.isJoinIdentity() )
             return opTable ;
-        return opTable ;
+        Table table = opTable.getTable() ;
+        if ( table.isEmpty() )
+            return opTable ;
+        if ( TableUnit.isTableUnit(table) )
+            return opTable ;
+        if ( table.getVars().size() == 0 )
+            return opTable ;
+        Table table2 = NodeTransformLib.transform(table, transform) ;
+        return OpTable.create(table2) ; 
     }
     
     @Override public Op transform(OpLeftJoin opLeftJoin, Op left, Op right)

Modified: jena/trunk/jena-arq/src/test/java/com/hp/hpl/jena/sparql/algebra/optimize/TestVarRename.java
URL: http://svn.apache.org/viewvc/jena/trunk/jena-arq/src/test/java/com/hp/hpl/jena/sparql/algebra/optimize/TestVarRename.java?rev=1511698&r1=1511697&r2=1511698&view=diff
==============================================================================
--- jena/trunk/jena-arq/src/test/java/com/hp/hpl/jena/sparql/algebra/optimize/TestVarRename.java
(original)
+++ jena/trunk/jena-arq/src/test/java/com/hp/hpl/jena/sparql/algebra/optimize/TestVarRename.java
Thu Aug  8 11:17:45 2013
@@ -80,7 +80,13 @@ public class TestVarRename extends BaseT
                                            true,
                                            "s", "o") ; }
     
+    // JENA-502 : failure to rewrite (table) in var rename.
+    @Test public void rename_13() { rename("(project (?s) (project (?s) (table (vars ?obj)
(row [?obj 123])) ))",
+                                           "(project (?s) (project (?s) (table (vars ?/obj)
(row [?/obj 123])) ))",
+                                           true,
+                                           "s") ; }
 
+    
     @Test public void rename_reverse_01() { reverse("(project (?s ?/p) (bgp (?s ?/p ?/o)))",
                                                     "(project (?s ?p) (bgp (?s ?p ?o)))",
true ) ; }  
 



Mime
View raw message