jena-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a...@apache.org
Subject svn commit: r1491880 - in /jena/trunk/jena-arq/src/main/java/com/hp/hpl/jena/sparql/engine: main/OpExecutor.java main/StageBuilder.java main/StageGeneratorGeneric.java ref/Eval.java
Date Tue, 11 Jun 2013 17:13:49 GMT
Author: andy
Date: Tue Jun 11 17:13:48 2013
New Revision: 1491880

URL: http://svn.apache.org/r1491880
Log:
Tidy up general algebra execution engine.
* reformat to more usual layout
* Create stage generator once per execution

Modified:
    jena/trunk/jena-arq/src/main/java/com/hp/hpl/jena/sparql/engine/main/OpExecutor.java
    jena/trunk/jena-arq/src/main/java/com/hp/hpl/jena/sparql/engine/main/StageBuilder.java
    jena/trunk/jena-arq/src/main/java/com/hp/hpl/jena/sparql/engine/main/StageGeneratorGeneric.java
    jena/trunk/jena-arq/src/main/java/com/hp/hpl/jena/sparql/engine/ref/Eval.java

Modified: jena/trunk/jena-arq/src/main/java/com/hp/hpl/jena/sparql/engine/main/OpExecutor.java
URL: http://svn.apache.org/viewvc/jena/trunk/jena-arq/src/main/java/com/hp/hpl/jena/sparql/engine/main/OpExecutor.java?rev=1491880&r1=1491879&r2=1491880&view=diff
==============================================================================
--- jena/trunk/jena-arq/src/main/java/com/hp/hpl/jena/sparql/engine/main/OpExecutor.java (original)
+++ jena/trunk/jena-arq/src/main/java/com/hp/hpl/jena/sparql/engine/main/OpExecutor.java Tue
Jun 11 17:13:48 2013
@@ -16,25 +16,26 @@
  * limitations under the License.
  */
 
-package com.hp.hpl.jena.sparql.engine.main;
+package com.hp.hpl.jena.sparql.engine.main ;
 
 import java.util.ArrayList ;
 import java.util.Iterator ;
 import java.util.List ;
-import java.util.Set;
+import java.util.Set ;
 
 import org.apache.jena.atlas.iterator.Iter ;
 import org.apache.jena.atlas.logging.Log ;
 
 import com.hp.hpl.jena.graph.Node ;
+import com.hp.hpl.jena.query.ARQ ;
 import com.hp.hpl.jena.query.QueryExecException ;
 import com.hp.hpl.jena.sparql.ARQNotImplemented ;
 import com.hp.hpl.jena.sparql.algebra.Op ;
-import com.hp.hpl.jena.sparql.algebra.OpVars;
+import com.hp.hpl.jena.sparql.algebra.OpVars ;
 import com.hp.hpl.jena.sparql.algebra.op.* ;
 import com.hp.hpl.jena.sparql.core.BasicPattern ;
 import com.hp.hpl.jena.sparql.core.Quad ;
-import com.hp.hpl.jena.sparql.core.Var;
+import com.hp.hpl.jena.sparql.core.Var ;
 import com.hp.hpl.jena.sparql.engine.ExecutionContext ;
 import com.hp.hpl.jena.sparql.engine.QueryIterator ;
 import com.hp.hpl.jena.sparql.engine.binding.Binding ;
@@ -58,133 +59,131 @@ import com.hp.hpl.jena.sparql.procedure.
  * execution. During execution, when a substitution into an algebra expression
  * happens (in other words, a streaming operation, index-join-like), there is a
  * call into the executor each time so it does not just happen once before a
- * query starts. */
+ * query starts.
+ */
 
 public class OpExecutor
 {
-    // Set this to a different factory implementation to have a different OpExecutor.  
-    protected static final OpExecutorFactory stdFactory = new OpExecutorFactory(){
-        @Override
-        public OpExecutor create(ExecutionContext execCxt)
-        {
-            return new OpExecutor(execCxt) ;
-        }} ;  
-//    public static Factory factory = stdFactory ; 
+    // Set this to a different factory implementation to have a different
+    // OpExecutor.
+    protected static final OpExecutorFactory stdFactory = new OpExecutorFactory() {
+                                                            @Override
+                                                            public OpExecutor create(ExecutionContext
execCxt) {
+                                                                return new OpExecutor(execCxt)
;
+                                                            }
+                                                        } ;
 
-    
-    private static OpExecutor createOpExecutor(ExecutionContext execCxt)
-    {
+    // public static Factory factory = stdFactory ;
+
+    private static OpExecutor createOpExecutor(ExecutionContext execCxt) {
         OpExecutorFactory factory = execCxt.getExecutor() ;
-        if ( factory == null )
+        if (factory == null)
             factory = stdFactory ;
-        if ( factory == null )
-            return new OpExecutor(execCxt) ; 
+        if (factory == null)
+            return new OpExecutor(execCxt) ;
         return factory.create(execCxt) ;
     }
-    
+
     // -------
-    
-    static QueryIterator execute(Op op, ExecutionContext execCxt)
-    {
+
+    static QueryIterator execute(Op op, ExecutionContext execCxt) {
         return execute(op, createRootQueryIterator(execCxt), execCxt) ;
     }
-    
+
     // Public interface is via QC.execute.
-    static QueryIterator execute(Op op, QueryIterator qIter, ExecutionContext execCxt)
-    {
+    static QueryIterator execute(Op op, QueryIterator qIter, ExecutionContext execCxt) {
         OpExecutor exec = createOpExecutor(execCxt) ;
         QueryIterator q = exec.executeOp(op, qIter) ;
         return q ;
     }
 
     // -------- The object starts here --------
-    
-    protected ExecutionContext execCxt ;
-    protected ExecutionDispatch dispatcher = null ;
-    protected static final int TOP_LEVEL = 0 ; 
-    protected int level = TOP_LEVEL-1 ;
+
+    protected ExecutionContext     execCxt ;
+    protected ExecutionDispatch    dispatcher = null ;
+    protected static final int     TOP_LEVEL  = 0 ;
+    protected int                  level      = TOP_LEVEL - 1 ;
+    private final boolean          hideBNodeVars ;
+    protected final StageGenerator stageGenerator ;
 
     protected OpExecutor(ExecutionContext execCxt)
-    { 
+    {
         this.execCxt = execCxt ;
-        dispatcher = new ExecutionDispatch(this) ;
+        this.dispatcher = new ExecutionDispatch(this) ;
+        this.hideBNodeVars = execCxt.getContext().isTrue(ARQ.hideNonDistiguishedVariables)
;
+        this.stageGenerator = StageBuilder.chooseStageGenerator(execCxt.getContext()) ;
     }
 
-//    public QueryIterator executeOp(Op op)
-//    {
+//    public QueryIterator executeOp(Op op) {
 //        return executeOp(op, root()) ;
 //    }
 
     // ---- The recursive step.
-    
-    public QueryIterator executeOp(Op op, QueryIterator input)
-    {
+
+    public QueryIterator executeOp(Op op, QueryIterator input) {
         level++ ;
         QueryIterator qIter = dispatcher.exec(op, input) ;
-        // Intentionally not try/finally so exceptions leave some evidence around.
+        // Intentionally not try/finally so exceptions leave some evidence
+        // around.
         level-- ;
         return qIter ;
     }
-    
+
     // ---- All the cases
-    
-    protected QueryIterator execute(OpBGP opBGP, QueryIterator input)
-    {
+
+    protected QueryIterator execute(OpBGP opBGP, QueryIterator input) {
         BasicPattern pattern = opBGP.getPattern() ;
-        return StageBuilder.execute(pattern, input, execCxt) ;
+        QueryIterator qIter = stageGenerator.execute(pattern, input, execCxt) ;
+        if (hideBNodeVars)
+            qIter = new QueryIterDistinguishedVars(qIter, execCxt) ;
+        return qIter ;
     }
 
-    protected QueryIterator execute(OpTriple opTriple, QueryIterator input)
-    {
+    protected QueryIterator execute(OpTriple opTriple, QueryIterator input) {
         return execute(opTriple.asBGP(), input) ;
     }
 
-    protected QueryIterator execute(OpGraph opGraph, QueryIterator input)
-    { 
+    protected QueryIterator execute(OpGraph opGraph, QueryIterator input) {
         QueryIterator qIter = specialcase(opGraph.getNode(), opGraph.getSubOp(), input) ;
-        if ( qIter != null )
+        if (qIter != null)
             return qIter ;
         return new QueryIterGraph(input, opGraph, execCxt) ;
     }
 
-    private QueryIterator specialcase(Node gn, Op subOp, QueryIterator input)
-    {
-        // This is a placeholder for code to specially handle explicitly named 
+    private QueryIterator specialcase(Node gn, Op subOp, QueryIterator input) {
+        // This is a placeholder for code to specially handle explicitly named
         // default graph and union graph.
-        
-        if ( Quad.isDefaultGraph(gn) )
-        {
+
+        if (Quad.isDefaultGraph(gn)) {
             ExecutionContext cxt2 = new ExecutionContext(execCxt, execCxt.getDataset().getDefaultGraph())
;
             return execute(subOp, input, cxt2) ;
         }
-        
-        if ( gn == Quad.unionGraph )
+
+        if (gn == Quad.unionGraph)
             Log.warn(this, "Not implemented yet: union default graph in general OpExecutor")
;
 
-        if ( true ) return null ;
-    
-        /* Bad
-        if ( gn == Quad.tripleInQuad ) {}
+        if (true)
+            return null ;
+
+        /*
+         * Bad if ( gn == Quad.tripleInQuad ) {}
          */
-    
+
         return null ;
     }
 
-    protected QueryIterator execute(OpQuad opQuad, QueryIterator input)
-    {
+    protected QueryIterator execute(OpQuad opQuad, QueryIterator input) {
         return execute(opQuad.asQuadPattern(), input) ;
     }
 
-
-    protected QueryIterator execute(OpQuadPattern quadPattern, QueryIterator input)
-    {
+    protected QueryIterator execute(OpQuadPattern quadPattern, QueryIterator input) {
         // Convert to BGP forms to execute in this graph-centric engine.
-        if ( quadPattern.isDefaultGraph() && execCxt.getActiveGraph() == execCxt.getDataset().getDefaultGraph()
)
-        {
-            // Note we tested that the containing graph was the dataset's default graph.

+        if (quadPattern.isDefaultGraph() && execCxt.getActiveGraph() == execCxt.getDataset().getDefaultGraph())
{
+            // Note we tested that the containing graph was the dataset's
+            // default graph.
             // Easy case.
             OpBGP opBGP = new OpBGP(quadPattern.getBasicPattern()) ;
-            return execute(opBGP, input) ;  
+            return execute(opBGP, input) ;
         }
         // Not default graph - (graph .... )
         OpBGP opBGP = new OpBGP(quadPattern.getBasicPattern()) ;
@@ -192,38 +191,35 @@ public class OpExecutor
         return execute(op, input) ;
     }
 
-    protected QueryIterator execute(OpPath opPath, QueryIterator input)
-    {
+    protected QueryIterator execute(OpPath opPath, QueryIterator input) {
         return new QueryIterPath(opPath.getTriplePath(), input, execCxt) ;
     }
 
-    protected QueryIterator execute(OpProcedure opProc, QueryIterator input)
-    {
+    protected QueryIterator execute(OpProcedure opProc, QueryIterator input) {
         Procedure procedure = ProcEval.build(opProc, execCxt) ;
         QueryIterator qIter = executeOp(opProc.getSubOp(), input) ;
         // Delay until query starts executing.
         return new QueryIterProcedure(qIter, procedure, execCxt) ;
     }
 
-    protected QueryIterator execute(OpPropFunc opPropFunc, QueryIterator input)
-    {
-        Procedure procedure = ProcEval.build(opPropFunc.getProperty(), opPropFunc.getSubjectArgs(),opPropFunc.getObjectArgs(),
execCxt) ;
+    protected QueryIterator execute(OpPropFunc opPropFunc, QueryIterator input) {
+        Procedure procedure = ProcEval.build(opPropFunc.getProperty(), opPropFunc.getSubjectArgs(),
+                                             opPropFunc.getObjectArgs(), execCxt) ;
         QueryIterator qIter = executeOp(opPropFunc.getSubOp(), input) ;
         return new QueryIterProcedure(qIter, procedure, execCxt) ;
     }
 
-    protected QueryIterator execute(OpJoin opJoin, QueryIterator input)
-    {
+    protected QueryIterator execute(OpJoin opJoin, QueryIterator input) {
         // Need to clone input into left and right.
-        // Do by evaling for each input case, the left and right and concat'ing the results.
+        // Do by evaling for each input case, the left and right and concat'ing
+        // the results.
 
-        if ( false )
-        {
-            // If needed, applies to OpDiff and OpLeftJoin as well. 
+        if (false) {
+            // If needed, applies to OpDiff and OpLeftJoin as well.
             List<Binding> a = all(input) ;
             QueryIterator qIter1 = new QueryIterPlainWrapper(a.iterator(), execCxt) ;
             QueryIterator qIter2 = new QueryIterPlainWrapper(a.iterator(), execCxt) ;
-            
+
             QueryIterator left = executeOp(opJoin.getLeft(), qIter1) ;
             QueryIterator right = executeOp(opJoin.getRight(), qIter2) ;
             QueryIterator qIter = new QueryIterJoin(left, right, execCxt) ;
@@ -236,46 +232,40 @@ public class OpExecutor
     }
 
     // Pass iterator from one step directly into the next.
-    protected QueryIterator execute(OpSequence opSequence, QueryIterator input)
-    {
+    protected QueryIterator execute(OpSequence opSequence, QueryIterator input) {
         QueryIterator qIter = input ;
-        
-        for ( Iterator<Op> iter = opSequence.iterator() ; iter.hasNext() ; )
-        {
+
+        for (Iterator<Op> iter = opSequence.iterator(); iter.hasNext();) {
             Op sub = iter.next() ;
             qIter = executeOp(sub, qIter) ;
         }
-        
+
         return qIter ;
     }
-    
-    protected QueryIterator execute(OpLeftJoin opLeftJoin, QueryIterator input)
-    {
+
+    protected QueryIterator execute(OpLeftJoin opLeftJoin, QueryIterator input) {
         QueryIterator left = executeOp(opLeftJoin.getLeft(), input) ;
         QueryIterator right = executeOp(opLeftJoin.getRight(), root()) ;
         QueryIterator qIter = new QueryIterLeftJoin(left, right, opLeftJoin.getExprs(), execCxt)
;
         return qIter ;
     }
 
-    protected QueryIterator execute(OpConditional opCondition, QueryIterator input)
-    {
+    protected QueryIterator execute(OpConditional opCondition, QueryIterator input) {
         QueryIterator left = executeOp(opCondition.getLeft(), input) ;
         QueryIterator qIter = new QueryIterOptionalIndex(left, opCondition.getRight(), execCxt)
;
         return qIter ;
     }
-    
-    protected QueryIterator execute(OpDiff opDiff, QueryIterator input)
-    { 
+
+    protected QueryIterator execute(OpDiff opDiff, QueryIterator input) {
         QueryIterator left = executeOp(opDiff.getLeft(), input) ;
         QueryIterator right = executeOp(opDiff.getRight(), root()) ;
         return new QueryIterDiff(left, right, execCxt) ;
     }
-    
-    protected QueryIterator execute(OpMinus opMinus, QueryIterator input)
-    { 
-    	Op lhsOp = opMinus.getLeft();
-    	Op rhsOp = opMinus.getRight();
-    	
+
+    protected QueryIterator execute(OpMinus opMinus, QueryIterator input) {
+        Op lhsOp = opMinus.getLeft() ;
+        Op rhsOp = opMinus.getRight() ;
+
         QueryIterator left = executeOp(lhsOp, input) ;
         QueryIterator right = executeOp(rhsOp, root()) ;
 
@@ -284,138 +274,122 @@ public class OpExecutor
 
         return new QueryIterMinus(left, right, commonVars, execCxt) ;
     }
-    
-    protected QueryIterator execute(OpDisjunction opDisjunction, QueryIterator input)
-    {
+
+    protected QueryIterator execute(OpDisjunction opDisjunction, QueryIterator input) {
         QueryIterator cIter = new QueryIterUnion(input, opDisjunction.getElements(), execCxt)
;
         return cIter ;
     }
 
-    protected QueryIterator execute(OpUnion opUnion, QueryIterator input)
-    {
+    protected QueryIterator execute(OpUnion opUnion, QueryIterator input) {
         List<Op> x = flattenUnion(opUnion) ;
         QueryIterator cIter = new QueryIterUnion(input, x, execCxt) ;
         return cIter ;
     }
-    
+
     // Based on code from Olaf Hartig.
-    protected List<Op> flattenUnion(OpUnion opUnion)
-    {
+    protected List<Op> flattenUnion(OpUnion opUnion) {
         List<Op> x = new ArrayList<Op>() ;
         flattenUnion(x, opUnion) ;
         return x ;
     }
-    
-    protected void flattenUnion(List<Op> acc, OpUnion opUnion)
-    {
+
+    protected void flattenUnion(List<Op> acc, OpUnion opUnion) {
         if (opUnion.getLeft() instanceof OpUnion)
             flattenUnion(acc, (OpUnion)opUnion.getLeft()) ;
         else
-            acc.add( opUnion.getLeft() ) ;
+            acc.add(opUnion.getLeft()) ;
 
         if (opUnion.getRight() instanceof OpUnion)
             flattenUnion(acc, (OpUnion)opUnion.getRight()) ;
         else
-            acc.add( opUnion.getRight() ) ;
+            acc.add(opUnion.getRight()) ;
     }
-    
-    protected QueryIterator execute(OpFilter opFilter, QueryIterator input)
-    {
+
+    protected QueryIterator execute(OpFilter opFilter, QueryIterator input) {
         ExprList exprs = opFilter.getExprs() ;
-        
+
         Op base = opFilter.getSubOp() ;
         QueryIterator qIter = executeOp(base, input) ;
 
-        for ( Expr expr : exprs )
+        for (Expr expr : exprs)
             qIter = new QueryIterFilterExpr(qIter, expr, execCxt) ;
         return qIter ;
     }
 
-    protected QueryIterator execute(OpService opService, QueryIterator input)
-    {
+    protected QueryIterator execute(OpService opService, QueryIterator input) {
         return new QueryIterService(input, opService, execCxt) ;
     }
-    
-    // Quad form, "GRAPH ?g {}"  Flip back to OpGraph.
+
+    // Quad form, "GRAPH ?g {}" Flip back to OpGraph.
     // Normally quad stores override this.
-    protected QueryIterator execute(OpDatasetNames dsNames, QueryIterator input)
-    { 
-        if ( false )
-        {
+    protected QueryIterator execute(OpDatasetNames dsNames, QueryIterator input) {
+        if (false) {
             OpGraph op = new OpGraph(dsNames.getGraphNode(), new OpBGP()) ;
             return execute(op, input) ;
         }
         throw new ARQNotImplemented("execute/OpDatasetNames") ;
     }
 
-    protected QueryIterator execute(OpTable opTable, QueryIterator input)
-    { 
-//        if ( input instanceof QueryIteratorBase )
-//        {
-//            String x = ((QueryIteratorBase)input).debug();
-//            System.out.println(x) ;
-//        }
-//        
-        if ( opTable.isJoinIdentity() )
+    protected QueryIterator execute(OpTable opTable, QueryIterator input) {
+        // if ( input instanceof QueryIteratorBase )
+        // {
+        // String x = ((QueryIteratorBase)input).debug();
+        // System.out.println(x) ;
+        // }
+        //
+        if (opTable.isJoinIdentity())
             return input ;
-        if ( input instanceof QueryIterRoot )
-        {
+        if (input instanceof QueryIterRoot) {
             input.close() ;
             return opTable.getTable().iterator(execCxt) ;
         }
-        //throw new ARQNotImplemented("Not identity table") ;
+        // throw new ARQNotImplemented("Not identity table") ;
         QueryIterator qIterT = opTable.getTable().iterator(execCxt) ;
-        //QueryIterator qIterT = root() ;
+        // QueryIterator qIterT = root() ;
         QueryIterator qIter = new QueryIterJoin(input, qIterT, execCxt) ;
         return qIter ;
     }
 
-    protected QueryIterator execute(OpExt opExt, QueryIterator input)
-    { 
+    protected QueryIterator execute(OpExt opExt, QueryIterator input) {
         try {
             QueryIterator qIter = opExt.eval(input, execCxt) ;
-            if ( qIter != null )
+            if (qIter != null)
                 return qIter ;
-        } catch (UnsupportedOperationException ex) { }
+        } catch (UnsupportedOperationException ex) {}
         // null or UnsupportedOperationException
-        throw new QueryExecException("Encountered unsupported OpExt: "+opExt.getName()) ;
+        throw new QueryExecException("Encountered unsupported OpExt: " + opExt.getName())
;
     }
 
-    protected QueryIterator execute(OpLabel opLabel, QueryIterator input)
-    {
-      if ( ! opLabel.hasSubOp() )
-          return input ;
+    protected QueryIterator execute(OpLabel opLabel, QueryIterator input) {
+        if (!opLabel.hasSubOp())
+            return input ;
 
-      return executeOp(opLabel.getSubOp(), input) ;
+        return executeOp(opLabel.getSubOp(), input) ;
     }
 
-    protected QueryIterator execute(OpNull opNull, QueryIterator input)
-    {
+    protected QueryIterator execute(OpNull opNull, QueryIterator input) {
         // Loose the input.
         input.close() ;
         return new QueryIterNullIterator(execCxt) ;
     }
 
-    protected QueryIterator execute(OpList opList, QueryIterator input)
-    {
+    protected QueryIterator execute(OpList opList, QueryIterator input) {
         return executeOp(opList.getSubOp(), input) ;
     }
-    
-    protected QueryIterator execute(OpOrder opOrder, QueryIterator input)
-    { 
+
+    protected QueryIterator execute(OpOrder opOrder, QueryIterator input) {
         QueryIterator qIter = executeOp(opOrder.getSubOp(), input) ;
         qIter = new QueryIterSort(qIter, opOrder.getConditions(), execCxt) ;
         return qIter ;
     }
 
-    protected QueryIterator execute(OpTopN opTop, QueryIterator input)
-    { 
+    protected QueryIterator execute(OpTopN opTop, QueryIterator input) {
         QueryIterator qIter = null ;
         // We could also do (reduced) here as well.
         // but it's detected in TrabsformTopN and turned into (distinct)
         // there so that code catches that already.
-        // We leave this to do the strict case of (top N (distinct ...)) 
-        if ( opTop.getSubOp() instanceof OpDistinct ) {
+        // We leave this to do the strict case of (top N (distinct ...))
+        if (opTop.getSubOp() instanceof OpDistinct) {
             OpDistinct opDistinct = (OpDistinct)opTop.getSubOp() ;
             qIter = executeOp(opDistinct.getSubOp(), input) ;
             qIter = new QueryIterTopN(qIter, opTop.getConditions(), opTop.getLimit(), true,
execCxt) ;
@@ -426,97 +400,86 @@ public class OpExecutor
         return qIter ;
     }
 
-    protected QueryIterator execute(OpProject opProject, QueryIterator input)
-    {
-        // This may be under a (graph) in which case we need to operate 
+    protected QueryIterator execute(OpProject opProject, QueryIterator input) {
+        // This may be under a (graph) in which case we need to operate
         // the active graph.
-        
+
         // More intelligent QueryIterProject needed.
-        
-        if ( input instanceof QueryIterRoot )
-        {
-            QueryIterator  qIter = executeOp(opProject.getSubOp(), input) ;
+
+        if (input instanceof QueryIterRoot) {
+            QueryIterator qIter = executeOp(opProject.getSubOp(), input) ;
             qIter = new QueryIterProject(qIter, opProject.getVars(), execCxt) ;
             return qIter ;
         }
         // Nested projected : need to ensure the input is seen.
         // ROLL into QueryIterProject
-        QueryIterator qIter = new QueryIterProject2(opProject, input, this, execCxt) ; 
+        QueryIterator qIter = new QueryIterProject2(opProject, input, this, execCxt) ;
         return qIter ;
     }
 
-    protected QueryIterator execute(OpSlice opSlice, QueryIterator input)
-    { 
+    protected QueryIterator execute(OpSlice opSlice, QueryIterator input) {
         QueryIterator qIter = executeOp(opSlice.getSubOp(), input) ;
         qIter = new QueryIterSlice(qIter, opSlice.getStart(), opSlice.getLength(), execCxt)
;
         return qIter ;
     }
-    
-    protected QueryIterator execute(OpGroup opGroup, QueryIterator input)
-    { 
+
+    protected QueryIterator execute(OpGroup opGroup, QueryIterator input) {
         QueryIterator qIter = executeOp(opGroup.getSubOp(), input) ;
         qIter = new QueryIterGroup(qIter, opGroup.getGroupVars(), opGroup.getAggregators(),
execCxt) ;
         return qIter ;
     }
-    
-    protected QueryIterator execute(OpDistinct opDistinct, QueryIterator input)
-    {
+
+    protected QueryIterator execute(OpDistinct opDistinct, QueryIterator input) {
         QueryIterator qIter = executeOp(opDistinct.getSubOp(), input) ;
         qIter = new QueryIterDistinct(qIter, execCxt) ;
         return qIter ;
     }
 
-    protected QueryIterator execute(OpReduced opReduced, QueryIterator input)
-    {
+    protected QueryIterator execute(OpReduced opReduced, QueryIterator input) {
         QueryIterator qIter = executeOp(opReduced.getSubOp(), input) ;
         qIter = new QueryIterReduced(qIter, execCxt) ;
         return qIter ;
     }
 
-    protected QueryIterator execute(OpAssign opAssign, QueryIterator input)
-    {
+    protected QueryIterator execute(OpAssign opAssign, QueryIterator input) {
         // Need prepare?
         QueryIterator qIter = executeOp(opAssign.getSubOp(), input) ;
         qIter = new QueryIterAssign(qIter, opAssign.getVarExprList(), execCxt, false) ;
         return qIter ;
     }
 
-    protected QueryIterator execute(OpExtend opExtend, QueryIterator input)
-    {
+    protected QueryIterator execute(OpExtend opExtend, QueryIterator input) {
         // We know (parse time checking) the variable is unused so far in
         // the query so we can use QueryIterAssign knowing that it behaves
-        // the same as extend. The boolean should only be a check. 
+        // the same as extend. The boolean should only be a check.
         QueryIterator qIter = executeOp(opExtend.getSubOp(), input) ;
         qIter = new QueryIterAssign(qIter, opExtend.getVarExprList(), execCxt, true) ;
         return qIter ;
     }
 
-    public static QueryIterator createRootQueryIterator(ExecutionContext execCxt)
-    {
+    public static QueryIterator createRootQueryIterator(ExecutionContext execCxt) {
         return QueryIterRoot.create(execCxt) ;
     }
 
-    protected QueryIterator root()
-    { return createRootQueryIterator(execCxt) ; }
+    protected QueryIterator root() {
+        return createRootQueryIterator(execCxt) ;
+    }
 
     // Use this to debug evaluation
     // Example:
-    //    input = debug(input) ;
-    private QueryIterator debug(String marker, QueryIterator input)
-    {
+    // input = debug(input) ;
+    private QueryIterator debug(String marker, QueryIterator input) {
         List<Binding> x = all(input) ;
-        for ( Binding b : x )
-        {
+        for (Binding b : x) {
             System.out.print(marker) ;
             System.out.print(": ") ;
             System.out.println(b) ;
         }
-        
+
         return new QueryIterPlainWrapper(x.iterator(), execCxt) ;
     }
 
-    private static List<Binding> all(QueryIterator input)
-    {
+    private static List<Binding> all(QueryIterator input) {
         return Iter.toList(input) ;
     }
 }

Modified: jena/trunk/jena-arq/src/main/java/com/hp/hpl/jena/sparql/engine/main/StageBuilder.java
URL: http://svn.apache.org/viewvc/jena/trunk/jena-arq/src/main/java/com/hp/hpl/jena/sparql/engine/main/StageBuilder.java?rev=1491880&r1=1491879&r2=1491880&view=diff
==============================================================================
--- jena/trunk/jena-arq/src/main/java/com/hp/hpl/jena/sparql/engine/main/StageBuilder.java
(original)
+++ jena/trunk/jena-arq/src/main/java/com/hp/hpl/jena/sparql/engine/main/StageBuilder.java
Tue Jun 11 17:13:48 2013
@@ -22,7 +22,7 @@ import com.hp.hpl.jena.query.ARQ ;
 import com.hp.hpl.jena.sparql.core.BasicPattern ;
 import com.hp.hpl.jena.sparql.engine.ExecutionContext ;
 import com.hp.hpl.jena.sparql.engine.QueryIterator ;
-import com.hp.hpl.jena.sparql.engine.iterator.QueryIterDistinguishedVars ;
+import com.hp.hpl.jena.sparql.engine.iterator.QueryIterBlockTriples ;
 import com.hp.hpl.jena.sparql.util.Context ;
 
 /** The stage builder (there is only one) is a library that encapsulates
@@ -45,24 +45,24 @@ import com.hp.hpl.jena.sparql.util.Conte
 
 public class StageBuilder
 {
-    public static QueryIterator execute(BasicPattern pattern, 
-                                        QueryIterator input, 
-                                        ExecutionContext execCxt)
-    {
-        if ( pattern.isEmpty() )
-            return input ;
-        
-        boolean hideBNodeVars = execCxt.getContext().isTrue(ARQ.hideNonDistiguishedVariables)
;
-        
-        StageGenerator gen = chooseStageGenerator(execCxt.getContext()) ;
-        QueryIterator qIter = gen.execute(pattern, input, execCxt) ;
-
-        // Remove non-distinguished variables here.
-        // Project out only named variables.
-        if ( hideBNodeVars )
-            qIter = new QueryIterDistinguishedVars(qIter, execCxt) ;
-        return qIter ;
-    }
+//    public static QueryIterator execute(BasicPattern pattern, 
+//                                        QueryIterator input, 
+//                                        ExecutionContext execCxt)
+//    {
+//        if ( pattern.isEmpty() )
+//            return input ;
+//        
+//        boolean hideBNodeVars = execCxt.getContext().isTrue(ARQ.hideNonDistiguishedVariables)
;
+//        
+//        StageGenerator gen = chooseStageGenerator(execCxt.getContext()) ;
+//        QueryIterator qIter = gen.execute(pattern, input, execCxt) ;
+//
+//        // Remove non-distinguished variables here.
+//        // Project out only named variables.
+//        if ( hideBNodeVars )
+//            qIter = new QueryIterDistinguishedVars(qIter, execCxt) ;
+//        return qIter ;
+//    }
     
     // -------- Initialize
     
@@ -76,6 +76,14 @@ public class StageBuilder
         }
     }
     
+    /** The plain StageGenerator, no reordring */
+    public static StageGenerator executeInline = new StageGenerator() {
+        @Override
+        public QueryIterator execute(BasicPattern pattern, QueryIterator input, ExecutionContext
execCxt)
+        {
+                return QueryIterBlockTriples.create(input, pattern, execCxt) ;
+        }} ;
+        
     // -------- Manage StageGenerator registration
     
     public static void setGenerator(Context context, StageGenerator builder)
@@ -100,11 +108,11 @@ public class StageBuilder
         return new StageGeneratorGeneric() ;
     }
     
-    private static StageGenerator chooseStageGenerator(Context context)
+    public static StageGenerator chooseStageGenerator(Context context)
     {
         StageGenerator gen = getGenerator(context) ;
         if ( gen == null )
-            gen = getGenerator() ;
+            gen = new StageGeneratorGeneric() ;
         return gen ; 
     }
 }

Modified: jena/trunk/jena-arq/src/main/java/com/hp/hpl/jena/sparql/engine/main/StageGeneratorGeneric.java
URL: http://svn.apache.org/viewvc/jena/trunk/jena-arq/src/main/java/com/hp/hpl/jena/sparql/engine/main/StageGeneratorGeneric.java?rev=1491880&r1=1491879&r2=1491880&view=diff
==============================================================================
--- jena/trunk/jena-arq/src/main/java/com/hp/hpl/jena/sparql/engine/main/StageGeneratorGeneric.java
(original)
+++ jena/trunk/jena-arq/src/main/java/com/hp/hpl/jena/sparql/engine/main/StageGeneratorGeneric.java
Tue Jun 11 17:13:48 2013
@@ -56,14 +56,14 @@ public class StageGeneratorGeneric imple
         if ( graph instanceof GraphMem  )            // Jena in-memory graph
         {
             reorder = reorderBasicStats(graph) ;
-            executor = executeInline ; 
+            executor = StageBuilder.executeInline ; ; 
         }
         else
         {
             // When in doubt ... use the general pass-through to graph query handler matcher.
             // Includes union graphs, InfGraphs and other composite or unusual kinds.
             reorder = null ;
-            executor = executeInline ;
+            executor = StageBuilder.executeInline ;
         }
 
         return execute(pattern, reorder, executor, input, execCxt) ;
@@ -87,13 +87,6 @@ public class StageGeneratorGeneric imple
         return execution.execute(pattern, input, execCxt) ; 
     }
     
-    private static StageGenerator executeInline = new StageGenerator() {
-        @Override
-        public QueryIterator execute(BasicPattern pattern, QueryIterator input, ExecutionContext
execCxt)
-        {
-                return QueryIterBlockTriples.create(input, pattern, execCxt) ;
-        }} ;
-        
     // ---- Reorder policies
         
     // Fixed - Variable counting only. 

Modified: jena/trunk/jena-arq/src/main/java/com/hp/hpl/jena/sparql/engine/ref/Eval.java
URL: http://svn.apache.org/viewvc/jena/trunk/jena-arq/src/main/java/com/hp/hpl/jena/sparql/engine/ref/Eval.java?rev=1491880&r1=1491879&r2=1491880&view=diff
==============================================================================
--- jena/trunk/jena-arq/src/main/java/com/hp/hpl/jena/sparql/engine/ref/Eval.java (original)
+++ jena/trunk/jena-arq/src/main/java/com/hp/hpl/jena/sparql/engine/ref/Eval.java Tue Jun
11 17:13:48 2013
@@ -24,6 +24,7 @@ import java.util.List ;
 
 import com.hp.hpl.jena.graph.Graph ;
 import com.hp.hpl.jena.graph.Node ;
+import com.hp.hpl.jena.query.ARQ ;
 import com.hp.hpl.jena.sparql.ARQInternalErrorException ;
 import com.hp.hpl.jena.sparql.algebra.Op ;
 import com.hp.hpl.jena.sparql.algebra.Table ;
@@ -42,9 +43,11 @@ import com.hp.hpl.jena.sparql.engine.bin
 import com.hp.hpl.jena.sparql.engine.binding.BindingFactory ;
 import com.hp.hpl.jena.sparql.engine.binding.BindingRoot ;
 import com.hp.hpl.jena.sparql.engine.iterator.QueryIterConcat ;
+import com.hp.hpl.jena.sparql.engine.iterator.QueryIterDistinguishedVars ;
 import com.hp.hpl.jena.sparql.engine.iterator.QueryIterPlainWrapper ;
 import com.hp.hpl.jena.sparql.engine.iterator.QueryIterRoot ;
 import com.hp.hpl.jena.sparql.engine.main.StageBuilder ;
+import com.hp.hpl.jena.sparql.engine.main.StageGenerator ;
 
 // Spit out a few of the longer ops.
 public class Eval
@@ -152,7 +155,7 @@ public class Eval
             if ( g == null )
                 return new TableEmpty() ;
             ExecutionContext cxt2 = new ExecutionContext(cxt, g) ;
-            QueryIterator qIter = StageBuilder.execute(pattern, QueryIterRoot.create(cxt2),
cxt2) ;
+            QueryIterator qIter = executeBGP(pattern, QueryIterRoot.create(cxt2), cxt2) ;
             return TableFactory.create(qIter) ;
         }
         else
@@ -173,7 +176,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 = StageBuilder.execute(pattern, QueryIterRoot.create(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)) ;
@@ -182,6 +185,22 @@ public class Eval
         }
     }
 
+    private static QueryIterator executeBGP(BasicPattern pattern, QueryIterator input, ExecutionContext
execCxt) {
+        if (pattern.isEmpty())
+            return input ;
+
+        boolean hideBNodeVars = execCxt.getContext().isTrue(ARQ.hideNonDistiguishedVariables)
;
+
+        StageGenerator gen = StageBuilder.executeInline ;
+        QueryIterator qIter = gen.execute(pattern, input, execCxt) ;
+
+        // Remove non-distinguished variables here.
+        // Project out only named variables.
+        if (hideBNodeVars)
+            qIter = new QueryIterDistinguishedVars(qIter, execCxt) ;
+        return qIter ;
+    }
+    
     // This is for an arbitrary quad collection.
     // Downside is that each quad is solved separtely, not in a BGP.
     // This breaks property functions with list arguments



Mime
View raw message