JENA-1193: Do not attempt to project vars when not at the top-level.

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

Branch: refs/heads/master
Commit: 0f2a544a6655b948c4a171a303442c767c2754a7
Parents: 5baef47
Author: Andy Seaborne <[email protected]>
Authored: Sat Jun 11 13:58:54 2016 +0100
Committer: Andy Seaborne <[email protected]>
Committed: Sat Jun 11 13:58:54 2016 +0100

----------------------------------------------------------------------
 .../jena/sdb/compiler/QueryIterOpSQL.java       | 43 ++++++++++++++------
 .../apache/jena/sdb/compiler/SDBCompile.java    |  3 +-
 .../org/apache/jena/sdb/core/SDBRequest.java    | 13 +++++-
 3 files changed, 44 insertions(+), 15 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/jena/blob/0f2a544a/jena-sdb/src/main/java/org/apache/jena/sdb/compiler/QueryIterOpSQL.java
----------------------------------------------------------------------
diff --git 
a/jena-sdb/src/main/java/org/apache/jena/sdb/compiler/QueryIterOpSQL.java 
b/jena-sdb/src/main/java/org/apache/jena/sdb/compiler/QueryIterOpSQL.java
index 958db93..e54b1ef 100644
--- a/jena-sdb/src/main/java/org/apache/jena/sdb/compiler/QueryIterOpSQL.java
+++ b/jena-sdb/src/main/java/org/apache/jena/sdb/compiler/QueryIterOpSQL.java
@@ -19,7 +19,9 @@
 package org.apache.jena.sdb.compiler;
 
 import org.apache.jena.atlas.io.IndentedWriter;
+import org.apache.jena.sdb.core.SDBRequest ;
 import org.apache.jena.sdb.shared.SDBInternalError ;
+import org.apache.jena.shared.PrefixMapping ;
 import org.apache.jena.sparql.algebra.Op ;
 import org.apache.jena.sparql.core.Substitute ;
 import org.apache.jena.sparql.engine.ExecutionContext ;
@@ -30,7 +32,11 @@ import 
org.apache.jena.sparql.engine.iterator.QueryIterRepeatApply ;
 public class QueryIterOpSQL extends QueryIterRepeatApply
 {
 
-    private OpSQL opSQL ;
+    private final OpSQL opSQL ;
+    // Modifed to remove the query - after substitution, the query is no 
longer useful
+    // information.  This also stops the bridge attempting to project 
variables -
+    // by this stage, we want all variables back.
+    private final SDBRequest request ;  
     
     public QueryIterOpSQL(OpSQL op, 
                         QueryIterator input ,
@@ -38,16 +44,24 @@ public class QueryIterOpSQL extends QueryIterRepeatApply
     { 
         super(input, context) ;
         this.opSQL = op ;
+        SDBRequest req = op.getRequest() ;
+        if ( req == null )
+            this.request = null ;
+        else {
+            PrefixMapping pmap = req.getQuery() == null ? null : 
req.getQuery().getPrefixMapping() ;
+            this.request = 
+                op.getRequest() == null 
+                ? null
+                : new SDBRequest(op.getRequest().getStore(), pmap, 
context.getContext()) ;
+        }
     }
     
     @Override
-    protected QueryIterator nextStage(Binding binding)
-    {
+    protected QueryIterator nextStage(Binding binding) {
         OpSQL execSQL = this.opSQL ;
 
-        if ( binding != null && ! isRoot(binding) )
-        {
-            QueryCompiler qc = 
opSQL.getRequest().getStore().getQueryCompilerFactory().createQueryCompiler(opSQL.getRequest())
 ;
+        if ( binding != null && ! isRoot(binding) ) {
+            QueryCompiler qc = 
opSQL.getRequest().getStore().getQueryCompilerFactory().createQueryCompiler(request)
 ;
             Op op2 = Substitute.substitute(opSQL.getOriginal(), binding) ;
             Op op = qc.compile(op2) ;
             if ( op instanceof OpSQL )
@@ -57,16 +71,21 @@ public class QueryIterOpSQL extends QueryIterRepeatApply
         }
 
         return execSQL.exec(binding, getExecContext()) ;
+//        QueryIterator qIter = execSQL.exec(binding, getExecContext()) ;
+//        List<Binding> x = Iter.toList(qIter) ;
+//        qIter = new QueryIterPlainWrapper(x.iterator(), getExecContext()) ;
+//        System.out.println("SQL Eval:") ;
+//        x.forEach(b -> System.out.println("  "+b) );
+//        System.out.println() ;
+//        return qIter ;
     }
-    
-    private static boolean isRoot(Binding binding)
-    {
-        return ! binding.vars().hasNext() ; 
+
+    private static boolean isRoot(Binding binding) {
+        return !binding.vars().hasNext() ;
     }
 
     @Override
-    public void output(IndentedWriter out)
-    {
+    public void output(IndentedWriter out) {
         opSQL.output(out) ;
     }
 }

http://git-wip-us.apache.org/repos/asf/jena/blob/0f2a544a/jena-sdb/src/main/java/org/apache/jena/sdb/compiler/SDBCompile.java
----------------------------------------------------------------------
diff --git 
a/jena-sdb/src/main/java/org/apache/jena/sdb/compiler/SDBCompile.java 
b/jena-sdb/src/main/java/org/apache/jena/sdb/compiler/SDBCompile.java
index a437730..d9a4515 100644
--- a/jena-sdb/src/main/java/org/apache/jena/sdb/compiler/SDBCompile.java
+++ b/jena-sdb/src/main/java/org/apache/jena/sdb/compiler/SDBCompile.java
@@ -24,6 +24,7 @@ import org.apache.jena.sdb.SDB ;
 import org.apache.jena.sdb.Store ;
 import org.apache.jena.sdb.core.SDBRequest ;
 import org.apache.jena.sdb.util.StoreUtils ;
+import org.apache.jena.shared.PrefixMapping ;
 import org.apache.jena.sparql.algebra.Op ;
 import org.apache.jena.sparql.core.Substitute ;
 import org.apache.jena.sparql.engine.binding.Binding ;
@@ -42,7 +43,7 @@ public class SDBCompile
         if ( context == null )
             context = SDB.getContext() ;
         
-        SDBRequest request = new SDBRequest(store, null, context) ;
+        SDBRequest request = new SDBRequest(store, (PrefixMapping)null, 
context) ;
         return compile(store, op, null, context, request) ;
     }
     

http://git-wip-us.apache.org/repos/asf/jena/blob/0f2a544a/jena-sdb/src/main/java/org/apache/jena/sdb/core/SDBRequest.java
----------------------------------------------------------------------
diff --git a/jena-sdb/src/main/java/org/apache/jena/sdb/core/SDBRequest.java 
b/jena-sdb/src/main/java/org/apache/jena/sdb/core/SDBRequest.java
index c37c49c..434fbae 100644
--- a/jena-sdb/src/main/java/org/apache/jena/sdb/core/SDBRequest.java
+++ b/jena-sdb/src/main/java/org/apache/jena/sdb/core/SDBRequest.java
@@ -38,7 +38,7 @@ import org.apache.jena.sparql.util.Context ;
 public class SDBRequest extends StoreHolder
 {
     private PrefixMapping prefixMapping ;
-    private Query query ;
+    private final Query query ;
     
     // Per request unique variables.
     private VarAlloc varAlloc = new VarAlloc(AliasesSparql.VarBase) ;
@@ -46,7 +46,7 @@ public class SDBRequest extends StoreHolder
     // Set in SDBCompile.compile
     public boolean LeftJoinTranslation = true ;     // Does the DB support 
general join expressions? 
     public boolean LimitOffsetTranslation = false ; // Does the DB grok the 
Limit/Offset SQL?
-    public boolean DistinctTranslation = true ;     // Some DBs can't do 
DISTINCt on CLOBS.
+    public boolean DistinctTranslation = true ;     // Some DBs can't do 
DISTINCT on CLOBS.
     
     private Context context ;
 
@@ -63,6 +63,15 @@ public class SDBRequest extends StoreHolder
         this.context = new Context(context) ;
     }
 
+    public SDBRequest(Store store, PrefixMapping prefixMapping, Context 
context) {
+        super(store) ;
+        this.query = null ;
+        this.prefixMapping = prefixMapping ;
+        if ( context == null )
+            context = SDB.getContext() ;
+        this.context = new Context(context) ;
+    }
+    
     public SDBRequest(Store store, Query query)
     { 
         this(store, query, null) ;

Reply via email to