jena-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a...@apache.org
Subject [05/20] jena git commit: Correct naming. Expand javadoc.
Date Tue, 08 Sep 2015 17:10:37 GMT
Correct naming. Expand javadoc.


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

Branch: refs/heads/master
Commit: 24e4c1ef3f66d5ffc23666988881f870a94d18fe
Parents: 07217a3
Author: Andy Seaborne <andy@apache.org>
Authored: Tue Sep 8 14:17:52 2015 +0100
Committer: Andy Seaborne <andy@apache.org>
Committed: Tue Sep 8 18:08:12 2015 +0100

----------------------------------------------------------------------
 .../apache/jena/sparql/engine/join/Join.java    | 89 ++++++++++++++++----
 1 file changed, 74 insertions(+), 15 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/jena/blob/24e4c1ef/jena-arq/src/main/java/org/apache/jena/sparql/engine/join/Join.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/main/java/org/apache/jena/sparql/engine/join/Join.java b/jena-arq/src/main/java/org/apache/jena/sparql/engine/join/Join.java
index 68536bf..4d4523f 100644
--- a/jena-arq/src/main/java/org/apache/jena/sparql/engine/join/Join.java
+++ b/jena-arq/src/main/java/org/apache/jena/sparql/engine/join/Join.java
@@ -19,7 +19,7 @@
 package org.apache.jena.sparql.engine.join;
 
 import static org.apache.jena.sparql.algebra.JoinType.LEFT ;
-import static org.apache.jena.sparql.algebra.JoinType.PLAIN ;
+import static org.apache.jena.sparql.algebra.JoinType.INNER ;
 
 import java.util.List ;
 
@@ -32,15 +32,22 @@ import org.apache.jena.sparql.algebra.TableFactory ;
 import org.apache.jena.sparql.engine.ExecutionContext ;
 import org.apache.jena.sparql.engine.QueryIterator ;
 import org.apache.jena.sparql.engine.binding.Binding ;
+import org.apache.jena.sparql.engine.iterator.QueryIterFilterExpr ;
 import org.apache.jena.sparql.engine.iterator.QueryIterPlainWrapper ;
 import org.apache.jena.sparql.engine.main.OpExecutor ;
 import org.apache.jena.sparql.engine.ref.TableJoin ;
+import org.apache.jena.sparql.expr.Expr ;
 import org.apache.jena.sparql.expr.ExprList ;
 
 /** API to various join algorithms */
 public class Join {
     // See also package org.apache.jena.sparql.engine.index
+    // The anti-join code for MINUS
 
+    // *******************
+    // USES OLD TableJoin CODE AT THE MOMENT
+    // *******************
+    
     /**
      * Standard entry point to a join of two streams.
      * This is not a substitution/index join.
@@ -51,7 +58,7 @@ public class Join {
      * @return QueryIterator
      */
     public static QueryIterator join(QueryIterator left, QueryIterator right, ExecutionContext
execCxt) {
-        return joinWorker(left, right, PLAIN, null, execCxt) ;
+        return joinWorker(left, right, INNER, null, execCxt) ;
     }
    
     /** Standard entry point to a left join of two streams.
@@ -106,8 +113,32 @@ public class Join {
     }
     
     
+    /** Inner loop join.
+     *  Cancellable.
+     * @param left      Left hand side
+     * @param right     Right hand side
+     * @param cxt       ExecutionContext
+     * @return          QueryIterator
+     */ 
+    public static QueryIterator nestedLoopJoin(QueryIterator left, QueryIterator right, ExecutionContext
cxt) {
+        return new QueryIterNestedLoopJoin(left, right, cxt) ;
+    }
+
+    /** Inner loop join.
+     *  Cancellable.
+     * @param left      Left hand side
+     * @param right     Right hand side
+     * @param cxt       ExecutionContext
+     * @return          QueryIterator
+     */ 
+    public static QueryIterator nestedLoopLeftJoin(QueryIterator left, QueryIterator right,
ExprList conditions, ExecutionContext cxt) {
+        return new QueryIterNestedLoopLeftJoin(left, right, conditions, cxt) ;
+    }
+
+
     /** Evaluate a hash join.  This code materializes the left into a probe table
      * then hash joins from the right.  
+     *  No cancelation, no stats.
      * 
      * @param joinKey   The key for the probe table.
      * @param left      Left hand side
@@ -119,10 +150,14 @@ public class Join {
         return new QueryIterHashJoin(joinKey, left, right, cxt) ;
     }
 
-    /** Very simple, materializing version - useful for debugging. 
-     * Does <b>not</b> scale. 
+    /** Very simple, materializing version - useful for debugging.
+     *  Builds output early. Materializes left, streams right.
+     *  Does <b>not</b> scale. 
+     *  No cancelation, no stats.
+     * 
+     * @see #nestedLoopJoin
      */
-    public static QueryIterator innerLoopJoinBasic(QueryIterator left, QueryIterator right,
ExecutionContext cxt) {
+    public static QueryIterator nestedLoopJoinBasic(QueryIterator left, QueryIterator right,
ExecutionContext cxt) {
         List<Binding> leftRows = Iter.toList(left) ;
         List<Binding> output = DS.list() ;
         for ( ; right.hasNext() ; ) {
@@ -136,16 +171,40 @@ public class Join {
         return new QueryIterPlainWrapper(output.iterator(), cxt) ;
     }
 
-    /** Inner loops join.  This code materializes the left ino the inner loop tabole and
-     *  then streams on the right.
-     *  
-     * @param left      Left hand side
-     * @param right     Right hand side
-     * @param cxt       ExecutionContext
-     * @return          QueryIterator
-     */ 
-    public static QueryIterator innerLoopJoin(QueryIterator left, QueryIterator right, ExecutionContext
cxt) {
-        return new QueryIterNestedLoopJoin(left, right, cxt) ;
+    /** Very simple, materializing version for leftjoin - useful for debugging.
+     *  Builds output early. Materializes right, streams left.
+     *  Does <b>not</b> scale. 
+     */
+    public static QueryIterator nestedLoopLeftJoinBasic(QueryIterator left, QueryIterator
right, ExprList condition, ExecutionContext cxt) {
+        // Stream from left, materialize right.
+        List<Binding> rightRows = Iter.toList(right) ;
+        List<Binding> output = DS.list() ;
+        long count = 0 ;
+        for ( ; left.hasNext() ; ) {
+            Binding row1 = left.next() ;
+            boolean match = false ;
+            for ( Binding row2 : rightRows ) {
+                Binding r = Algebra.merge(row1, row2) ;
+                if ( r != null ) {
+                    output.add(r) ;
+                    match = true ;
+                }
+            }
+            if ( ! match )
+                output.add(row1) ;
+        }
+        QueryIterator qIter = new QueryIterPlainWrapper(output.iterator(), cxt) ;
+        qIter = applyConditions(qIter, condition, cxt) ;
+        return qIter ;
+    }
+
+    // apply conditions.
+    private static QueryIterator applyConditions(QueryIterator qIter, ExprList conditions,
ExecutionContext execCxt) {
+        if ( conditions == null )
+            return qIter ;
+        for (Expr expr : conditions)
+            qIter = new QueryIterFilterExpr(qIter, expr, execCxt) ;
+        return qIter ;
     }
 }
 


Mime
View raw message