jena-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a...@apache.org
Subject jena git commit: JENA-1354: Create a marked root iterator for initialBindings
Date Wed, 31 May 2017 15:31:33 GMT
Repository: jena
Updated Branches:
  refs/heads/master 54fac0be8 -> 08abdebae


JENA-1354: Create a marked root iterator for initialBindings


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

Branch: refs/heads/master
Commit: 08abdebaedd869804c592f112d2cd225385c4186
Parents: 54fac0b
Author: Andy Seaborne <andy@apache.org>
Authored: Wed May 31 16:27:28 2017 +0100
Committer: Andy Seaborne <andy@apache.org>
Committed: Wed May 31 16:27:28 2017 +0100

----------------------------------------------------------------------
 .../sparql/engine/iterator/QueryIterRoot.java   | 20 +++++++++++++-------
 .../jena/sparql/engine/main/OpExecutor.java     |  2 +-
 .../sparql/engine/main/QueryEngineMain.java     |  6 ++----
 .../org/apache/jena/sparql/engine/ref/Eval.java |  4 ++--
 .../jena/sparql/engine/ref/EvaluatorSimple.java |  4 ++--
 .../jena/sparql/path/eval/PathEngine.java       |  2 +-
 .../org/apache/jena/sparql/api/TestAPI.java     | 12 ++++++++++++
 .../apache/jena/sdb/engine/QueryEngineSDB.java  |  2 +-
 8 files changed, 34 insertions(+), 18 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/jena/blob/08abdeba/jena-arq/src/main/java/org/apache/jena/sparql/engine/iterator/QueryIterRoot.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/main/java/org/apache/jena/sparql/engine/iterator/QueryIterRoot.java
b/jena-arq/src/main/java/org/apache/jena/sparql/engine/iterator/QueryIterRoot.java
index eb7170e..20cffdd 100644
--- a/jena-arq/src/main/java/org/apache/jena/sparql/engine/iterator/QueryIterRoot.java
+++ b/jena-arq/src/main/java/org/apache/jena/sparql/engine/iterator/QueryIterRoot.java
@@ -25,17 +25,24 @@ import org.apache.jena.sparql.engine.binding.Binding ;
 import org.apache.jena.sparql.engine.binding.BindingRoot ;
 import org.apache.jena.sparql.serializer.SerializationContext ;
 
-/** The root binding is one-row, no columns making it the join identity.
+/** The root binding is one-row, usually no columns making it the join identity.
+ *  It has columns only for an initial binding.
  *  It is useful to be able to spot it before having to activate a {@link QueryIterator}.
  *  Executing with a pre-set binding does not use QueryIterRoot.
  */
-public class QueryIterRoot extends QueryIterSingleton
+public class QueryIterRoot extends QueryIterYieldN 
+    // Not "extends QueryIterSingleton" so we don't get its factory statics.
 {
-    public static QueryIterator createRoot(ExecutionContext execCxt)
-    { return new QueryIterRoot(BindingRoot.create(), execCxt) ; }
+    /** Create a root */ 
+    public static QueryIterator create(ExecutionContext execCxt)
+    { return create(BindingRoot.create(), execCxt) ; }
     
+    /** Create a root with an initial binding */
+    public static QueryIterator create(Binding binding, ExecutionContext execCxt)
+    { return new QueryIterRoot(binding, execCxt) ; }
+
     private QueryIterRoot(Binding binding, ExecutionContext execCxt) {
-        super(binding, execCxt) ;
+        super(1, binding, execCxt) ;
     }
 
     @Override
@@ -43,10 +50,9 @@ public class QueryIterRoot extends QueryIterSingleton
         if ( binding instanceof BindingRoot )
             out.print("QueryIterRoot");
         else
-            // Not used
             out.print("QueryIterRoot: "+binding);
     }
     
     @Override
-    public boolean isJoinIdentity() { return true; }
+    public boolean isJoinIdentity() { return binding.isEmpty(); }
 }

http://git-wip-us.apache.org/repos/asf/jena/blob/08abdeba/jena-arq/src/main/java/org/apache/jena/sparql/engine/main/OpExecutor.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/main/java/org/apache/jena/sparql/engine/main/OpExecutor.java b/jena-arq/src/main/java/org/apache/jena/sparql/engine/main/OpExecutor.java
index a8ab2f4..506f055 100644
--- a/jena-arq/src/main/java/org/apache/jena/sparql/engine/main/OpExecutor.java
+++ b/jena-arq/src/main/java/org/apache/jena/sparql/engine/main/OpExecutor.java
@@ -435,7 +435,7 @@ public class OpExecutor
     }
 
     public static QueryIterator createRootQueryIterator(ExecutionContext execCxt) {
-        return QueryIterRoot.createRoot(execCxt) ;
+        return QueryIterRoot.create(execCxt) ;
     }
 
     protected QueryIterator root() {

http://git-wip-us.apache.org/repos/asf/jena/blob/08abdeba/jena-arq/src/main/java/org/apache/jena/sparql/engine/main/QueryEngineMain.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/main/java/org/apache/jena/sparql/engine/main/QueryEngineMain.java
b/jena-arq/src/main/java/org/apache/jena/sparql/engine/main/QueryEngineMain.java
index 861242a..49a7452 100644
--- a/jena-arq/src/main/java/org/apache/jena/sparql/engine/main/QueryEngineMain.java
+++ b/jena-arq/src/main/java/org/apache/jena/sparql/engine/main/QueryEngineMain.java
@@ -27,7 +27,6 @@ import org.apache.jena.sparql.core.DatasetGraph ;
 import org.apache.jena.sparql.engine.* ;
 import org.apache.jena.sparql.engine.binding.Binding ;
 import org.apache.jena.sparql.engine.iterator.QueryIterRoot ;
-import org.apache.jena.sparql.engine.iterator.QueryIterSingleton;
 import org.apache.jena.sparql.engine.iterator.QueryIteratorCheck ;
 import org.apache.jena.sparql.engine.iterator.QueryIteratorTiming ;
 import org.apache.jena.sparql.util.Context ;
@@ -51,9 +50,8 @@ public class QueryEngineMain extends QueryEngineBase
     {
         ExecutionContext execCxt = new ExecutionContext(context, dsg.getDefaultGraph(), dsg,
QC.getFactory(context)) ;
         QueryIterator qIter1 = 
-            ( input.isEmpty() ) 
-            ? QueryIterRoot.createRoot(execCxt)
-            : QueryIterSingleton.create(input, execCxt);
+            ( input.isEmpty() ) ? QueryIterRoot.create(execCxt) 
+                                : QueryIterRoot.create(input, execCxt);
         QueryIterator qIter = QC.execute(op, qIter1, execCxt) ;
         // Wrap with something to check for closed iterators.
         qIter = QueryIteratorCheck.check(qIter, execCxt) ;

http://git-wip-us.apache.org/repos/asf/jena/blob/08abdeba/jena-arq/src/main/java/org/apache/jena/sparql/engine/ref/Eval.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/main/java/org/apache/jena/sparql/engine/ref/Eval.java b/jena-arq/src/main/java/org/apache/jena/sparql/engine/ref/Eval.java
index 5843728..40608d2 100644
--- a/jena-arq/src/main/java/org/apache/jena/sparql/engine/ref/Eval.java
+++ b/jena-arq/src/main/java/org/apache/jena/sparql/engine/ref/Eval.java
@@ -159,7 +159,7 @@ public class Eval
             if ( g == null )
                 return new TableEmpty() ;
             ExecutionContext cxt2 = new ExecutionContext(cxt, g) ;
-            QueryIterator qIter = executeBGP(pattern, QueryIterRoot.createRoot(cxt2), cxt2)
;
+            QueryIterator qIter = executeBGP(pattern, QueryIterRoot.create(cxt2), cxt2) ;
             return TableFactory.create(qIter) ;
         }
         else
@@ -180,7 +180,7 @@ public class Eval
                 // Eval the pattern, eval the variable, join.
                 // Pattern may be non-linear in the variable - do a pure execution.  
                 Table t1 = TableFactory.create(gVar, gn) ;
-                QueryIterator qIter = executeBGP(pattern, QueryIterRoot.createRoot(cxt2),
cxt2) ;
+                QueryIterator qIter = executeBGP(pattern, QueryIterRoot.create(cxt2), cxt2)
;
                 Table t2 = TableFactory.create(qIter) ;
                 Table t3 = evaluator.join(t1, t2) ;
                 concat.add(t3.iterator(cxt2)) ;

http://git-wip-us.apache.org/repos/asf/jena/blob/08abdeba/jena-arq/src/main/java/org/apache/jena/sparql/engine/ref/EvaluatorSimple.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/main/java/org/apache/jena/sparql/engine/ref/EvaluatorSimple.java
b/jena-arq/src/main/java/org/apache/jena/sparql/engine/ref/EvaluatorSimple.java
index f14befa..fb57584 100644
--- a/jena-arq/src/main/java/org/apache/jena/sparql/engine/ref/EvaluatorSimple.java
+++ b/jena-arq/src/main/java/org/apache/jena/sparql/engine/ref/EvaluatorSimple.java
@@ -63,7 +63,7 @@ public class EvaluatorSimple implements Evaluator
     @Override
     public Table basicPattern(BasicPattern pattern)
     {
-        QueryIterator qIter = QC.executeDirect(pattern, QueryIterRoot.createRoot(execCxt),
execCxt) ;
+        QueryIterator qIter = QC.executeDirect(pattern, QueryIterRoot.create(execCxt), execCxt)
;
         return TableFactory.create(qIter) ;
     }
 
@@ -72,7 +72,7 @@ public class EvaluatorSimple implements Evaluator
     {
         // Shudder - this may well be expensive, but this is the simple evaluator, written
for correctness. 
         QueryIterator qIter = new QueryIterPath(triplePath, 
-                                                QueryIterRoot.createRoot(execCxt),
+                                                QueryIterRoot.create(execCxt),
                                                 execCxt) ;
         return TableFactory.create(qIter) ;
     }

http://git-wip-us.apache.org/repos/asf/jena/blob/08abdeba/jena-arq/src/main/java/org/apache/jena/sparql/path/eval/PathEngine.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/main/java/org/apache/jena/sparql/path/eval/PathEngine.java b/jena-arq/src/main/java/org/apache/jena/sparql/path/eval/PathEngine.java
index 0def867..643411c 100644
--- a/jena-arq/src/main/java/org/apache/jena/sparql/path/eval/PathEngine.java
+++ b/jena-arq/src/main/java/org/apache/jena/sparql/path/eval/PathEngine.java
@@ -210,7 +210,7 @@ abstract public class PathEngine
         PropertyFunction pf = f.create(p.getURI()) ;
         PropFuncArg sv = arg(s, "S") ;
         PropFuncArg ov = arg(o, "O") ;
-        QueryIterator r = QueryIterRoot.createRoot(new ExecutionContext(context, graph, null,
null)) ;
+        QueryIterator r = QueryIterRoot.create(new ExecutionContext(context, graph, null,
null)) ;
         QueryIterator qIter = pf.exec(r, sv, p, ov, new ExecutionContext(ARQ.getContext(),
graph, null, null)) ;
         if ( ! qIter.hasNext() )
             return Iter.nullIterator() ;

http://git-wip-us.apache.org/repos/asf/jena/blob/08abdeba/jena-arq/src/test/java/org/apache/jena/sparql/api/TestAPI.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/test/java/org/apache/jena/sparql/api/TestAPI.java b/jena-arq/src/test/java/org/apache/jena/sparql/api/TestAPI.java
index dbc9bf3..74c27a8 100644
--- a/jena-arq/src/test/java/org/apache/jena/sparql/api/TestAPI.java
+++ b/jena-arq/src/test/java/org/apache/jena/sparql/api/TestAPI.java
@@ -247,6 +247,18 @@ public class TestAPI extends BaseTest
         assertTrue(result);
     }
     
+    @Test public void testInitialBindings7() {
+        // JENA-1354
+        Query query = QueryFactory.create("SELECT DISTINCT ?x WHERE {}");
+        Dataset ds = DatasetFactory.create();
+        QuerySolutionMap initialBinding = new QuerySolutionMap();
+        initialBinding.add("a", ResourceFactory.createTypedLiteral(Boolean.TRUE));
+        try ( QueryExecution qexec = QueryExecutionFactory.create(query, ds, initialBinding)
) {
+            assertFalse(qexec.execSelect().next().contains("a"));
+        }
+    }
+    
+
     @Test public void testReuseQueryObject1()
     {
         String queryString = "SELECT * {?s ?p ?o}";

http://git-wip-us.apache.org/repos/asf/jena/blob/08abdeba/jena-sdb/src/main/java/org/apache/jena/sdb/engine/QueryEngineSDB.java
----------------------------------------------------------------------
diff --git a/jena-sdb/src/main/java/org/apache/jena/sdb/engine/QueryEngineSDB.java b/jena-sdb/src/main/java/org/apache/jena/sdb/engine/QueryEngineSDB.java
index b14f39c..8f3e826 100644
--- a/jena-sdb/src/main/java/org/apache/jena/sdb/engine/QueryEngineSDB.java
+++ b/jena-sdb/src/main/java/org/apache/jena/sdb/engine/QueryEngineSDB.java
@@ -143,7 +143,7 @@ public class QueryEngineSDB extends QueryEngineBase
             if ( binding != null && binding.size() != 0 )
                 qIter = QueryIterSingleton.create(binding, execCxt) ;
             else
-                qIter = QueryIterRoot.createRoot(execCxt) ;
+                qIter = QueryIterRoot.create(execCxt) ;
         }
         else
             qIter = opSQL.exec(binding, execCxt) ;


Mime
View raw message