You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jena.apache.org by an...@apache.org on 2015/09/08 19:11:43 UTC
[01/20] jena git commit: Move simple join code into ref query engine.
Repository: jena
Updated Branches:
refs/heads/master 668db14a4 -> 0fcfbe739
Move simple join code into ref query engine.
Project: http://git-wip-us.apache.org/repos/asf/jena/repo
Commit: http://git-wip-us.apache.org/repos/asf/jena/commit/c7dafa2d
Tree: http://git-wip-us.apache.org/repos/asf/jena/tree/c7dafa2d
Diff: http://git-wip-us.apache.org/repos/asf/jena/diff/c7dafa2d
Branch: refs/heads/master
Commit: c7dafa2dbf6273b35ceb5717e2cfe820ec694db0
Parents: 9f158b6
Author: Andy Seaborne <an...@apache.org>
Authored: Tue Sep 8 10:21:49 2015 +0100
Committer: Andy Seaborne <an...@apache.org>
Committed: Tue Sep 8 10:21:49 2015 +0100
----------------------------------------------------------------------
.../apache/jena/sparql/engine/TableJoin.java | 104 ------------------
.../apache/jena/sparql/engine/join/Join.java | 74 +++++++++++++
.../engine/main/iterator/QueryIterJoinBase.java | 73 ++++++-------
.../jena/sparql/engine/ref/EvaluatorSimple.java | 1 -
.../jena/sparql/engine/ref/TableJoin.java | 106 +++++++++++++++++++
5 files changed, 215 insertions(+), 143 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/jena/blob/c7dafa2d/jena-arq/src/main/java/org/apache/jena/sparql/engine/TableJoin.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/main/java/org/apache/jena/sparql/engine/TableJoin.java b/jena-arq/src/main/java/org/apache/jena/sparql/engine/TableJoin.java
deleted file mode 100644
index e16c505..0000000
--- a/jena-arq/src/main/java/org/apache/jena/sparql/engine/TableJoin.java
+++ /dev/null
@@ -1,104 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.jena.sparql.engine;
-
-import static org.apache.jena.sparql.algebra.JoinType.* ;
-
-import java.util.ArrayList ;
-import java.util.Iterator ;
-import java.util.List ;
-
-import org.apache.jena.sparql.algebra.Algebra ;
-import org.apache.jena.sparql.algebra.JoinType ;
-import org.apache.jena.sparql.algebra.Table ;
-import org.apache.jena.sparql.algebra.table.TableUnit ;
-import org.apache.jena.sparql.engine.binding.Binding ;
-import org.apache.jena.sparql.engine.iterator.QueryIterFilterExpr ;
-import org.apache.jena.sparql.engine.iterator.QueryIterNullIterator ;
-import org.apache.jena.sparql.engine.iterator.QueryIterPlainWrapper ;
-import org.apache.jena.sparql.expr.Expr ;
-import org.apache.jena.sparql.expr.ExprList ;
-
-/** Table join - this only happens if the patterns can not be streamed. */
-public class TableJoin
-{
- public static QueryIterator join(QueryIterator left, Table right, ExprList condition, ExecutionContext execCxt) {
- return joinWorker(left, right, PLAIN, condition, execCxt) ;
- }
-
- public static QueryIterator leftJoin(QueryIterator left, Table right, ExprList condition, ExecutionContext execCxt) {
- return joinWorker(left, right, LEFT, condition, execCxt) ;
- }
-
- public static QueryIterator joinWorker(QueryIterator left, Table right, JoinType joinType, ExprList conditions, ExecutionContext execCxt) {
- if ( right.isEmpty() ) {
- if ( joinType == PLAIN ) {
- // No rows - no match
- left.close() ;
- return QueryIterNullIterator.create(execCxt) ;
- }
- else
- return left ;
- }
-
- if ( TableUnit.isTableUnit(right) ) {
- if ( joinType == PLAIN )
- return applyConditions(left, conditions, execCxt) ;
- else
- return left ;
- }
- return joinWorkerN(left, right, joinType, conditions, execCxt) ;
- }
-
- private static QueryIterator joinWorkerN(QueryIterator left, Table right, JoinType joinType, ExprList conditions, ExecutionContext execCxt) {
- // We could hash the right except we don't know much about columns.
-
- List<Binding> out = new ArrayList<>() ;
- for ( ; left.hasNext() ; ) {
- Binding bindingLeft = left.next() ;
- int count = 0 ;
- for (Iterator<Binding> iter = right.rows() ; iter.hasNext();) {
- Binding bindingRight = iter.next() ;
- Binding r = Algebra.merge(bindingLeft, bindingRight) ;
-
- if ( r == null )
- continue ;
- // This does the conditional part. Theta-join.
- if ( conditions == null || conditions.isSatisfied(r, execCxt) ) {
- count ++ ;
- out.add(r) ;
- }
- }
-
- if ( count == 0 && ( joinType == LEFT) )
- // Conditions on left?
- out.add(bindingLeft) ;
- }
-
- return new QueryIterPlainWrapper(out.iterator(), execCxt) ;
- }
-
- 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 ;
- }
-}
http://git-wip-us.apache.org/repos/asf/jena/blob/c7dafa2d/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 0a71cc1..68536bf 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
@@ -18,19 +18,93 @@
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 java.util.List ;
import org.apache.jena.atlas.iterator.Iter ;
import org.apache.jena.atlas.lib.DS ;
import org.apache.jena.sparql.algebra.Algebra ;
+import org.apache.jena.sparql.algebra.JoinType ;
+import org.apache.jena.sparql.algebra.Table ;
+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.QueryIterPlainWrapper ;
+import org.apache.jena.sparql.engine.main.OpExecutor ;
+import org.apache.jena.sparql.engine.ref.TableJoin ;
+import org.apache.jena.sparql.expr.ExprList ;
/** API to various join algorithms */
public class Join {
// See also package org.apache.jena.sparql.engine.index
+
+ /**
+ * Standard entry point to a join of two streams.
+ * This is not a substitution/index join.
+ * (See {@link OpExecutor} for streamed execution using substitution).
+ * @param left
+ * @param right
+ * @param execCxt
+ * @return QueryIterator
+ */
+ public static QueryIterator join(QueryIterator left, QueryIterator right, ExecutionContext execCxt) {
+ return joinWorker(left, right, PLAIN, null, execCxt) ;
+ }
+
+ /** Standard entry point to a left join of two streams.
+ * This is not a substitution/index join.
+ * (See {@link OpExecutor} for streamed execution using substitution).
+ *
+ * @param left
+ * @param right
+ * @param conditions
+ * @param execCxt
+ * @return QueryIterator
+ */
+ public static QueryIterator leftJoin(QueryIterator left, QueryIterator right, ExprList conditions, ExecutionContext execCxt) {
+ return joinWorker(left, right, LEFT, conditions, execCxt) ;
+ }
+
+
+ /**
+ * Standard entry point to a join of two streams.
+ * This is not a substitution/index join.
+ * (See {@link OpExecutor} for streamed execution using substitution).
+ * @param left
+ * @param right
+ * @param joinType
+ * @param conditions
+ * @param execCxt
+ * @return QueryIterator
+ */
+ public static QueryIterator joinWorker(QueryIterator left, QueryIterator right,
+ JoinType joinType, ExprList conditions,
+ ExecutionContext execCxt) {
+ // Catch easy cases.
+ // If left or right is a root, do fast.
+// if ( right.isEmpty() ) {
+// if ( joinType == PLAIN ) {
+// // No rows - no match
+// left.close() ;
+// return QueryIterNullIterator.create(execCxt) ;
+// }
+// else
+// // Left join - pass out left rows regardless of conditions.
+// return left ;
+// }
+//
+// if ( TableUnit.isTableUnit(right) )
+// return applyConditions(left, conditions, execCxt) ;
+// return joinWorkerN(left, right, joinType, conditions, execCxt) ;
+ // XXX TEMPORARY!
+ //throw new NotImplemented() ;
+ Table t = TableFactory.create(right) ;
+ return TableJoin.joinWorker(left, t, joinType, conditions, execCxt) ;
+ }
+
/** Evaluate a hash join. This code materializes the left into a probe table
* then hash joins from the right.
http://git-wip-us.apache.org/repos/asf/jena/blob/c7dafa2d/jena-arq/src/main/java/org/apache/jena/sparql/engine/main/iterator/QueryIterJoinBase.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/main/java/org/apache/jena/sparql/engine/main/iterator/QueryIterJoinBase.java b/jena-arq/src/main/java/org/apache/jena/sparql/engine/main/iterator/QueryIterJoinBase.java
index c346ecf..3fb00dc 100644
--- a/jena-arq/src/main/java/org/apache/jena/sparql/engine/main/iterator/QueryIterJoinBase.java
+++ b/jena-arq/src/main/java/org/apache/jena/sparql/engine/main/iterator/QueryIterJoinBase.java
@@ -18,62 +18,59 @@
package org.apache.jena.sparql.engine.main.iterator;
-import org.apache.jena.sparql.algebra.JoinType ;
-import org.apache.jena.sparql.algebra.Table ;
-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.TableJoin ;
-import org.apache.jena.sparql.engine.binding.Binding ;
-import org.apache.jena.sparql.engine.iterator.QueryIter ;
-import org.apache.jena.sparql.expr.ExprList ;
+import org.apache.jena.sparql.algebra.JoinType;
+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.QueryIter;
+import org.apache.jena.sparql.engine.join.Join;
+import org.apache.jena.sparql.expr.ExprList;
-/** Join or LeftJoin by calculating both sides, then doing the join
- * It usually better to use substitute algorithm (not this
- * QueryIterator in other words) as that is effectively indexing
- * from one side into the other. */
-public class QueryIterJoinBase extends QueryIter
-{
+/**
+ * Join or LeftJoin by calculating both sides, then doing the join It usually
+ * better to use substitute algorithm (not this QueryIterator in other words) as
+ * that is effectively indexing from one side into the other.
+ */
+public class QueryIterJoinBase extends QueryIter {
// This should be converted to a hash or sort-merge join.
- private final QueryIterator left ;
- private final QueryIterator right ;
- private final QueryIterator result ;
-
- protected QueryIterJoinBase(QueryIterator left, QueryIterator right, JoinType joinType, ExprList exprs, ExecutionContext execCxt)
- {
- super(execCxt) ;
- this.left = left ;
- this.right = right ;
- this.result = calc(left, right, joinType, exprs, execCxt) ;
- }
+ private final QueryIterator left;
+ private final QueryIterator right;
+ private final QueryIterator result;
- private static QueryIterator calc(QueryIterator left, QueryIterator right, JoinType joinType, ExprList exprs, ExecutionContext execCxt) {
- Table tableRight = TableFactory.create(right) ;
- return TableJoin.joinWorker(left, tableRight, joinType, exprs, execCxt) ;
+ protected QueryIterJoinBase(QueryIterator left, QueryIterator right, JoinType joinType, ExprList exprs, ExecutionContext execCxt) {
+ super(execCxt);
+ this.left = left;
+ this.right = right;
+ this.result = calc(left, right, joinType, exprs, execCxt);
+ }
+ private static QueryIterator calc(QueryIterator left, QueryIterator right,
+ JoinType joinType, ExprList exprs,
+ ExecutionContext execCxt) {
+ return Join.joinWorker(left, right, joinType, exprs, execCxt);
}
-
+
@Override
protected boolean hasNextBinding() {
- return result.hasNext() ;
+ return result.hasNext();
}
@Override
protected Binding moveToNextBinding() {
- return result.nextBinding() ;
+ return result.nextBinding();
}
@Override
protected void closeIterator() {
- left.close() ;
- right.close() ;
- result.close() ;
+ left.close();
+ right.close();
+ result.close();
}
@Override
protected void requestCancel() {
- left.cancel() ;
- right.cancel() ;
- result.cancel() ;
+ left.cancel();
+ right.cancel();
+ result.cancel();
}
}
http://git-wip-us.apache.org/repos/asf/jena/blob/c7dafa2d/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 d79fe12..0f22aed 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
@@ -35,7 +35,6 @@ import org.apache.jena.sparql.core.VarExprList ;
import org.apache.jena.sparql.engine.ExecutionContext ;
import org.apache.jena.sparql.engine.QueryIterator ;
import org.apache.jena.sparql.engine.ResultSetStream ;
-import org.apache.jena.sparql.engine.TableJoin ;
import org.apache.jena.sparql.engine.binding.Binding ;
import org.apache.jena.sparql.engine.iterator.* ;
import org.apache.jena.sparql.engine.main.QC ;
http://git-wip-us.apache.org/repos/asf/jena/blob/c7dafa2d/jena-arq/src/main/java/org/apache/jena/sparql/engine/ref/TableJoin.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/main/java/org/apache/jena/sparql/engine/ref/TableJoin.java b/jena-arq/src/main/java/org/apache/jena/sparql/engine/ref/TableJoin.java
new file mode 100644
index 0000000..483764e
--- /dev/null
+++ b/jena-arq/src/main/java/org/apache/jena/sparql/engine/ref/TableJoin.java
@@ -0,0 +1,106 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.jena.sparql.engine.ref;
+
+import static org.apache.jena.sparql.algebra.JoinType.* ;
+
+import java.util.ArrayList ;
+import java.util.Iterator ;
+import java.util.List ;
+
+import org.apache.jena.sparql.algebra.Algebra ;
+import org.apache.jena.sparql.algebra.JoinType ;
+import org.apache.jena.sparql.algebra.Table ;
+import org.apache.jena.sparql.algebra.table.TableUnit ;
+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.QueryIterNullIterator ;
+import org.apache.jena.sparql.engine.iterator.QueryIterPlainWrapper ;
+import org.apache.jena.sparql.expr.Expr ;
+import org.apache.jena.sparql.expr.ExprList ;
+
+/** Table join - this only happens if the patterns can not be streamed.
+ * This code is simple!
+ * Primarily for use in testing and also the reference query engine which is designed for simplicity, not performance.
+ */
+public class TableJoin
+{
+ public static QueryIterator join(QueryIterator left, Table right, ExprList condition, ExecutionContext execCxt) {
+ return joinWorker(left, right, PLAIN, condition, execCxt) ;
+ }
+
+ public static QueryIterator leftJoin(QueryIterator left, Table right, ExprList condition, ExecutionContext execCxt) {
+ return joinWorker(left, right, LEFT, condition, execCxt) ;
+ }
+
+ public static QueryIterator joinWorker(QueryIterator left, Table right, JoinType joinType, ExprList conditions, ExecutionContext execCxt) {
+ if ( right.isEmpty() ) {
+ if ( joinType == PLAIN ) {
+ // No rows - no match
+ left.close() ;
+ return QueryIterNullIterator.create(execCxt) ;
+ }
+ else
+ // Left join - pass out left rows regardless of conditions.
+ return left ;
+ }
+
+ if ( TableUnit.isTableUnit(right) )
+ return applyConditions(left, conditions, execCxt) ;
+ return joinWorkerN(left, right, joinType, conditions, execCxt) ;
+ }
+
+ private static QueryIterator joinWorkerN(QueryIterator left, Table right, JoinType joinType, ExprList conditions, ExecutionContext execCxt) {
+ // We could hash the right except we don't know much about columns.
+
+ List<Binding> out = new ArrayList<>() ;
+ for ( ; left.hasNext() ; ) {
+ Binding bindingLeft = left.next() ;
+ int count = 0 ;
+ for (Iterator<Binding> iter = right.rows() ; iter.hasNext();) {
+ Binding bindingRight = iter.next() ;
+ Binding r = Algebra.merge(bindingLeft, bindingRight) ;
+
+ if ( r == null )
+ continue ;
+ // This does the conditional part. Theta-join.
+ if ( conditions == null || conditions.isSatisfied(r, execCxt) ) {
+ count ++ ;
+ out.add(r) ;
+ }
+ }
+
+ if ( count == 0 && ( joinType == LEFT) )
+ // Conditions on left?
+ out.add(bindingLeft) ;
+ }
+
+ return new QueryIterPlainWrapper(out.iterator(), execCxt) ;
+ }
+
+ 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 ;
+ }
+}
[10/20] jena git commit: Rename in JoinType.
Posted by an...@apache.org.
Rename in JoinType.
Project: http://git-wip-us.apache.org/repos/asf/jena/repo
Commit: http://git-wip-us.apache.org/repos/asf/jena/commit/ed70d5ca
Tree: http://git-wip-us.apache.org/repos/asf/jena/tree/ed70d5ca
Diff: http://git-wip-us.apache.org/repos/asf/jena/diff/ed70d5ca
Branch: refs/heads/master
Commit: ed70d5caef1ceb8656a2a70fa5ae3c8e851b12ef
Parents: 5dfc29b
Author: Andy Seaborne <an...@apache.org>
Authored: Tue Sep 8 14:19:03 2015 +0100
Committer: Andy Seaborne <an...@apache.org>
Committed: Tue Sep 8 14:19:03 2015 +0100
----------------------------------------------------------------------
.../org/apache/jena/sparql/engine/main/iterator/QueryIterJoin.java | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/jena/blob/ed70d5ca/jena-arq/src/main/java/org/apache/jena/sparql/engine/main/iterator/QueryIterJoin.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/main/java/org/apache/jena/sparql/engine/main/iterator/QueryIterJoin.java b/jena-arq/src/main/java/org/apache/jena/sparql/engine/main/iterator/QueryIterJoin.java
index fdefc44..2b45202 100644
--- a/jena-arq/src/main/java/org/apache/jena/sparql/engine/main/iterator/QueryIterJoin.java
+++ b/jena-arq/src/main/java/org/apache/jena/sparql/engine/main/iterator/QueryIterJoin.java
@@ -27,6 +27,6 @@ public class QueryIterJoin extends QueryIterJoinBase
{
public QueryIterJoin(QueryIterator left, QueryIterator right, ExecutionContext qCxt)
{
- super(left, right, JoinType.PLAIN, null, qCxt) ;
+ super(left, right, JoinType.INNER, null, qCxt) ;
}
}
[19/20] jena git commit: Uss Join Use "Join" for OpJoin and
OpLeftJoin.
Posted by an...@apache.org.
Uss Join Use "Join" for OpJoin and OpLeftJoin.
Project: http://git-wip-us.apache.org/repos/asf/jena/repo
Commit: http://git-wip-us.apache.org/repos/asf/jena/commit/07a097c9
Tree: http://git-wip-us.apache.org/repos/asf/jena/tree/07a097c9
Diff: http://git-wip-us.apache.org/repos/asf/jena/diff/07a097c9
Branch: refs/heads/master
Commit: 07a097c9e3c0286f3aab93f7a2a8a50b9412b2a6
Parents: e7780fb
Author: Andy Seaborne <an...@apache.org>
Authored: Tue Sep 8 17:56:51 2015 +0100
Committer: Andy Seaborne <an...@apache.org>
Committed: Tue Sep 8 17:56:51 2015 +0100
----------------------------------------------------------------------
.../main/java/org/apache/jena/sparql/engine/main/OpExecutor.java | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/jena/blob/07a097c9/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 801a48e..3929975 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
@@ -214,7 +214,7 @@ public class OpExecutor
QueryIterator left = exec(opJoin.getLeft(), qIter1) ;
QueryIterator right = exec(opJoin.getRight(), qIter2) ;
- QueryIterator qIter = new QueryIterJoin(left, right, execCxt) ;
+ QueryIterator qIter = Join.join(left, right, execCxt) ;
return qIter ;
}
QueryIterator left = exec(opJoin.getLeft(), input) ;
@@ -329,7 +329,7 @@ public class OpExecutor
return opTable.getTable().iterator(execCxt) ;
}
QueryIterator qIterT = opTable.getTable().iterator(execCxt) ;
- QueryIterator qIter = new QueryIterJoin(input, qIterT, execCxt) ;
+ QueryIterator qIter = Join.join(input, qIterT, execCxt) ;
return qIter ;
}
[17/20] jena git commit: Factory operations to catch simple cases.
Posted by an...@apache.org.
Factory operations to catch simple cases.
Project: http://git-wip-us.apache.org/repos/asf/jena/repo
Commit: http://git-wip-us.apache.org/repos/asf/jena/commit/8e999b61
Tree: http://git-wip-us.apache.org/repos/asf/jena/tree/8e999b61
Diff: http://git-wip-us.apache.org/repos/asf/jena/diff/8e999b61
Branch: refs/heads/master
Commit: 8e999b61c42f0f2af8c273ad11b8addf37ae2b8a
Parents: 7e25172
Author: Andy Seaborne <an...@apache.org>
Authored: Tue Sep 8 17:56:11 2015 +0100
Committer: Andy Seaborne <an...@apache.org>
Committed: Tue Sep 8 17:56:11 2015 +0100
----------------------------------------------------------------------
.../sparql/engine/join/QueryIterHashJoin.java | 57 ++++++++++++++++++--
1 file changed, 52 insertions(+), 5 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/jena/blob/8e999b61/jena-arq/src/main/java/org/apache/jena/sparql/engine/join/QueryIterHashJoin.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/main/java/org/apache/jena/sparql/engine/join/QueryIterHashJoin.java b/jena-arq/src/main/java/org/apache/jena/sparql/engine/join/QueryIterHashJoin.java
index cf8a520..1b4b29a 100644
--- a/jena-arq/src/main/java/org/apache/jena/sparql/engine/join/QueryIterHashJoin.java
+++ b/jena-arq/src/main/java/org/apache/jena/sparql/engine/join/QueryIterHashJoin.java
@@ -19,12 +19,17 @@
package org.apache.jena.sparql.engine.join;
import java.util.Iterator ;
+import java.util.List ;
+import org.apache.jena.atlas.iterator.Iter ;
import org.apache.jena.sparql.algebra.Algebra ;
+import org.apache.jena.sparql.core.Var ;
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.QueryIter2 ;
+import org.apache.jena.sparql.engine.iterator.QueryIterNullIterator ;
+import org.apache.jena.sparql.engine.iterator.QueryIterPeek ;
/** Hash join. This code materializes the left into a probe table
* then hash joins from the right.
@@ -49,8 +54,53 @@ public class QueryIterHashJoin extends QueryIter2 {
private Binding slot = null ;
private boolean finished = false ;
- public QueryIterHashJoin(JoinKey joinKey, QueryIterator left, QueryIterator right, ExecutionContext cxt) {
- super(left, right, cxt) ;
+ /**
+ * Create a hashjoin QueryIterator.
+ * @param joinKey Join key - if null, one is guessed by snooping the input QueryIterators
+ * @param left
+ * @param right
+ * @param execCxt
+ * @return QueryIterator
+ */
+ public static QueryIterator create(JoinKey joinKey, QueryIterator left, QueryIterator right, ExecutionContext execCxt) {
+ // Easy cases.
+ if ( ! left.hasNext() || ! right.hasNext() ) {
+ left.close() ;
+ right.close() ;
+ return QueryIterNullIterator.create(execCxt) ;
+ }
+ return new QueryIterHashJoin(joinKey, left, right, execCxt) ;
+ }
+
+ /**
+ * Create a hashjoin QueryIterator.
+ * @param left
+ * @param right
+ * @param execCxt
+ * @return QueryIterator
+ */
+
+ public static QueryIterator create(QueryIterator left, QueryIterator right, ExecutionContext execCxt) {
+ return create(null, left, right, execCxt) ;
+ }
+
+ private QueryIterHashJoin(JoinKey joinKey, QueryIterator left, QueryIterator right, ExecutionContext execCxt) {
+ super(left, right, execCxt) ;
+
+ if ( joinKey == null ) {
+ QueryIterPeek pLeft = QueryIterPeek.create(left, execCxt) ;
+ QueryIterPeek pRight = QueryIterPeek.create(right, execCxt) ;
+
+ Binding bLeft = pLeft.peek() ;
+ Binding bRight = pRight.peek() ;
+
+ List<Var> varsLeft = Iter.toList(bLeft.vars()) ;
+ List<Var> varsRight = Iter.toList(bRight.vars()) ;
+ joinKey = JoinKey.create(varsLeft, varsRight) ;
+ left = pLeft ;
+ right = pRight ;
+ }
+
this.joinKey = joinKey ;
this.iterRight = right ;
this.hashTable = new HashProbeTable(joinKey) ;
@@ -119,9 +169,6 @@ public class QueryIterHashJoin extends QueryIter2 {
if (r != null) {
s_countResults ++ ;
return r ;
- } else {
- // XXX LeftJoin
- // return rowLeft ;
}
}
}
[20/20] jena git commit: Merge branch 'Jena-1023_join_library'
Posted by an...@apache.org.
Merge branch 'Jena-1023_join_library'
Project: http://git-wip-us.apache.org/repos/asf/jena/repo
Commit: http://git-wip-us.apache.org/repos/asf/jena/commit/0fcfbe73
Tree: http://git-wip-us.apache.org/repos/asf/jena/tree/0fcfbe73
Diff: http://git-wip-us.apache.org/repos/asf/jena/diff/0fcfbe73
Branch: refs/heads/master
Commit: 0fcfbe7395ffae3ca18f1e0774d8e4819004241a
Parents: 668db14 07a097c
Author: Andy Seaborne <an...@apache.org>
Authored: Tue Sep 8 18:11:23 2015 +0100
Committer: Andy Seaborne <an...@apache.org>
Committed: Tue Sep 8 18:11:23 2015 +0100
----------------------------------------------------------------------
----------------------------------------------------------------------
[04/20] jena git commit: Drop into isomorphicsm testing if not simply
equivalent.
Posted by an...@apache.org.
Drop into isomorphicsm testing if not simply equivalent.
Project: http://git-wip-us.apache.org/repos/asf/jena/repo
Commit: http://git-wip-us.apache.org/repos/asf/jena/commit/985c1323
Tree: http://git-wip-us.apache.org/repos/asf/jena/tree/985c1323
Diff: http://git-wip-us.apache.org/repos/asf/jena/diff/985c1323
Branch: refs/heads/master
Commit: 985c1323680fdab1df9495d21f8a94f4da46f8bf
Parents: 07fcde9
Author: Andy Seaborne <an...@apache.org>
Authored: Tue Sep 8 11:45:43 2015 +0100
Committer: Andy Seaborne <an...@apache.org>
Committed: Tue Sep 8 11:45:43 2015 +0100
----------------------------------------------------------------------
.../java/org/apache/jena/sparql/resultset/ResultSetCompare.java | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/jena/blob/985c1323/jena-arq/src/main/java/org/apache/jena/sparql/resultset/ResultSetCompare.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/main/java/org/apache/jena/sparql/resultset/ResultSetCompare.java b/jena-arq/src/main/java/org/apache/jena/sparql/resultset/ResultSetCompare.java
index 34e793a..eb3c329 100644
--- a/jena-arq/src/main/java/org/apache/jena/sparql/resultset/ResultSetCompare.java
+++ b/jena-arq/src/main/java/org/apache/jena/sparql/resultset/ResultSetCompare.java
@@ -133,11 +133,12 @@ public class ResultSetCompare
ResultSetRewindable rs1a = ResultSetFactory.makeRewindable(rs1) ;
ResultSetRewindable rs2a = ResultSetFactory.makeRewindable(rs2) ;
+ // Aligned rows
if ( equivalent(convert(rs1a), convert(rs2a), new BNodeIso(NodeUtils.sameTerm)) )
return true ;
rs1a.reset() ;
rs2a.reset() ;
- return isomorphic(rs1, rs2) ;
+ return isomorphic(rs1a, rs2a) ;
}
[09/20] jena git commit: Nest loop leftJoin to fit with cancelation
etc.
Posted by an...@apache.org.
Nest loop leftJoin to fit with cancelation etc.
Project: http://git-wip-us.apache.org/repos/asf/jena/repo
Commit: http://git-wip-us.apache.org/repos/asf/jena/commit/5dfc29bd
Tree: http://git-wip-us.apache.org/repos/asf/jena/tree/5dfc29bd
Diff: http://git-wip-us.apache.org/repos/asf/jena/diff/5dfc29bd
Branch: refs/heads/master
Commit: 5dfc29bdb5acd7abf54d78dcbefb6f031e830a8e
Parents: 8656a45
Author: Andy Seaborne <an...@apache.org>
Authored: Tue Sep 8 14:18:44 2015 +0100
Committer: Andy Seaborne <an...@apache.org>
Committed: Tue Sep 8 14:18:44 2015 +0100
----------------------------------------------------------------------
.../join/QueryIterNestedLoopLeftJoin.java | 135 +++++++++++++++++++
1 file changed, 135 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/jena/blob/5dfc29bd/jena-arq/src/main/java/org/apache/jena/sparql/engine/join/QueryIterNestedLoopLeftJoin.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/main/java/org/apache/jena/sparql/engine/join/QueryIterNestedLoopLeftJoin.java b/jena-arq/src/main/java/org/apache/jena/sparql/engine/join/QueryIterNestedLoopLeftJoin.java
new file mode 100644
index 0000000..338f6e9
--- /dev/null
+++ b/jena-arq/src/main/java/org/apache/jena/sparql/engine/join/QueryIterNestedLoopLeftJoin.java
@@ -0,0 +1,135 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.jena.sparql.engine.join;
+
+import java.util.Iterator;
+import java.util.List;
+
+import org.apache.jena.atlas.iterator.Iter;
+import org.apache.jena.sparql.algebra.Algebra;
+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.QueryIter2;
+import org.apache.jena.sparql.expr.ExprList ;
+
+/**
+ * Nested Loop left Join (materializing on the right, streaming on the left)
+ * A simple, dependable join.
+ * <p>
+ * See {@link Join#nestedLoopLeftJoinBasic} for a very simple implementation for
+ * testing purposes only.
+ */
+public class QueryIterNestedLoopLeftJoin extends QueryIter2 {
+ // XXX Can we materialise left instead?
+
+ private long s_countLHS = 0;
+ private long s_countRHS = 0;
+ private long s_countResults = 0;
+
+ private final ExprList conditions;
+ private final List<Binding> rightRows;
+ private Iterator<Binding> right = null;
+ private QueryIterator left;
+ private Binding rowLeft = null;
+ private boolean foundMatch ;
+
+ private Binding slot = null;
+ private boolean finished = false;
+
+ public QueryIterNestedLoopLeftJoin(QueryIterator left, QueryIterator right, ExprList exprList, ExecutionContext cxt) {
+ super(left, right, cxt);
+ conditions = exprList ;
+ rightRows = Iter.toList(right);
+ s_countRHS = rightRows.size();
+ this.left = left;
+ }
+
+ @Override
+ protected boolean hasNextBinding() {
+ if ( finished )
+ return false;
+ if ( slot == null ) {
+ slot = moveToNextBindingOrNull();
+ if ( slot == null ) {
+ close();
+ return false;
+ }
+ }
+ return true;
+ }
+
+ @Override
+ protected Binding moveToNextBinding() {
+ Binding r = slot;
+ slot = null;
+ return r;
+ }
+
+ protected Binding moveToNextBindingOrNull() {
+ if ( isFinished() )
+ return null;
+
+ for ( ;; ) { // For rows from the left
+ if ( rowLeft == null ) {
+ if ( left.hasNext() ) {
+ rowLeft = left.next();
+ foundMatch = false ;
+ s_countLHS++;
+ right = rightRows.iterator();
+ } else
+ return null;
+ }
+
+ while (right.hasNext()) {
+ Binding rowRight = right.next();
+ Binding r = Algebra.merge(rowLeft, rowRight);
+ if ( r != null && applyConditions(r) ) {
+ s_countResults++;
+ foundMatch = true ;
+ return r;
+ }
+ }
+ if ( ! foundMatch ) {
+ s_countResults++;
+ Binding r = rowLeft ;
+ rowLeft = null;
+ return r ;
+ }
+ rowLeft = null;
+ }
+ }
+
+ private boolean applyConditions(Binding binding) {
+ if ( conditions == null )
+ return true ;
+ return conditions.isSatisfied(binding, getExecContext()) ;
+ }
+
+ @Override
+ protected void requestSubCancel() {}
+
+ @Override
+ protected void closeSubIterator() {
+ if ( JoinLib.JOIN_EXPLAIN ) {
+ String x = String.format("InnerLoopJoin: LHS=%d RHS=%d Results=%d", s_countLHS, s_countRHS, s_countResults);
+ System.out.println(x);
+ }
+ }
+}
[03/20] jena git commit: Move join test package to aling to main.
Start leftjoin tests.
Posted by an...@apache.org.
Move join test package to aling to main. Start leftjoin tests.
Project: http://git-wip-us.apache.org/repos/asf/jena/repo
Commit: http://git-wip-us.apache.org/repos/asf/jena/commit/07fcde9e
Tree: http://git-wip-us.apache.org/repos/asf/jena/tree/07fcde9e
Diff: http://git-wip-us.apache.org/repos/asf/jena/diff/07fcde9e
Branch: refs/heads/master
Commit: 07fcde9e0be07ab10edb1bfb75beb5bd652948b9
Parents: 804f2be
Author: Andy Seaborne <an...@apache.org>
Authored: Tue Sep 8 10:22:57 2015 +0100
Committer: Andy Seaborne <an...@apache.org>
Committed: Tue Sep 8 10:22:57 2015 +0100
----------------------------------------------------------------------
.../java/org/apache/jena/sparql/TC_General.java | 2 +-
.../apache/jena/sparql/engine/TS_Engine.java | 3 +-
.../apache/jena/sparql/engine/TestTableLib.java | 119 ----------
.../engine/join/AbstractTestInnerJoin.java | 170 +++++++++++++
.../sparql/engine/join/AbstractTestJoin.java | 101 ++++++++
.../engine/join/AbstractTestLeftJoin.java | 170 +++++++++++++
.../apache/jena/sparql/engine/join/TS_Join.java | 34 +++
.../jena/sparql/engine/join/TestHashJoin.java | 38 +++
.../sparql/engine/join/TestJoinNestedLoop.java | 34 +++
.../engine/join/TestJoinNestedLoopSimple.java | 34 +++
.../jena/sparql/engine/join/TestJoinSimple.java | 34 +++
.../sparql/engine/join/TestLeftJoinSimple.java | 34 +++
.../jena/sparql/join/AbstractTestJoin.java | 236 -------------------
.../org/apache/jena/sparql/join/TS_Join.java | 34 ---
.../apache/jena/sparql/join/TestHashJoin.java | 38 ---
.../jena/sparql/join/TestJoinNestedLoop.java | 34 ---
.../sparql/join/TestJoinNestedLoopSimple.java | 34 ---
.../apache/jena/sparql/join/TestJoinSimple.java | 34 ---
18 files changed, 652 insertions(+), 531 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/jena/blob/07fcde9e/jena-arq/src/test/java/org/apache/jena/sparql/TC_General.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/test/java/org/apache/jena/sparql/TC_General.java b/jena-arq/src/test/java/org/apache/jena/sparql/TC_General.java
index 7c67a5d..429387e 100644
--- a/jena-arq/src/test/java/org/apache/jena/sparql/TC_General.java
+++ b/jena-arq/src/test/java/org/apache/jena/sparql/TC_General.java
@@ -25,12 +25,12 @@ import org.apache.jena.sparql.algebra.optimize.TS_Optimization ;
import org.apache.jena.sparql.api.TS_API ;
import org.apache.jena.sparql.core.TS_Core ;
import org.apache.jena.sparql.engine.TS_Engine ;
+import org.apache.jena.sparql.engine.join.TS_Join ;
import org.apache.jena.sparql.expr.E_Function ;
import org.apache.jena.sparql.expr.NodeValue ;
import org.apache.jena.sparql.expr.TS_Expr ;
import org.apache.jena.sparql.function.user.TS_UserFunctions ;
import org.apache.jena.sparql.graph.TS_Graph ;
-import org.apache.jena.sparql.join.TS_Join ;
import org.apache.jena.sparql.lang.TS_Lang ;
import org.apache.jena.sparql.modify.TS_Update ;
import org.apache.jena.sparql.negation.TS_Negation ;
http://git-wip-us.apache.org/repos/asf/jena/blob/07fcde9e/jena-arq/src/test/java/org/apache/jena/sparql/engine/TS_Engine.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/test/java/org/apache/jena/sparql/engine/TS_Engine.java b/jena-arq/src/test/java/org/apache/jena/sparql/engine/TS_Engine.java
index 889acf9..d7b386c 100644
--- a/jena-arq/src/test/java/org/apache/jena/sparql/engine/TS_Engine.java
+++ b/jena-arq/src/test/java/org/apache/jena/sparql/engine/TS_Engine.java
@@ -22,13 +22,14 @@ import org.apache.jena.sparql.engine.binding.TestBindingStreams ;
import org.apache.jena.sparql.engine.http.TestQueryEngineHTTP ;
import org.apache.jena.sparql.engine.http.TestService ;
import org.apache.jena.sparql.engine.iterator.TS_QueryIterators ;
+import org.apache.jena.sparql.engine.ref.TestTableJoin ;
import org.junit.runner.RunWith ;
import org.junit.runners.Suite ;
@RunWith(Suite.class)
@Suite.SuiteClasses( {
TestBindingStreams.class
- , TestTableLib.class
+ , TestTableJoin.class
, TS_QueryIterators.class
, TestService.class
, TestQueryEngineHTTP.class
http://git-wip-us.apache.org/repos/asf/jena/blob/07fcde9e/jena-arq/src/test/java/org/apache/jena/sparql/engine/TestTableLib.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/test/java/org/apache/jena/sparql/engine/TestTableLib.java b/jena-arq/src/test/java/org/apache/jena/sparql/engine/TestTableLib.java
deleted file mode 100644
index 88f8cf0..0000000
--- a/jena-arq/src/test/java/org/apache/jena/sparql/engine/TestTableLib.java
+++ /dev/null
@@ -1,119 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.jena.sparql.engine;
-
-import java.util.HashSet ;
-import java.util.Set ;
-
-import org.apache.jena.atlas.junit.BaseTest ;
-import org.apache.jena.query.ARQ ;
-import org.apache.jena.query.ResultSet ;
-import org.apache.jena.query.ResultSetFactory ;
-import org.apache.jena.sparql.algebra.Table ;
-import org.apache.jena.sparql.algebra.table.TableEmpty ;
-import org.apache.jena.sparql.algebra.table.TableN ;
-import org.apache.jena.sparql.algebra.table.TableUnit ;
-import org.apache.jena.sparql.engine.ExecutionContext ;
-import org.apache.jena.sparql.engine.QueryIterator ;
-import org.apache.jena.sparql.engine.TableJoin ;
-import org.apache.jena.sparql.expr.ExprList ;
-import org.apache.jena.sparql.resultset.ResultSetCompare ;
-import org.apache.jena.sparql.sse.SSE ;
-import org.junit.Test ;
-
-public class TestTableLib extends BaseTest
-{
- Table unit = new TableUnit() ;
- Table zero = new TableEmpty() ;
- Table zeroData = SSE.parseTable("(table)") ;
- Table unitData = SSE.parseTable("(table (row))") ;
- Table data1 = SSE.parseTable("(table (row (?a 1) (?b 2)))") ;
- Table data2 = SSE.parseTable("(table (row (?a 1) (?c 3)) (row (?a 9) (?c 5)) )") ;
- Table data3 = SSE.parseTable("(table (row (?a 1) (?c 3)) (row (?a 1) (?c 4)) (row (?a 9) (?c 5)) )") ;
-
- Table data1J2 = SSE.parseTable("(table (row (?a 1) (?b 2) (?c 3)) )") ;
- Table data1LJ2 = SSE.parseTable("(table (row (?a 1) (?b 2) (?c 3)) (row (?a 9) (?c 5)) )") ;
- Table data2LJ1 = SSE.parseTable("(table (row (?a 1) (?b 2) (?c 3)) )") ;
-
- Table data1J3 = SSE.parseTable("(table (row (?a 1) (?b 2) (?c 3)) (row (?a 1) (?b 2) (?c 4)) )") ;
-
- @Test public void table_01() { test(unit, zero, true, null, zero) ; }
- @Test public void table_02() { test(zero, unit, true, null, zero) ; }
- @Test public void table_03() { test(unit, zero, false, null, unit) ; }
- @Test public void table_04() { test(zero, unit, false, null, zero) ; }
- // Same again but with non-special tables.
- @Test public void table_05() { test(unitData, zeroData, true, null, zeroData) ; }
- @Test public void table_06() { test(zeroData, unitData, true, null, zeroData) ; }
- @Test public void table_07() { test(unitData, zeroData, false, null, unitData) ; }
- @Test public void table_08() { test(zeroData, unitData, false, null, zeroData) ; }
-
- @Test public void table_10() { test(data1, zero, true, null, zero) ; }
- @Test public void table_11() { test(zero, data1, true, null, zero) ; }
- @Test public void table_12() { test(data1, zero, false, null, data1) ; }
- @Test public void table_13() { test(zero, data1, false, null, zero) ; }
-
- @Test public void table_14() { test(data1, zeroData, true, null, zeroData) ; }
- @Test public void table_15() { test(zeroData, data1, true, null, zeroData) ; }
- @Test public void table_16() { test(data1, zeroData, false, null, data1) ; }
- @Test public void table_17() { test(zeroData, data1, false, null, zeroData) ; }
-
- @Test public void table_18() { test(data2, unitData, true, null, data2) ; }
- @Test public void table_19() { test(unitData, data2, true, null, data2) ; }
-
- @Test public void table_20() { test(data1, data2, true, null, data1J2) ; }
- @Test public void table_21() { test(data2, data1, true, null, data1J2) ; }
- @Test public void table_22() { test(data1, data2, false, null, data1LJ2) ; }
- @Test public void table_23() { test(data2, data1, false, null, data2LJ1) ; }
-
- @Test public void table_24() { test(data1, data3, true, null, data1J3) ; }
- @Test public void table_25() { test(data3, data1, true, null, data1J3) ; }
-
- private void test(Table left, Table right, boolean normalJoin, ExprList exprs, Table expected) {
- ExecutionContext execCxt = new ExecutionContext(ARQ.getContext(), null, null, null) ;
- QueryIterator leftIter = left.iterator(execCxt) ;
- QueryIterator qIter = normalJoin
- ? TableJoin.join(leftIter, right, exprs, execCxt)
- : TableJoin.leftJoin(leftIter, right, exprs, execCxt) ;
-
- // Order issues
-
- Set<String> vars1 = new HashSet<>() ;
- vars1.addAll(left.getVarNames()) ;
- vars1.addAll(right.getVarNames()) ;
-
- TableN results = new TableN(qIter) ;
- boolean b = TableCompare.equalsByTerm(expected, results) ;
- if ( !b ) {
- System.out.println("** Expected") ;
- System.out.println(expected) ;
- System.out.println("** Actual") ;
- System.out.println(results) ;
- }
- assertTrue(b) ;
- }
-
- static class TableCompare {
- public static boolean equalsByTerm(Table table1, Table table2) {
- ResultSet rs1 = ResultSetFactory.create(table1.iterator(null), table1.getVarNames()) ;
- ResultSet rs2 = ResultSetFactory.create(table2.iterator(null), table2.getVarNames()) ;
- return ResultSetCompare.equalsByTerm(rs1, rs2) ;
- }
- }
-
-}
http://git-wip-us.apache.org/repos/asf/jena/blob/07fcde9e/jena-arq/src/test/java/org/apache/jena/sparql/engine/join/AbstractTestInnerJoin.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/test/java/org/apache/jena/sparql/engine/join/AbstractTestInnerJoin.java b/jena-arq/src/test/java/org/apache/jena/sparql/engine/join/AbstractTestInnerJoin.java
new file mode 100644
index 0000000..f5a1bdc
--- /dev/null
+++ b/jena-arq/src/test/java/org/apache/jena/sparql/engine/join/AbstractTestInnerJoin.java
@@ -0,0 +1,170 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.jena.sparql.engine.join;
+
+import org.apache.jena.sparql.algebra.Table ;
+import org.apache.jena.sparql.core.Var ;
+import org.apache.jena.sparql.engine.join.JoinKey ;
+import org.junit.Test ;
+
+/** Tests for inner/equi joins */
+public abstract class AbstractTestInnerJoin extends AbstractTestJoin {
+
+ @Override
+ protected void executeTest(JoinKey joinKey, Table left, Table right, Table expectedResults) {
+ executeTestJoin("1", joinKey, left, right, expectedResults) ;
+ executeTestJoin("2", joinKey, right, left, expectedResults) ;
+ }
+
+ static Var var_a = Var.alloc("a") ;
+ static Var var_b = Var.alloc("b") ;
+ static Var var_c = Var.alloc("c") ;
+ static Var var_d = Var.alloc("d") ;
+
+ static Table table0() { return parseTableInt("(table)") ; }
+
+ // Table of one row and no colums.
+ static Table table1() {
+ return parseTableInt("(table (row))") ; }
+
+ static Table tableD1() {
+ return parseTableInt("(table",
+ " (row (?a 1) (?b 2))",
+ " (row (?a 1) (?b 3))",
+ " (row (?a 1) (?b 2))",
+ ")") ;
+ }
+
+ static Table tableD2() {
+ return parseTableInt("(table",
+ " (row (?a 0) (?d 8))",
+ " (row (?a 1) (?c 9))",
+ ")") ;
+ }
+
+ static Table tableD3() {
+ return parseTableInt("(table",
+ " (row (?a 1) (?c 9) (?b 2))",
+ " (row (?a 1) (?c 9) (?b 3))",
+ " (row (?a 1) (?c 9) (?b 2))",
+ ")") ;
+ }
+
+ static Table tableD4() {
+ return parseTableInt("(table",
+ " (row (?a 1) (?b 2))",
+ " (row (?a 1) (?b 3))",
+ " (row (?a 4) (?b 4))",
+ " (row (?a 4) (?b 5))",
+ ")") ;
+ }
+
+ static Table tableD5() {
+ return parseTableInt("(table",
+ " (row (?a 4) (?c 4))",
+ " (row (?a 4) (?c 5))",
+ " (row (?a 6) (?c 5))",
+ ")") ;
+ }
+
+ static Table tableD6() {
+ return parseTableInt("(table",
+ " (row (?a 1) (?c 2))",
+ " (row (?a 1) (?c 3))",
+ " (row (?a 4) (?c 4))",
+ " (row (?a 4) (?c 5))",
+ ")") ;
+ }
+
+ static Table tableD4x5() {
+ return parseTableInt("(table",
+ " (row (?a 4) (?c 4) (?b 4))",
+ " (row (?a 4) (?c 4) (?b 5))",
+ " (row (?a 4) (?c 5) (?b 4))",
+ " (row (?a 4) (?c 5) (?b 5))",
+ ")") ;
+ }
+
+ static Table tableD4x6() {
+ return parseTableInt("(table",
+ " (row (?a 1) (?c 2) (?b 2))",
+ " (row (?a 1) (?c 2) (?b 3))",
+ " (row (?a 1) (?c 3) (?b 2))",
+ " (row (?a 1) (?c 3) (?b 3))",
+ " (row (?a 4) (?c 4) (?b 4))",
+ " (row (?a 4) (?c 4) (?b 5))",
+ " (row (?a 4) (?c 5) (?b 4))",
+ " (row (?a 4) (?c 5) (?b 5))",
+ ")") ;
+ }
+
+ // Disjoint.
+ static Table tableD8() {
+ return parseTableInt("(table",
+ " (row (?x 10))",
+ " (row (?z 11))",
+ ")") ;
+ }
+
+ // Table8 crossproduct table2
+ static Table tableD8x2() {
+ return parseTableInt("(table",
+ " (row (?a 0) (?d 8) (?z 11))",
+ " (row (?a 0) (?d 8) (?x 10))",
+ " (row (?a 1) (?c 9) (?z 11))",
+ " (row (?a 1) (?c 9) (?x 10))",
+ ")") ;
+ }
+
+ @Test public void join_00() { testJoin("a", table0(), table0(), table0()) ; }
+ @Test public void join_00a() { testJoin("a", table1(), table0(), table0()) ; }
+ @Test public void join_00b() { testJoin("a", tableD1(), table1(), tableD1()) ; }
+ @Test public void join_00c() { testJoin("z", tableD1(), table1(), tableD1()) ; }
+
+ @Test public void join_01() { testJoin("a", table0(), tableD2(), table0()) ; }
+ @Test public void join_02() { testJoin("a", tableD1(), table0(), table0()) ; }
+ @Test public void join_03() { testJoin("a", tableD1(), tableD2(), tableD3()) ; }
+
+ // Identity.
+ @Test public void join_04() { testJoin("a", tableD2(), table1(), tableD2()) ; }
+ @Test public void join_05() { testJoin("a", table1(), tableD2(), tableD2()) ; }
+ // Identity, keymiss
+ @Test public void join_06() { testJoin("z", table1(), tableD2(), tableD2()) ; }
+ @Test public void join_07() { testJoin("z", tableD2(), table1(), tableD2()) ; }
+
+ @Test public void join_08() { testJoin("a", tableD4(), tableD5(), tableD4x5()) ; }
+ @Test public void join_09() { testJoin("a", tableD5(), tableD4(), tableD4x5()) ; }
+
+ @Test public void join_10() { testJoin("a", tableD4(), tableD6(), tableD4x6()) ; }
+ @Test public void join_11() { testJoin("a", tableD6(), tableD4(), tableD4x6()) ; }
+
+ // Not the right join key - should still work albeit less efficiently.
+ @Test public void join_12() { testJoin("z", tableD1(), tableD2(), tableD3()) ; }
+ @Test public void join_13() { testJoin("z", tableD2(), tableD1(), tableD3()) ; }
+
+ // No key.
+ @Test public void join_14() { testJoin(null, tableD1(), tableD2(), tableD3()) ; }
+
+
+ // Disjoint tables.
+ @Test public void join_disjoint_01() { testJoin("a", tableD2(), tableD8(), tableD8x2()) ; }
+ @Test public void join_disjoint_02() { testJoin("z", tableD2(), tableD8(), tableD8x2()) ; }
+}
+
+
http://git-wip-us.apache.org/repos/asf/jena/blob/07fcde9e/jena-arq/src/test/java/org/apache/jena/sparql/engine/join/AbstractTestJoin.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/test/java/org/apache/jena/sparql/engine/join/AbstractTestJoin.java b/jena-arq/src/test/java/org/apache/jena/sparql/engine/join/AbstractTestJoin.java
new file mode 100644
index 0000000..b48c66b
--- /dev/null
+++ b/jena-arq/src/test/java/org/apache/jena/sparql/engine/join/AbstractTestJoin.java
@@ -0,0 +1,101 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.jena.sparql.engine.join;
+
+import java.util.List ;
+
+import org.apache.jena.atlas.iterator.Iter ;
+import org.apache.jena.atlas.lib.StrUtils ;
+import org.apache.jena.query.ResultSet ;
+import org.apache.jena.query.ResultSetFactory ;
+import org.apache.jena.sparql.algebra.Table ;
+import org.apache.jena.sparql.algebra.TableFactory ;
+import org.apache.jena.sparql.core.Var ;
+import org.apache.jena.sparql.engine.QueryIterator ;
+import org.apache.jena.sparql.engine.binding.Binding ;
+import org.apache.jena.sparql.engine.join.JoinKey ;
+import org.apache.jena.sparql.resultset.ResultSetCompare ;
+import org.apache.jena.sparql.sse.SSE ;
+import org.junit.Assert ;
+
+/** Tests for inner/equi joins */
+public abstract class AbstractTestJoin extends Assert {
+ protected static Table parseTableInt(String... strings) {
+ String x = StrUtils.strjoinNL(strings) ;
+ return SSE.parseTable(x) ;
+ }
+
+ protected void testJoin(String var, Table left, Table right, Table tableOut) {
+ JoinKey joinKey ;
+ if ( var != null ) {
+ if ( var.startsWith("?") )
+ var = var.substring(1) ;
+ joinKey = JoinKey.create(Var.alloc(var)) ;
+ }
+ else {
+ // No vars in join key. Legal, albeit silly.
+ joinKey = new JoinKey.Builder().build() ;
+ }
+
+ executeTest(joinKey, left, right, tableOut) ;
+ }
+
+ protected abstract void executeTest(JoinKey joinKey, Table left, Table right, Table expectedResults) ;
+
+
+ private List<Binding> toList(Table table) {
+ return Iter.toList(table.rows()) ;
+ }
+
+ protected void executeTestJoin(String num, JoinKey joinKey, Table left, Table right, Table expectedResults) {
+ Table x1 = joinMaterialize(joinKey, left, right) ;
+ assertNotNull("Null table from join ("+num+")", x1) ;
+ check("Results not equal ("+num+")", joinKey, left, right, expectedResults, x1) ;
+ }
+
+ private Table joinMaterialize(JoinKey joinKey, Table left, Table right) {
+ QueryIterator qIter = join(joinKey, left , right) ;
+ return TableFactory.create(qIter) ;
+ }
+
+ public abstract QueryIterator join(JoinKey joinKey , Table left , Table right) ;
+
+ private static void check(String msg, JoinKey joinKey, Table left, Table right, Table expected, Table actual) {
+ boolean b = equalTables(expected, actual) ;
+ if ( ! b ) {
+ System.out.println("Joinkey: "+joinKey) ;
+ System.out.println("Left: \n"+left) ;
+ System.out.println("Right: \n"+right) ;
+ System.out.println("Expected: \n"+expected) ;
+ System.out.println("Actual: \n"+actual) ;
+ System.out.println() ;
+ }
+
+ assertTrue(msg, b) ;
+ }
+
+ private static boolean equalTables(Table table1, Table table2) {
+ ResultSet rs1 = ResultSetFactory.create(table1.iterator(null), table1.getVarNames()) ;
+ ResultSet rs2 = ResultSetFactory.create(table2.iterator(null), table2.getVarNames()) ;
+ return ResultSetCompare.equalsByTerm(rs1, rs2) ;
+ }
+
+}
+
+
http://git-wip-us.apache.org/repos/asf/jena/blob/07fcde9e/jena-arq/src/test/java/org/apache/jena/sparql/engine/join/AbstractTestLeftJoin.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/test/java/org/apache/jena/sparql/engine/join/AbstractTestLeftJoin.java b/jena-arq/src/test/java/org/apache/jena/sparql/engine/join/AbstractTestLeftJoin.java
new file mode 100644
index 0000000..57756ff
--- /dev/null
+++ b/jena-arq/src/test/java/org/apache/jena/sparql/engine/join/AbstractTestLeftJoin.java
@@ -0,0 +1,170 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.jena.sparql.engine.join;
+
+import org.apache.jena.sparql.algebra.Table ;
+import org.apache.jena.sparql.core.Var ;
+import org.apache.jena.sparql.engine.join.JoinKey ;
+import org.junit.Test ;
+
+public abstract class AbstractTestLeftJoin extends AbstractTestJoin {
+ @Override
+ protected void executeTest(JoinKey joinKey, Table left, Table right, Table expectedResults) {
+ executeTestJoin("LJ", joinKey, left, right, expectedResults) ;
+ }
+
+ static Var var_a = Var.alloc("a") ;
+ static Var var_b = Var.alloc("b") ;
+ static Var var_c = Var.alloc("c") ;
+ static Var var_d = Var.alloc("d") ;
+
+ static Table table0() { return parseTableInt("(table)") ; }
+
+ // Table of one row and no colums.
+ static Table table1() {
+ return parseTableInt("(table (row))") ; }
+
+ static Table tableD1() {
+ return parseTableInt("(table",
+ " (row (?a 1) (?b 2))",
+ " (row (?a 1) (?b 3))",
+ " (row (?a 1) (?b 2))",
+ ")") ;
+ }
+
+ static Table tableD2() {
+ return parseTableInt("(table",
+ " (row (?a 0) (?d 8))",
+ " (row (?a 1) (?c 9))",
+ ")") ;
+ }
+
+ static Table tableD3() {
+ return parseTableInt("(table",
+ " (row (?a 1) (?c 9) (?b 2))",
+ " (row (?a 1) (?c 9) (?b 3))",
+ " (row (?a 1) (?c 9) (?b 2))",
+ ")") ;
+ }
+
+ static Table tableD4() {
+ return parseTableInt("(table",
+ " (row (?a 1) (?b 2))",
+ " (row (?a 1) (?b 3))",
+ " (row (?a 4) (?b 4))",
+ " (row (?a 4) (?b 5))",
+ ")") ;
+ }
+
+ static Table tableD5() {
+ return parseTableInt("(table",
+ " (row (?a 4) (?c 4))",
+ " (row (?a 4) (?c 5))",
+ " (row (?a 6) (?c 5))",
+ ")") ;
+ }
+
+ static Table tableD6() {
+ return parseTableInt("(table",
+ " (row (?a 1) (?c 2))",
+ " (row (?a 1) (?c 3))",
+ " (row (?a 4) (?c 4))",
+ " (row (?a 4) (?c 5))",
+ ")") ;
+ }
+
+ static Table tableD4x5() {
+ return parseTableInt("(table",
+ " (row (?a 4) (?c 4) (?b 4))",
+ " (row (?a 4) (?c 4) (?b 5))",
+ " (row (?a 4) (?c 5) (?b 4))",
+ " (row (?a 4) (?c 5) (?b 5))",
+ ")") ;
+ }
+
+ static Table tableD4x6() {
+ return parseTableInt("(table",
+ " (row (?a 1) (?c 2) (?b 2))",
+ " (row (?a 1) (?c 2) (?b 3))",
+ " (row (?a 1) (?c 3) (?b 2))",
+ " (row (?a 1) (?c 3) (?b 3))",
+ " (row (?a 4) (?c 4) (?b 4))",
+ " (row (?a 4) (?c 4) (?b 5))",
+ " (row (?a 4) (?c 5) (?b 4))",
+ " (row (?a 4) (?c 5) (?b 5))",
+ ")") ;
+ }
+
+ // Disjoint.
+ static Table tableD8() {
+ return parseTableInt("(table",
+ " (row (?x 10))",
+ " (row (?z 11))",
+ ")") ;
+ }
+
+ // Table8 crossproduct table2
+ static Table tableD8x2() {
+ return parseTableInt("(table",
+ " (row (?a 0) (?d 8) (?z 11))",
+ " (row (?a 0) (?d 8) (?x 10))",
+ " (row (?a 1) (?c 9) (?z 11))",
+ " (row (?a 1) (?c 9) (?x 10))",
+ ")") ;
+ }
+
+ // XXX And conditions.
+
+ @Test public void leftjoin_00() { testJoin("a", table0(), table0(), table0()) ; }
+ @Test public void leftjoin_00a() { testJoin("a", table1(), table0(), table0()) ; }
+ @Test public void leftjoin_00b() { testJoin("a", tableD1(), table1(), tableD1()) ; }
+ @Test public void leftjoin_00c() { testJoin("z", tableD1(), table1(), tableD1()) ; }
+
+ @Test public void leftjoin_01() { testJoin("a", table0(), tableD2(), table0()) ; }
+ @Test public void leftjoin_02() { testJoin("a", tableD1(), table0(), tableD1()) ; }
+ @Test public void leftjoin_03() { testJoin("a", tableD1(), tableD2(), tableD3()) ; }
+
+ // Identity.
+ @Test public void leftjoin_04() { testJoin("a", tableD2(), table1(), tableD2()) ; }
+ @Test public void leftjoin_05() { testJoin("a", table1(), tableD2(), tableD2()) ; }
+ // Identity, keymiss
+ @Test public void leftjoin_06() { testJoin("z", table1(), tableD2(), tableD2()) ; }
+ @Test public void leftjoin_07() { testJoin("z", tableD2(), table1(), tableD2()) ; }
+
+ @Test public void leftjoin_08() { testJoin("a", tableD4(), tableD5(), tableD4x5()) ; }
+ @Test public void leftjoin_09() { testJoin("a", tableD5(), tableD4(), tableD4x5()) ; }
+
+ @Test public void leftjoin_10() { testJoin("a", tableD4(), tableD6(), tableD4x6()) ; }
+ @Test public void leftjoin_11() { testJoin("a", tableD6(), tableD4(), tableD4x6()) ; }
+
+ // Not the right join key - should still work albeit less efficiently.
+ @Test public void leftjoin_12() { testJoin("z", tableD1(), tableD2(), tableD3()) ; }
+ @Test public void leftjoin_13() { testJoin("z", tableD2(), tableD1(), tableD3()) ; }
+
+ // No key.
+ @Test public void leftjoin_14() { testJoin(null, tableD1(), tableD2(), tableD3()) ; }
+
+
+ // Disjoint tables.
+ @Test public void leftjoin_disjoint_01() { testJoin("a", tableD2(), tableD8(), tableD8x2()) ; }
+ @Test public void leftjoin_disjoint_02() { testJoin("z", tableD2(), tableD8(), tableD8x2()) ; }
+
+}
+
+
http://git-wip-us.apache.org/repos/asf/jena/blob/07fcde9e/jena-arq/src/test/java/org/apache/jena/sparql/engine/join/TS_Join.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/test/java/org/apache/jena/sparql/engine/join/TS_Join.java b/jena-arq/src/test/java/org/apache/jena/sparql/engine/join/TS_Join.java
new file mode 100644
index 0000000..69b5fb4
--- /dev/null
+++ b/jena-arq/src/test/java/org/apache/jena/sparql/engine/join/TS_Join.java
@@ -0,0 +1,34 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.jena.sparql.engine.join;
+
+import org.junit.runner.RunWith ;
+import org.junit.runners.Suite ;
+import org.junit.runners.Suite.SuiteClasses ;
+
+@RunWith(Suite.class)
+@SuiteClasses( {
+ TestJoinSimple.class
+ , TestJoinNestedLoopSimple.class // Real simple materializing version.
+ , TestJoinNestedLoop.class
+ , TestHashJoin.class
+})
+
+public class TS_Join { }
+
http://git-wip-us.apache.org/repos/asf/jena/blob/07fcde9e/jena-arq/src/test/java/org/apache/jena/sparql/engine/join/TestHashJoin.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/test/java/org/apache/jena/sparql/engine/join/TestHashJoin.java b/jena-arq/src/test/java/org/apache/jena/sparql/engine/join/TestHashJoin.java
new file mode 100644
index 0000000..4a4bd6f
--- /dev/null
+++ b/jena-arq/src/test/java/org/apache/jena/sparql/engine/join/TestHashJoin.java
@@ -0,0 +1,38 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.jena.sparql.engine.join;
+
+import java.util.Iterator ;
+
+import org.apache.jena.sparql.algebra.Table ;
+import org.apache.jena.sparql.engine.QueryIterator ;
+import org.apache.jena.sparql.engine.binding.Binding ;
+import org.apache.jena.sparql.engine.iterator.QueryIterPlainWrapper ;
+import org.apache.jena.sparql.engine.join.Join ;
+import org.apache.jena.sparql.engine.join.JoinKey ;
+
+public class TestHashJoin extends AbstractTestInnerJoin {
+
+ @Override
+ public QueryIterator join(JoinKey joinKey, Table left, Table right) {
+ Iterator<Binding> data = Join.hashJoin(joinKey, left.iterator(null), right.iterator(null), null) ;
+ QueryIterator qIter = new QueryIterPlainWrapper(data) ;
+ return qIter ;
+ }
+}
http://git-wip-us.apache.org/repos/asf/jena/blob/07fcde9e/jena-arq/src/test/java/org/apache/jena/sparql/engine/join/TestJoinNestedLoop.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/test/java/org/apache/jena/sparql/engine/join/TestJoinNestedLoop.java b/jena-arq/src/test/java/org/apache/jena/sparql/engine/join/TestJoinNestedLoop.java
new file mode 100644
index 0000000..c844ea2
--- /dev/null
+++ b/jena-arq/src/test/java/org/apache/jena/sparql/engine/join/TestJoinNestedLoop.java
@@ -0,0 +1,34 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.jena.sparql.engine.join;
+
+import org.apache.jena.sparql.algebra.Table ;
+import org.apache.jena.sparql.engine.QueryIterator ;
+import org.apache.jena.sparql.engine.join.Join ;
+import org.apache.jena.sparql.engine.join.JoinKey ;
+
+public class TestJoinNestedLoop extends AbstractTestInnerJoin {
+
+ @Override
+ public QueryIterator join(JoinKey joinKey, Table left, Table right) {
+ return Join.innerLoopJoin(left.iterator(null), right.iterator(null), null) ;
+ }
+
+}
+
http://git-wip-us.apache.org/repos/asf/jena/blob/07fcde9e/jena-arq/src/test/java/org/apache/jena/sparql/engine/join/TestJoinNestedLoopSimple.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/test/java/org/apache/jena/sparql/engine/join/TestJoinNestedLoopSimple.java b/jena-arq/src/test/java/org/apache/jena/sparql/engine/join/TestJoinNestedLoopSimple.java
new file mode 100644
index 0000000..0d9db54
--- /dev/null
+++ b/jena-arq/src/test/java/org/apache/jena/sparql/engine/join/TestJoinNestedLoopSimple.java
@@ -0,0 +1,34 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.jena.sparql.engine.join;
+
+import org.apache.jena.sparql.algebra.Table ;
+import org.apache.jena.sparql.engine.QueryIterator ;
+import org.apache.jena.sparql.engine.join.Join ;
+import org.apache.jena.sparql.engine.join.JoinKey ;
+
+public class TestJoinNestedLoopSimple extends AbstractTestInnerJoin {
+
+ @Override
+ public QueryIterator join(JoinKey joinKey, Table left, Table right) {
+ return Join.innerLoopJoinBasic(left.iterator(null), right.iterator(null), null) ;
+ }
+
+}
+
http://git-wip-us.apache.org/repos/asf/jena/blob/07fcde9e/jena-arq/src/test/java/org/apache/jena/sparql/engine/join/TestJoinSimple.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/test/java/org/apache/jena/sparql/engine/join/TestJoinSimple.java b/jena-arq/src/test/java/org/apache/jena/sparql/engine/join/TestJoinSimple.java
new file mode 100644
index 0000000..d091168
--- /dev/null
+++ b/jena-arq/src/test/java/org/apache/jena/sparql/engine/join/TestJoinSimple.java
@@ -0,0 +1,34 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.jena.sparql.engine.join;
+
+import org.apache.jena.sparql.algebra.Table ;
+import org.apache.jena.sparql.engine.QueryIterator ;
+import org.apache.jena.sparql.engine.join.JoinKey ;
+import org.apache.jena.sparql.engine.ref.TableJoin ;
+
+public class TestJoinSimple extends AbstractTestInnerJoin {
+
+ @Override
+ public QueryIterator join(JoinKey joinKey, Table left, Table right) {
+ return TableJoin.join(left.iterator(null), right, null, null) ;
+ }
+
+}
+
http://git-wip-us.apache.org/repos/asf/jena/blob/07fcde9e/jena-arq/src/test/java/org/apache/jena/sparql/engine/join/TestLeftJoinSimple.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/test/java/org/apache/jena/sparql/engine/join/TestLeftJoinSimple.java b/jena-arq/src/test/java/org/apache/jena/sparql/engine/join/TestLeftJoinSimple.java
new file mode 100644
index 0000000..041dfe5
--- /dev/null
+++ b/jena-arq/src/test/java/org/apache/jena/sparql/engine/join/TestLeftJoinSimple.java
@@ -0,0 +1,34 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.jena.sparql.engine.join;
+
+import org.apache.jena.sparql.algebra.Table ;
+import org.apache.jena.sparql.engine.QueryIterator ;
+import org.apache.jena.sparql.engine.join.JoinKey ;
+import org.apache.jena.sparql.engine.ref.TableJoin ;
+
+public class TestLeftJoinSimple extends AbstractTestLeftJoin {
+
+ @Override
+ public QueryIterator join(JoinKey joinKey, Table left, Table right) {
+ return TableJoin.leftJoin(left.iterator(null), right, null, null) ;
+ }
+
+}
+
http://git-wip-us.apache.org/repos/asf/jena/blob/07fcde9e/jena-arq/src/test/java/org/apache/jena/sparql/join/AbstractTestJoin.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/test/java/org/apache/jena/sparql/join/AbstractTestJoin.java b/jena-arq/src/test/java/org/apache/jena/sparql/join/AbstractTestJoin.java
deleted file mode 100644
index a15d3e3..0000000
--- a/jena-arq/src/test/java/org/apache/jena/sparql/join/AbstractTestJoin.java
+++ /dev/null
@@ -1,236 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.jena.sparql.join;
-
-import java.util.List ;
-
-import org.apache.jena.atlas.iterator.Iter ;
-import org.apache.jena.atlas.lib.StrUtils ;
-import org.apache.jena.query.ResultSet ;
-import org.apache.jena.query.ResultSetFactory ;
-import org.apache.jena.sparql.algebra.Table ;
-import org.apache.jena.sparql.algebra.TableFactory ;
-import org.apache.jena.sparql.core.Var ;
-import org.apache.jena.sparql.engine.QueryIterator ;
-import org.apache.jena.sparql.engine.binding.Binding ;
-import org.apache.jena.sparql.engine.join.JoinKey ;
-import org.apache.jena.sparql.resultset.ResultSetCompare ;
-import org.apache.jena.sparql.sse.SSE ;
-import org.junit.Assert ;
-import org.junit.Test ;
-
-public abstract class AbstractTestJoin extends Assert {
- static Var var_a = Var.alloc("a") ;
- static Var var_b = Var.alloc("b") ;
- static Var var_c = Var.alloc("c") ;
- static Var var_d = Var.alloc("d") ;
-
- static Table table0() { return parseTableInt("(table)") ; }
-
- // For Mere, these must be in sort-joinkey order.
-
- private static Table parseTableInt(String... strings) {
- String x = StrUtils.strjoinNL(strings) ;
- return SSE.parseTable(x) ;
- }
-
- // Table of one row and no colums.
- static Table table1() {
- return parseTableInt("(table (row))") ; }
-
- static Table tableD1() {
- return parseTableInt("(table",
- " (row (?a 1) (?b 2))",
- " (row (?a 1) (?b 3))",
- " (row (?a 1) (?b 2))",
- ")") ;
- }
-
- static Table tableD2() {
- return parseTableInt("(table",
- " (row (?a 0) (?d 8))",
- " (row (?a 1) (?c 9))",
- ")") ;
- }
-
- static Table tableD3() {
- return parseTableInt("(table",
- " (row (?a 1) (?c 9) (?b 2))",
- " (row (?a 1) (?c 9) (?b 3))",
- " (row (?a 1) (?c 9) (?b 2))",
- ")") ;
- }
-
- static Table tableD4() {
- return parseTableInt("(table",
- " (row (?a 1) (?b 2))",
- " (row (?a 1) (?b 3))",
- " (row (?a 4) (?b 4))",
- " (row (?a 4) (?b 5))",
- ")") ;
- }
-
- static Table tableD5() {
- return parseTableInt("(table",
- " (row (?a 4) (?c 4))",
- " (row (?a 4) (?c 5))",
- " (row (?a 6) (?c 5))",
- ")") ;
- }
-
- static Table tableD6() {
- return parseTableInt("(table",
- " (row (?a 1) (?c 2))",
- " (row (?a 1) (?c 3))",
- " (row (?a 4) (?c 4))",
- " (row (?a 4) (?c 5))",
- ")") ;
- }
-
- static Table tableD4x5() {
- return parseTableInt("(table",
- " (row (?a 4) (?c 4) (?b 4))",
- " (row (?a 4) (?c 4) (?b 5))",
- " (row (?a 4) (?c 5) (?b 4))",
- " (row (?a 4) (?c 5) (?b 5))",
- ")") ;
- }
-
- static Table tableD4x6() {
- return parseTableInt("(table",
- " (row (?a 1) (?c 2) (?b 2))",
- " (row (?a 1) (?c 2) (?b 3))",
- " (row (?a 1) (?c 3) (?b 2))",
- " (row (?a 1) (?c 3) (?b 3))",
- " (row (?a 4) (?c 4) (?b 4))",
- " (row (?a 4) (?c 4) (?b 5))",
- " (row (?a 4) (?c 5) (?b 4))",
- " (row (?a 4) (?c 5) (?b 5))",
- ")") ;
- }
-
- // Disjoint.
- static Table tableD8() {
- return parseTableInt("(table",
- " (row (?x 10))",
- " (row (?z 11))",
- ")") ;
- }
-
- // Table8 crossproduct table2
- static Table tableD8x2() {
- return parseTableInt("(table",
- " (row (?a 0) (?d 8) (?z 11))",
- " (row (?a 0) (?d 8) (?x 10))",
- " (row (?a 1) (?c 9) (?z 11))",
- " (row (?a 1) (?c 9) (?x 10))",
- ")") ;
- }
-
- @Test public void join_00() { testJoin("a", table0(), table0(), table0()) ; }
- @Test public void join_00a() { testJoin("a", table1(), table0(), table0()) ; }
- @Test public void join_00b() { testJoin("a", tableD1(), table1(), tableD1()) ; }
- @Test public void join_00c() { testJoin("z", tableD1(), table1(), tableD1()) ; }
-
- @Test public void join_01() { testJoin("a", table0(), tableD2(), table0()) ; }
- @Test public void join_02() { testJoin("a", tableD1(), table0(), table0()) ; }
- @Test public void join_03() { testJoin("a", tableD1(), tableD2(), tableD3()) ; }
-
- // Identity.
- @Test public void join_04() { testJoin("a", tableD2(), table1(), tableD2()) ; }
- @Test public void join_05() { testJoin("a", table1(), tableD2(), tableD2()) ; }
- // Identity, keymiss
- @Test public void join_06() { testJoin("z", table1(), tableD2(), tableD2()) ; }
- @Test public void join_07() { testJoin("z", tableD2(), table1(), tableD2()) ; }
-
- @Test public void join_08() { testJoin("a", tableD4(), tableD5(), tableD4x5()) ; }
- @Test public void join_09() { testJoin("a", tableD5(), tableD4(), tableD4x5()) ; }
-
- @Test public void join_10() { testJoin("a", tableD4(), tableD6(), tableD4x6()) ; }
- @Test public void join_11() { testJoin("a", tableD6(), tableD4(), tableD4x6()) ; }
-
- // Not the right join key - should still work albeit less efficiently.
- @Test public void join_12() { testJoin("z", tableD1(), tableD2(), tableD3()) ; }
- @Test public void join_13() { testJoin("z", tableD2(), tableD1(), tableD3()) ; }
-
- // No key.
- @Test public void join_14() { testJoin(null, tableD1(), tableD2(), tableD3()) ; }
-
-
- // Disjoint tables.
- @Test public void join_disjoint_01() { testJoin("a", tableD2(), tableD8(), tableD8x2()) ; }
- @Test public void join_disjoint_02() { testJoin("z", tableD2(), tableD8(), tableD8x2()) ; }
-
- private void testJoin(String var, Table left, Table right, Table tableOut) {
- JoinKey joinKey ;
- if ( var != null ) {
- if ( var.startsWith("?") )
- var = var.substring(1) ;
- joinKey = JoinKey.create(Var.alloc(var)) ;
- }
- else {
- // No vars in join key. Legal, albeit silly.
- joinKey = new JoinKey.Builder().build() ;
- }
-
- testJoin1("1", joinKey, left, right, tableOut) ;
- // Commumute
- testJoin1("2", joinKey, right, left, tableOut) ;
- }
-
- private List<Binding> toList(Table table) {
- return Iter.toList(table.rows()) ;
- }
-
- private void testJoin1(String num, JoinKey joinKey, Table left, Table right, Table expectedResults) {
- Table x1 = joinMaterialize(joinKey, left, right) ;
- assertNotNull("Null table from join ("+num+")", x1) ;
- check("Results not equal ("+num+")", joinKey, left, right, expectedResults, x1) ;
- }
-
- private Table joinMaterialize(JoinKey joinKey, Table left, Table right) {
- QueryIterator qIter = join(joinKey , left , right) ;
- return TableFactory.create(qIter) ;
- }
-
- public abstract QueryIterator join(JoinKey joinKey , Table left , Table right) ;
-
- private static void check(String msg, JoinKey joinKey, Table left, Table right, Table expected, Table actual) {
- boolean b = equalTables(expected, actual) ;
- if ( ! b ) {
- System.out.println("Joinkey: "+joinKey) ;
- System.out.println("Left: "+left) ;
- System.out.println("Right: "+right) ;
- System.out.println("Expected: "+expected) ;
- System.out.println("Actual: "+actual) ;
- System.out.println() ;
- }
-
- assertTrue(msg, b) ;
- }
-
- private static boolean equalTables(Table table1, Table table2) {
- ResultSet rs1 = ResultSetFactory.create(table1.iterator(null), table1.getVarNames()) ;
- ResultSet rs2 = ResultSetFactory.create(table2.iterator(null), table2.getVarNames()) ;
- return ResultSetCompare.equalsByTerm(rs1, rs2) ;
- }
-
-}
-
-
http://git-wip-us.apache.org/repos/asf/jena/blob/07fcde9e/jena-arq/src/test/java/org/apache/jena/sparql/join/TS_Join.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/test/java/org/apache/jena/sparql/join/TS_Join.java b/jena-arq/src/test/java/org/apache/jena/sparql/join/TS_Join.java
deleted file mode 100644
index 0a4c2a6..0000000
--- a/jena-arq/src/test/java/org/apache/jena/sparql/join/TS_Join.java
+++ /dev/null
@@ -1,34 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.jena.sparql.join;
-
-import org.junit.runner.RunWith ;
-import org.junit.runners.Suite ;
-import org.junit.runners.Suite.SuiteClasses ;
-
-@RunWith(Suite.class)
-@SuiteClasses( {
- TestJoinSimple.class
- , TestJoinNestedLoopSimple.class // Real simple materializing version.
- , TestJoinNestedLoop.class
- , TestHashJoin.class
-})
-
-public class TS_Join { }
-
http://git-wip-us.apache.org/repos/asf/jena/blob/07fcde9e/jena-arq/src/test/java/org/apache/jena/sparql/join/TestHashJoin.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/test/java/org/apache/jena/sparql/join/TestHashJoin.java b/jena-arq/src/test/java/org/apache/jena/sparql/join/TestHashJoin.java
deleted file mode 100644
index 8358bc3..0000000
--- a/jena-arq/src/test/java/org/apache/jena/sparql/join/TestHashJoin.java
+++ /dev/null
@@ -1,38 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.jena.sparql.join;
-
-import java.util.Iterator ;
-
-import org.apache.jena.sparql.algebra.Table ;
-import org.apache.jena.sparql.engine.QueryIterator ;
-import org.apache.jena.sparql.engine.binding.Binding ;
-import org.apache.jena.sparql.engine.iterator.QueryIterPlainWrapper ;
-import org.apache.jena.sparql.engine.join.Join ;
-import org.apache.jena.sparql.engine.join.JoinKey ;
-
-public class TestHashJoin extends AbstractTestJoin {
-
- @Override
- public QueryIterator join(JoinKey joinKey, Table left, Table right) {
- Iterator<Binding> data = Join.hashJoin(joinKey, left.iterator(null), right.iterator(null), null) ;
- QueryIterator qIter = new QueryIterPlainWrapper(data) ;
- return qIter ;
- }
-}
http://git-wip-us.apache.org/repos/asf/jena/blob/07fcde9e/jena-arq/src/test/java/org/apache/jena/sparql/join/TestJoinNestedLoop.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/test/java/org/apache/jena/sparql/join/TestJoinNestedLoop.java b/jena-arq/src/test/java/org/apache/jena/sparql/join/TestJoinNestedLoop.java
deleted file mode 100644
index 4123c1c..0000000
--- a/jena-arq/src/test/java/org/apache/jena/sparql/join/TestJoinNestedLoop.java
+++ /dev/null
@@ -1,34 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.jena.sparql.join;
-
-import org.apache.jena.sparql.algebra.Table ;
-import org.apache.jena.sparql.engine.QueryIterator ;
-import org.apache.jena.sparql.engine.join.Join ;
-import org.apache.jena.sparql.engine.join.JoinKey ;
-
-public class TestJoinNestedLoop extends AbstractTestJoin {
-
- @Override
- public QueryIterator join(JoinKey joinKey, Table left, Table right) {
- return Join.innerLoopJoin(left.iterator(null), right.iterator(null), null) ;
- }
-
-}
-
http://git-wip-us.apache.org/repos/asf/jena/blob/07fcde9e/jena-arq/src/test/java/org/apache/jena/sparql/join/TestJoinNestedLoopSimple.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/test/java/org/apache/jena/sparql/join/TestJoinNestedLoopSimple.java b/jena-arq/src/test/java/org/apache/jena/sparql/join/TestJoinNestedLoopSimple.java
deleted file mode 100644
index ff56d13..0000000
--- a/jena-arq/src/test/java/org/apache/jena/sparql/join/TestJoinNestedLoopSimple.java
+++ /dev/null
@@ -1,34 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.jena.sparql.join;
-
-import org.apache.jena.sparql.algebra.Table ;
-import org.apache.jena.sparql.engine.QueryIterator ;
-import org.apache.jena.sparql.engine.join.Join ;
-import org.apache.jena.sparql.engine.join.JoinKey ;
-
-public class TestJoinNestedLoopSimple extends AbstractTestJoin {
-
- @Override
- public QueryIterator join(JoinKey joinKey, Table left, Table right) {
- return Join.innerLoopJoinBasic(left.iterator(null), right.iterator(null), null) ;
- }
-
-}
-
http://git-wip-us.apache.org/repos/asf/jena/blob/07fcde9e/jena-arq/src/test/java/org/apache/jena/sparql/join/TestJoinSimple.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/test/java/org/apache/jena/sparql/join/TestJoinSimple.java b/jena-arq/src/test/java/org/apache/jena/sparql/join/TestJoinSimple.java
deleted file mode 100644
index b7135cf..0000000
--- a/jena-arq/src/test/java/org/apache/jena/sparql/join/TestJoinSimple.java
+++ /dev/null
@@ -1,34 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.jena.sparql.join;
-
-import org.apache.jena.sparql.algebra.Table ;
-import org.apache.jena.sparql.engine.QueryIterator ;
-import org.apache.jena.sparql.engine.TableJoin ;
-import org.apache.jena.sparql.engine.join.JoinKey ;
-
-public class TestJoinSimple extends AbstractTestJoin {
-
- @Override
- public QueryIterator join(JoinKey joinKey, Table left, Table right) {
- return TableJoin.join(left.iterator(null), right, null, null) ;
- }
-
-}
-
[07/20] jena git commit: Correct naming. Expand javadoc.
Posted by an...@apache.org.
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/723daa25
Tree: http://git-wip-us.apache.org/repos/asf/jena/tree/723daa25
Diff: http://git-wip-us.apache.org/repos/asf/jena/diff/723daa25
Branch: refs/heads/master
Commit: 723daa258a26c96c20115c725f9e4b72796cc4e3
Parents: c6288c3
Author: Andy Seaborne <an...@apache.org>
Authored: Tue Sep 8 14:17:52 2015 +0100
Committer: Andy Seaborne <an...@apache.org>
Committed: Tue Sep 8 14:17:52 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/723daa25/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 ;
}
}
[11/20] jena git commit: Rename in JoinType.
Posted by an...@apache.org.
Rename in JoinType.
Project: http://git-wip-us.apache.org/repos/asf/jena/repo
Commit: http://git-wip-us.apache.org/repos/asf/jena/commit/d674763e
Tree: http://git-wip-us.apache.org/repos/asf/jena/tree/d674763e
Diff: http://git-wip-us.apache.org/repos/asf/jena/diff/d674763e
Branch: refs/heads/master
Commit: d674763e77065a11601f77a8353513c30581b695
Parents: ed70d5c
Author: Andy Seaborne <an...@apache.org>
Authored: Tue Sep 8 14:19:12 2015 +0100
Committer: Andy Seaborne <an...@apache.org>
Committed: Tue Sep 8 14:19:12 2015 +0100
----------------------------------------------------------------------
.../main/java/org/apache/jena/sparql/engine/ref/TableJoin.java | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/jena/blob/d674763e/jena-arq/src/main/java/org/apache/jena/sparql/engine/ref/TableJoin.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/main/java/org/apache/jena/sparql/engine/ref/TableJoin.java b/jena-arq/src/main/java/org/apache/jena/sparql/engine/ref/TableJoin.java
index 483764e..acdb5cc 100644
--- a/jena-arq/src/main/java/org/apache/jena/sparql/engine/ref/TableJoin.java
+++ b/jena-arq/src/main/java/org/apache/jena/sparql/engine/ref/TableJoin.java
@@ -44,7 +44,7 @@ import org.apache.jena.sparql.expr.ExprList ;
public class TableJoin
{
public static QueryIterator join(QueryIterator left, Table right, ExprList condition, ExecutionContext execCxt) {
- return joinWorker(left, right, PLAIN, condition, execCxt) ;
+ return joinWorker(left, right, INNER, condition, execCxt) ;
}
public static QueryIterator leftJoin(QueryIterator left, Table right, ExprList condition, ExecutionContext execCxt) {
@@ -53,7 +53,7 @@ public class TableJoin
public static QueryIterator joinWorker(QueryIterator left, Table right, JoinType joinType, ExprList conditions, ExecutionContext execCxt) {
if ( right.isEmpty() ) {
- if ( joinType == PLAIN ) {
+ if ( joinType == INNER ) {
// No rows - no match
left.close() ;
return QueryIterNullIterator.create(execCxt) ;
[18/20] jena git commit: Remove old code.
Posted by an...@apache.org.
Remove old code.
Project: http://git-wip-us.apache.org/repos/asf/jena/repo
Commit: http://git-wip-us.apache.org/repos/asf/jena/commit/e7780fb2
Tree: http://git-wip-us.apache.org/repos/asf/jena/tree/e7780fb2
Diff: http://git-wip-us.apache.org/repos/asf/jena/diff/e7780fb2
Branch: refs/heads/master
Commit: e7780fb26ffd2f08867e0dcf27303d4bf22296ee
Parents: 8e999b6
Author: Andy Seaborne <an...@apache.org>
Authored: Tue Sep 8 17:56:25 2015 +0100
Committer: Andy Seaborne <an...@apache.org>
Committed: Tue Sep 8 17:56:25 2015 +0100
----------------------------------------------------------------------
.../engine/main/iterator/QueryIterJoin.java | 32 ---------
.../engine/main/iterator/QueryIterJoinBase.java | 76 --------------------
.../engine/main/iterator/QueryIterLeftJoin.java | 32 ---------
3 files changed, 140 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/jena/blob/e7780fb2/jena-arq/src/main/java/org/apache/jena/sparql/engine/main/iterator/QueryIterJoin.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/main/java/org/apache/jena/sparql/engine/main/iterator/QueryIterJoin.java b/jena-arq/src/main/java/org/apache/jena/sparql/engine/main/iterator/QueryIterJoin.java
deleted file mode 100644
index 2b45202..0000000
--- a/jena-arq/src/main/java/org/apache/jena/sparql/engine/main/iterator/QueryIterJoin.java
+++ /dev/null
@@ -1,32 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.jena.sparql.engine.main.iterator;
-
-import org.apache.jena.sparql.algebra.JoinType ;
-import org.apache.jena.sparql.engine.ExecutionContext ;
-import org.apache.jena.sparql.engine.QueryIterator ;
-
-/** Join by materializing the RHS - this is not streamed */
-public class QueryIterJoin extends QueryIterJoinBase
-{
- public QueryIterJoin(QueryIterator left, QueryIterator right, ExecutionContext qCxt)
- {
- super(left, right, JoinType.INNER, null, qCxt) ;
- }
-}
http://git-wip-us.apache.org/repos/asf/jena/blob/e7780fb2/jena-arq/src/main/java/org/apache/jena/sparql/engine/main/iterator/QueryIterJoinBase.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/main/java/org/apache/jena/sparql/engine/main/iterator/QueryIterJoinBase.java b/jena-arq/src/main/java/org/apache/jena/sparql/engine/main/iterator/QueryIterJoinBase.java
deleted file mode 100644
index 3fb00dc..0000000
--- a/jena-arq/src/main/java/org/apache/jena/sparql/engine/main/iterator/QueryIterJoinBase.java
+++ /dev/null
@@ -1,76 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.jena.sparql.engine.main.iterator;
-
-import org.apache.jena.sparql.algebra.JoinType;
-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.QueryIter;
-import org.apache.jena.sparql.engine.join.Join;
-import org.apache.jena.sparql.expr.ExprList;
-
-/**
- * Join or LeftJoin by calculating both sides, then doing the join It usually
- * better to use substitute algorithm (not this QueryIterator in other words) as
- * that is effectively indexing from one side into the other.
- */
-public class QueryIterJoinBase extends QueryIter {
- // This should be converted to a hash or sort-merge join.
- private final QueryIterator left;
- private final QueryIterator right;
- private final QueryIterator result;
-
- protected QueryIterJoinBase(QueryIterator left, QueryIterator right, JoinType joinType, ExprList exprs, ExecutionContext execCxt) {
- super(execCxt);
- this.left = left;
- this.right = right;
- this.result = calc(left, right, joinType, exprs, execCxt);
- }
-
- private static QueryIterator calc(QueryIterator left, QueryIterator right,
- JoinType joinType, ExprList exprs,
- ExecutionContext execCxt) {
- return Join.joinWorker(left, right, joinType, exprs, execCxt);
- }
-
- @Override
- protected boolean hasNextBinding() {
- return result.hasNext();
- }
-
- @Override
- protected Binding moveToNextBinding() {
- return result.nextBinding();
- }
-
- @Override
- protected void closeIterator() {
- left.close();
- right.close();
- result.close();
- }
-
- @Override
- protected void requestCancel() {
- left.cancel();
- right.cancel();
- result.cancel();
- }
-}
http://git-wip-us.apache.org/repos/asf/jena/blob/e7780fb2/jena-arq/src/main/java/org/apache/jena/sparql/engine/main/iterator/QueryIterLeftJoin.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/main/java/org/apache/jena/sparql/engine/main/iterator/QueryIterLeftJoin.java b/jena-arq/src/main/java/org/apache/jena/sparql/engine/main/iterator/QueryIterLeftJoin.java
deleted file mode 100644
index 4a442f7..0000000
--- a/jena-arq/src/main/java/org/apache/jena/sparql/engine/main/iterator/QueryIterLeftJoin.java
+++ /dev/null
@@ -1,32 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.jena.sparql.engine.main.iterator;
-
-import org.apache.jena.sparql.algebra.JoinType ;
-import org.apache.jena.sparql.engine.ExecutionContext ;
-import org.apache.jena.sparql.engine.QueryIterator ;
-import org.apache.jena.sparql.expr.ExprList ;
-
-/** Left join by materializing the RHS */
-public class QueryIterLeftJoin extends QueryIterJoinBase
-{
- public QueryIterLeftJoin(QueryIterator left, QueryIterator right, ExprList exprs, ExecutionContext qCxt) {
- super(left, right, JoinType.LEFT, exprs, qCxt) ;
- }
-}
[16/20] jena git commit: Easily switchable when use join() and
leftJoin().
Posted by an...@apache.org.
Easily switchable when use join() and leftJoin().
Project: http://git-wip-us.apache.org/repos/asf/jena/repo
Commit: http://git-wip-us.apache.org/repos/asf/jena/commit/7e25172e
Tree: http://git-wip-us.apache.org/repos/asf/jena/tree/7e25172e
Diff: http://git-wip-us.apache.org/repos/asf/jena/diff/7e25172e
Branch: refs/heads/master
Commit: 7e25172e8ab8823e8b77e62dffb9ecdac243d56d
Parents: abf68b0
Author: Andy Seaborne <an...@apache.org>
Authored: Tue Sep 8 17:55:40 2015 +0100
Committer: Andy Seaborne <an...@apache.org>
Committed: Tue Sep 8 17:55:40 2015 +0100
----------------------------------------------------------------------
.../apache/jena/sparql/engine/join/Join.java | 118 +++++++++++--------
1 file changed, 70 insertions(+), 48 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/jena/blob/7e25172e/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 4d4523f..5b09544 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
@@ -18,13 +18,11 @@
package org.apache.jena.sparql.engine.join;
-import static org.apache.jena.sparql.algebra.JoinType.LEFT ;
-import static org.apache.jena.sparql.algebra.JoinType.INNER ;
-
import java.util.List ;
import org.apache.jena.atlas.iterator.Iter ;
import org.apache.jena.atlas.lib.DS ;
+import org.apache.jena.atlas.lib.NotImplemented ;
import org.apache.jena.sparql.algebra.Algebra ;
import org.apache.jena.sparql.algebra.JoinType ;
import org.apache.jena.sparql.algebra.Table ;
@@ -43,11 +41,10 @@ import org.apache.jena.sparql.expr.ExprList ;
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
- // *******************
+ private final static boolean useNestedLoopJoin = false ;
+ private final static boolean useNestedLoopLeftJoin = false ;
+
/**
* Standard entry point to a join of two streams.
* This is not a substitution/index join.
@@ -58,7 +55,9 @@ public class Join {
* @return QueryIterator
*/
public static QueryIterator join(QueryIterator left, QueryIterator right, ExecutionContext execCxt) {
- return joinWorker(left, right, INNER, null, execCxt) ;
+ if ( useNestedLoopJoin )
+ return nestedLoopJoin(left, right, execCxt) ;
+ return hashJoin(left, right, execCxt) ;
}
/** Standard entry point to a left join of two streams.
@@ -72,7 +71,10 @@ public class Join {
* @return QueryIterator
*/
public static QueryIterator leftJoin(QueryIterator left, QueryIterator right, ExprList conditions, ExecutionContext execCxt) {
- return joinWorker(left, right, LEFT, conditions, execCxt) ;
+// if ( useNestedLoopJoin )
+// return nestedLoopLeftJoin(left, right, conditions, execCxt) ;
+// return hashLeftJoin(left, right, execCxt) ;
+ return nestedLoopLeftJoin(left, right, conditions, execCxt) ;
}
@@ -80,6 +82,8 @@ public class Join {
* Standard entry point to a join of two streams.
* This is not a substitution/index join.
* (See {@link OpExecutor} for streamed execution using substitution).
+ * @deprecated Do not use directly.
+ *
* @param left
* @param right
* @param joinType
@@ -87,67 +91,85 @@ public class Join {
* @param execCxt
* @return QueryIterator
*/
+ @Deprecated
public static QueryIterator joinWorker(QueryIterator left, QueryIterator right,
JoinType joinType, ExprList conditions,
ExecutionContext execCxt) {
- // Catch easy cases.
- // If left or right is a root, do fast.
-// if ( right.isEmpty() ) {
-// if ( joinType == PLAIN ) {
-// // No rows - no match
-// left.close() ;
-// return QueryIterNullIterator.create(execCxt) ;
-// }
-// else
-// // Left join - pass out left rows regardless of conditions.
-// return left ;
-// }
-//
-// if ( TableUnit.isTableUnit(right) )
-// return applyConditions(left, conditions, execCxt) ;
-// return joinWorkerN(left, right, joinType, conditions, execCxt) ;
- // XXX TEMPORARY!
- //throw new NotImplemented() ;
- Table t = TableFactory.create(right) ;
- return TableJoin.joinWorker(left, t, joinType, conditions, execCxt) ;
+ if ( false ) {
+ // Safe, and slow.
+ switch(joinType) {
+ case INNER: return nestedLoopJoin(left, right, execCxt) ;
+ case LEFT: return nestedLoopLeftJoin(left, right, conditions, execCxt) ;
+ default: throw new NotImplemented("JoinType "+joinType+" not implemented") ;
+ }
+ }
+ if ( false ) {
+ // Very safe, and slow.
+ switch(joinType) {
+ case INNER: return nestedLoopJoinBasic(left, right, execCxt) ;
+ case LEFT: return nestedLoopLeftJoinBasic(left, right, conditions, execCxt) ;
+ default: throw new NotImplemented("JoinType "+joinType+" not implemented") ;
+ }
+ }
+
+ if ( false ) {
+ // Very safe, well used old code. And slow.
+ Table t = TableFactory.create(right) ;
+ return TableJoin.joinWorker(left, t, joinType, conditions, execCxt) ;
+ }
+
+ // Normal.
+ switch(joinType) {
+ case INNER: return join(left, right, execCxt) ;
+ case LEFT: return leftJoin(left, right, conditions, execCxt) ;
+ default: throw new NotImplemented("JoinType "+joinType+" not implemented") ;
+ }
}
-
-
+
/** Inner loop join.
* Cancellable.
* @param left Left hand side
* @param right Right hand side
- * @param cxt ExecutionContext
+ * @param execCxt ExecutionContext
* @return QueryIterator
*/
- public static QueryIterator nestedLoopJoin(QueryIterator left, QueryIterator right, ExecutionContext cxt) {
- return new QueryIterNestedLoopJoin(left, right, cxt) ;
+ public static QueryIterator nestedLoopJoin(QueryIterator left, QueryIterator right, ExecutionContext execCxt) {
+ return new QueryIterNestedLoopJoin(left, right, execCxt) ;
}
/** Inner loop join.
* Cancellable.
* @param left Left hand side
* @param right Right hand side
- * @param cxt ExecutionContext
+ * @param execCxt ExecutionContext
* @return QueryIterator
*/
- public static QueryIterator nestedLoopLeftJoin(QueryIterator left, QueryIterator right, ExprList conditions, ExecutionContext cxt) {
- return new QueryIterNestedLoopLeftJoin(left, right, conditions, cxt) ;
+ public static QueryIterator nestedLoopLeftJoin(QueryIterator left, QueryIterator right, ExprList conditions, ExecutionContext execCxt) {
+ return new QueryIterNestedLoopLeftJoin(left, right, conditions, execCxt) ;
}
- /** Evaluate a hash join. This code materializes the left into a probe table
- * then hash joins from the right.
- * No cancelation, no stats.
+ /** Evaluate using a hash join.
+ *
+ * @param left Left hand side
+ * @param right Right hand side
+ * @param execCxt ExecutionContext
+ * @return QueryIterator
+ */
+ public static QueryIterator hashJoin(QueryIterator left, QueryIterator right, ExecutionContext execCxt) {
+ return QueryIterHashJoin.create(left, right, execCxt) ;
+ }
+
+ /** Evaluate using a hash join.
*
* @param joinKey The key for the probe table.
* @param left Left hand side
* @param right Right hand side
- * @param cxt ExecutionContext
+ * @param execCxt ExecutionContext
* @return QueryIterator
*/
- public static QueryIterator hashJoin(JoinKey joinKey, QueryIterator left, QueryIterator right, ExecutionContext cxt) {
- return new QueryIterHashJoin(joinKey, left, right, cxt) ;
+ public static QueryIterator hashJoin(JoinKey joinKey, QueryIterator left, QueryIterator right, ExecutionContext execCxt) {
+ return QueryIterHashJoin.create(joinKey, left, right, execCxt) ;
}
/** Very simple, materializing version - useful for debugging.
@@ -157,7 +179,7 @@ public class Join {
*
* @see #nestedLoopJoin
*/
- public static QueryIterator nestedLoopJoinBasic(QueryIterator left, QueryIterator right, ExecutionContext cxt) {
+ public static QueryIterator nestedLoopJoinBasic(QueryIterator left, QueryIterator right, ExecutionContext execCxt) {
List<Binding> leftRows = Iter.toList(left) ;
List<Binding> output = DS.list() ;
for ( ; right.hasNext() ; ) {
@@ -168,14 +190,14 @@ public class Join {
output.add(r) ;
}
}
- return new QueryIterPlainWrapper(output.iterator(), cxt) ;
+ return new QueryIterPlainWrapper(output.iterator(), execCxt) ;
}
/** 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) {
+ public static QueryIterator nestedLoopLeftJoinBasic(QueryIterator left, QueryIterator right, ExprList condition, ExecutionContext execCxt) {
// Stream from left, materialize right.
List<Binding> rightRows = Iter.toList(right) ;
List<Binding> output = DS.list() ;
@@ -193,8 +215,8 @@ public class Join {
if ( ! match )
output.add(row1) ;
}
- QueryIterator qIter = new QueryIterPlainWrapper(output.iterator(), cxt) ;
- qIter = applyConditions(qIter, condition, cxt) ;
+ QueryIterator qIter = new QueryIterPlainWrapper(output.iterator(), execCxt) ;
+ qIter = applyConditions(qIter, condition, execCxt) ;
return qIter ;
}
[13/20] jena git commit: Fix comment.
Posted by an...@apache.org.
Fix comment.
Project: http://git-wip-us.apache.org/repos/asf/jena/repo
Commit: http://git-wip-us.apache.org/repos/asf/jena/commit/85eff501
Tree: http://git-wip-us.apache.org/repos/asf/jena/tree/85eff501
Diff: http://git-wip-us.apache.org/repos/asf/jena/diff/85eff501
Branch: refs/heads/master
Commit: 85eff50190394c82ee7e712a28540c8625d3b706
Parents: b2ece9a
Author: Andy Seaborne <an...@apache.org>
Authored: Tue Sep 8 17:40:48 2015 +0100
Committer: Andy Seaborne <an...@apache.org>
Committed: Tue Sep 8 17:40:48 2015 +0100
----------------------------------------------------------------------
.../java/org/apache/jena/sparql/engine/iterator/QueryIter2.java | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/jena/blob/85eff501/jena-arq/src/main/java/org/apache/jena/sparql/engine/iterator/QueryIter2.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/main/java/org/apache/jena/sparql/engine/iterator/QueryIter2.java b/jena-arq/src/main/java/org/apache/jena/sparql/engine/iterator/QueryIter2.java
index d017573..ba5118e 100644
--- a/jena-arq/src/main/java/org/apache/jena/sparql/engine/iterator/QueryIter2.java
+++ b/jena-arq/src/main/java/org/apache/jena/sparql/engine/iterator/QueryIter2.java
@@ -64,7 +64,7 @@ public abstract class QueryIter2 extends QueryIter
/** Cancellation of the query execution is happening */
protected abstract void requestSubCancel() ;
- /** Pass on the close method - no need to close the left or right QueryIterators passed to the QueryIter1 constructor */
+ /** Pass on the close method - no need to close the left or right QueryIterators passed to the QueryIter2 constructor */
protected abstract void closeSubIterator() ;
// Do better
[14/20] jena git commit: Null joinKey if unset.
Posted by an...@apache.org.
Null joinKey if unset.
Project: http://git-wip-us.apache.org/repos/asf/jena/repo
Commit: http://git-wip-us.apache.org/repos/asf/jena/commit/1df6ee49
Tree: http://git-wip-us.apache.org/repos/asf/jena/tree/1df6ee49
Diff: http://git-wip-us.apache.org/repos/asf/jena/diff/1df6ee49
Branch: refs/heads/master
Commit: 1df6ee49ee589fdf71b3bd9f70df72c18a5e4a0a
Parents: 85eff50
Author: Andy Seaborne <an...@apache.org>
Authored: Tue Sep 8 17:42:12 2015 +0100
Committer: Andy Seaborne <an...@apache.org>
Committed: Tue Sep 8 17:42:12 2015 +0100
----------------------------------------------------------------------
.../org/apache/jena/sparql/engine/join/AbstractTestJoin.java | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/jena/blob/1df6ee49/jena-arq/src/test/java/org/apache/jena/sparql/engine/join/AbstractTestJoin.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/test/java/org/apache/jena/sparql/engine/join/AbstractTestJoin.java b/jena-arq/src/test/java/org/apache/jena/sparql/engine/join/AbstractTestJoin.java
index 2ed9647..434af09 100644
--- a/jena-arq/src/test/java/org/apache/jena/sparql/engine/join/AbstractTestJoin.java
+++ b/jena-arq/src/test/java/org/apache/jena/sparql/engine/join/AbstractTestJoin.java
@@ -235,8 +235,10 @@ public abstract class AbstractTestJoin extends Assert {
joinKey = JoinKey.create(Var.alloc(var)) ;
}
else {
- // No vars in join key. Legal, albeit silly.
- joinKey = new JoinKey.Builder().build() ;
+ // No vars in join key. Allow implementation to decide
+ // if needed. Join keys are only needed for hash join
+ // (and related algorithms).
+ joinKey = null ;
}
executeTest(joinKey, left, right, null, tableOut) ;
[08/20] jena git commit: Minor
Posted by an...@apache.org.
Minor
Project: http://git-wip-us.apache.org/repos/asf/jena/repo
Commit: http://git-wip-us.apache.org/repos/asf/jena/commit/8656a459
Tree: http://git-wip-us.apache.org/repos/asf/jena/tree/8656a459
Diff: http://git-wip-us.apache.org/repos/asf/jena/diff/8656a459
Branch: refs/heads/master
Commit: 8656a45978397ab3129c033d1bd2a0eaa1d0b77c
Parents: 723daa2
Author: Andy Seaborne <an...@apache.org>
Authored: Tue Sep 8 14:18:21 2015 +0100
Committer: Andy Seaborne <an...@apache.org>
Committed: Tue Sep 8 14:18:21 2015 +0100
----------------------------------------------------------------------
.../jena/sparql/engine/join/QueryIterNestedLoopJoin.java | 10 +++-------
1 file changed, 3 insertions(+), 7 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/jena/blob/8656a459/jena-arq/src/main/java/org/apache/jena/sparql/engine/join/QueryIterNestedLoopJoin.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/main/java/org/apache/jena/sparql/engine/join/QueryIterNestedLoopJoin.java b/jena-arq/src/main/java/org/apache/jena/sparql/engine/join/QueryIterNestedLoopJoin.java
index 0208697..19684c3 100644
--- a/jena-arq/src/main/java/org/apache/jena/sparql/engine/join/QueryIterNestedLoopJoin.java
+++ b/jena-arq/src/main/java/org/apache/jena/sparql/engine/join/QueryIterNestedLoopJoin.java
@@ -32,7 +32,7 @@ import org.apache.jena.sparql.engine.iterator.QueryIter2;
* Nested Loop Join (materializing on the left, streaming on the right)
* A simple, dependable join.
* <p>
- * See {@link Join#innerLoopJoinBasic} for a very simple implementation for
+ * See {@link Join#nestedLoopLeftJoinBasic} for a very simple implementation for
* testing purposes only.
*/
public class QueryIterNestedLoopJoin extends QueryIter2 {
@@ -50,9 +50,8 @@ public class QueryIterNestedLoopJoin extends QueryIter2 {
public QueryIterNestedLoopJoin(QueryIterator left, QueryIterator right, ExecutionContext cxt) {
super(left, right, cxt);
- List<Binding> rowsLeftList = Iter.toList(left);
- leftRows = rowsLeftList;
- s_countLHS = rowsLeftList.size();
+ leftRows = Iter.toList(left);
+ s_countLHS = leftRows.size();
this.right = right;
}
@@ -98,9 +97,6 @@ public class QueryIterNestedLoopJoin extends QueryIter2 {
if ( r != null ) {
s_countResults++;
return r;
- } else {
- // XXX LeftJoin
- //return rowLeft ;
}
}
// Nothing more for this rowRight.
[15/20] jena git commit: Use "Join" for OpJoin and OpLeftJoin.
Posted by an...@apache.org.
Use "Join" for OpJoin and OpLeftJoin.
Project: http://git-wip-us.apache.org/repos/asf/jena/repo
Commit: http://git-wip-us.apache.org/repos/asf/jena/commit/abf68b08
Tree: http://git-wip-us.apache.org/repos/asf/jena/tree/abf68b08
Diff: http://git-wip-us.apache.org/repos/asf/jena/diff/abf68b08
Branch: refs/heads/master
Commit: abf68b081141757397a692421406c2a3291a1ed8
Parents: 1df6ee4
Author: Andy Seaborne <an...@apache.org>
Authored: Tue Sep 8 17:42:49 2015 +0100
Committer: Andy Seaborne <an...@apache.org>
Committed: Tue Sep 8 17:42:49 2015 +0100
----------------------------------------------------------------------
.../java/org/apache/jena/sparql/engine/main/OpExecutor.java | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/jena/blob/abf68b08/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 709f735..801a48e 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
@@ -39,6 +39,7 @@ 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.* ;
+import org.apache.jena.sparql.engine.join.Join ;
import org.apache.jena.sparql.engine.main.iterator.* ;
import org.apache.jena.sparql.expr.Expr ;
import org.apache.jena.sparql.expr.ExprList ;
@@ -218,14 +219,14 @@ public class OpExecutor
}
QueryIterator left = exec(opJoin.getLeft(), input) ;
QueryIterator right = exec(opJoin.getRight(), root()) ;
- QueryIterator qIter = new QueryIterJoin(left, right, execCxt) ;
+ // Join key.
+ QueryIterator qIter = Join.join(left, right, execCxt) ;
return qIter ;
}
// Pass iterator from one step directly into the next.
protected QueryIterator execute(OpSequence opSequence, QueryIterator input) {
QueryIterator qIter = input ;
-
for (Iterator<Op> iter = opSequence.iterator(); iter.hasNext();) {
Op sub = iter.next() ;
qIter = exec(sub, qIter) ;
@@ -236,7 +237,7 @@ public class OpExecutor
protected QueryIterator execute(OpLeftJoin opLeftJoin, QueryIterator input) {
QueryIterator left = exec(opLeftJoin.getLeft(), input) ;
QueryIterator right = exec(opLeftJoin.getRight(), root()) ;
- QueryIterator qIter = new QueryIterLeftJoin(left, right, opLeftJoin.getExprs(), execCxt) ;
+ QueryIterator qIter = Join.leftJoin(left, right, opLeftJoin.getExprs(), execCxt) ;
return qIter ;
}
[12/20] jena git commit: Left join tests
Posted by an...@apache.org.
Left join tests
Project: http://git-wip-us.apache.org/repos/asf/jena/repo
Commit: http://git-wip-us.apache.org/repos/asf/jena/commit/b2ece9ad
Tree: http://git-wip-us.apache.org/repos/asf/jena/tree/b2ece9ad
Diff: http://git-wip-us.apache.org/repos/asf/jena/diff/b2ece9ad
Branch: refs/heads/master
Commit: b2ece9ad7c485fddda7c09a02f3d731a74b00123
Parents: d674763
Author: Andy Seaborne <an...@apache.org>
Authored: Tue Sep 8 14:19:35 2015 +0100
Committer: Andy Seaborne <an...@apache.org>
Committed: Tue Sep 8 14:19:35 2015 +0100
----------------------------------------------------------------------
.../engine/join/AbstractTestInnerJoin.java | 124 ++--------
.../sparql/engine/join/AbstractTestJoin.java | 231 +++++++++++++++++--
.../engine/join/AbstractTestLeftJoin.java | 153 +++---------
.../apache/jena/sparql/engine/join/TS_Join.java | 5 +
.../jena/sparql/engine/join/TestHashJoin.java | 3 +-
.../sparql/engine/join/TestJoinNestedLoop.java | 5 +-
.../engine/join/TestJoinNestedLoopSimple.java | 5 +-
.../jena/sparql/engine/join/TestJoinSimple.java | 3 +-
.../engine/join/TestLeftJoinNestedLoop.java | 35 +++
.../join/TestLeftJoinNestedLoopSimple.java | 35 +++
.../sparql/engine/join/TestLeftJoinSimple.java | 6 +-
11 files changed, 348 insertions(+), 257 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/jena/blob/b2ece9ad/jena-arq/src/test/java/org/apache/jena/sparql/engine/join/AbstractTestInnerJoin.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/test/java/org/apache/jena/sparql/engine/join/AbstractTestInnerJoin.java b/jena-arq/src/test/java/org/apache/jena/sparql/engine/join/AbstractTestInnerJoin.java
index f5a1bdc..0242d4a 100644
--- a/jena-arq/src/test/java/org/apache/jena/sparql/engine/join/AbstractTestInnerJoin.java
+++ b/jena-arq/src/test/java/org/apache/jena/sparql/engine/join/AbstractTestInnerJoin.java
@@ -19,123 +19,29 @@
package org.apache.jena.sparql.engine.join;
import org.apache.jena.sparql.algebra.Table ;
-import org.apache.jena.sparql.core.Var ;
-import org.apache.jena.sparql.engine.join.JoinKey ;
+import org.apache.jena.sparql.expr.ExprList ;
import org.junit.Test ;
/** Tests for inner/equi joins */
public abstract class AbstractTestInnerJoin extends AbstractTestJoin {
@Override
- protected void executeTest(JoinKey joinKey, Table left, Table right, Table expectedResults) {
- executeTestJoin("1", joinKey, left, right, expectedResults) ;
- executeTestJoin("2", joinKey, right, left, expectedResults) ;
+ protected void executeTest(JoinKey joinKey, Table left, Table right, ExprList conditions, Table expectedResults) {
+ if ( conditions != null )
+ fail("Conditions on inner join are meaningless (currently)") ;
+ // No conditions.
+ // Commutative.
+ executeTestJoin("1", joinKey, left, right, null, expectedResults) ;
+ executeTestJoin("2", joinKey, right, left, null, expectedResults) ;
}
- static Var var_a = Var.alloc("a") ;
- static Var var_b = Var.alloc("b") ;
- static Var var_c = Var.alloc("c") ;
- static Var var_d = Var.alloc("d") ;
-
- static Table table0() { return parseTableInt("(table)") ; }
-
- // Table of one row and no colums.
- static Table table1() {
- return parseTableInt("(table (row))") ; }
-
- static Table tableD1() {
- return parseTableInt("(table",
- " (row (?a 1) (?b 2))",
- " (row (?a 1) (?b 3))",
- " (row (?a 1) (?b 2))",
- ")") ;
- }
-
- static Table tableD2() {
- return parseTableInt("(table",
- " (row (?a 0) (?d 8))",
- " (row (?a 1) (?c 9))",
- ")") ;
- }
-
- static Table tableD3() {
- return parseTableInt("(table",
- " (row (?a 1) (?c 9) (?b 2))",
- " (row (?a 1) (?c 9) (?b 3))",
- " (row (?a 1) (?c 9) (?b 2))",
- ")") ;
- }
-
- static Table tableD4() {
- return parseTableInt("(table",
- " (row (?a 1) (?b 2))",
- " (row (?a 1) (?b 3))",
- " (row (?a 4) (?b 4))",
- " (row (?a 4) (?b 5))",
- ")") ;
- }
-
- static Table tableD5() {
- return parseTableInt("(table",
- " (row (?a 4) (?c 4))",
- " (row (?a 4) (?c 5))",
- " (row (?a 6) (?c 5))",
- ")") ;
- }
-
- static Table tableD6() {
- return parseTableInt("(table",
- " (row (?a 1) (?c 2))",
- " (row (?a 1) (?c 3))",
- " (row (?a 4) (?c 4))",
- " (row (?a 4) (?c 5))",
- ")") ;
- }
-
- static Table tableD4x5() {
- return parseTableInt("(table",
- " (row (?a 4) (?c 4) (?b 4))",
- " (row (?a 4) (?c 4) (?b 5))",
- " (row (?a 4) (?c 5) (?b 4))",
- " (row (?a 4) (?c 5) (?b 5))",
- ")") ;
- }
-
- static Table tableD4x6() {
- return parseTableInt("(table",
- " (row (?a 1) (?c 2) (?b 2))",
- " (row (?a 1) (?c 2) (?b 3))",
- " (row (?a 1) (?c 3) (?b 2))",
- " (row (?a 1) (?c 3) (?b 3))",
- " (row (?a 4) (?c 4) (?b 4))",
- " (row (?a 4) (?c 4) (?b 5))",
- " (row (?a 4) (?c 5) (?b 4))",
- " (row (?a 4) (?c 5) (?b 5))",
- ")") ;
- }
-
- // Disjoint.
- static Table tableD8() {
- return parseTableInt("(table",
- " (row (?x 10))",
- " (row (?z 11))",
- ")") ;
- }
-
- // Table8 crossproduct table2
- static Table tableD8x2() {
- return parseTableInt("(table",
- " (row (?a 0) (?d 8) (?z 11))",
- " (row (?a 0) (?d 8) (?x 10))",
- " (row (?a 1) (?c 9) (?z 11))",
- " (row (?a 1) (?c 9) (?x 10))",
- ")") ;
- }
-
- @Test public void join_00() { testJoin("a", table0(), table0(), table0()) ; }
- @Test public void join_00a() { testJoin("a", table1(), table0(), table0()) ; }
- @Test public void join_00b() { testJoin("a", tableD1(), table1(), tableD1()) ; }
- @Test public void join_00c() { testJoin("z", tableD1(), table1(), tableD1()) ; }
+ @Test public void join_basic_1() { testJoin("a", table0(), table0(), table0()) ; }
+ @Test public void join_basic_2() { testJoin("a", table1(), table0(), table0()) ; }
+ @Test public void join_basic_3() { testJoin("a", tableD1(), table1(), tableD1()) ; }
+ @Test public void join_basic_4() { testJoin("z", tableD1(), table1(), tableD1()) ; }
+
+ @Test public void join_basic_5() { testJoin("a", table0(), table1(), table0()) ; }
+ @Test public void join_basic_6() { testJoin("a", table1(), table0(), table0()) ; }
@Test public void join_01() { testJoin("a", table0(), tableD2(), table0()) ; }
@Test public void join_02() { testJoin("a", tableD1(), table0(), table0()) ; }
http://git-wip-us.apache.org/repos/asf/jena/blob/b2ece9ad/jena-arq/src/test/java/org/apache/jena/sparql/engine/join/AbstractTestJoin.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/test/java/org/apache/jena/sparql/engine/join/AbstractTestJoin.java b/jena-arq/src/test/java/org/apache/jena/sparql/engine/join/AbstractTestJoin.java
index b48c66b..2ed9647 100644
--- a/jena-arq/src/test/java/org/apache/jena/sparql/engine/join/AbstractTestJoin.java
+++ b/jena-arq/src/test/java/org/apache/jena/sparql/engine/join/AbstractTestJoin.java
@@ -29,19 +29,205 @@ import org.apache.jena.sparql.algebra.TableFactory ;
import org.apache.jena.sparql.core.Var ;
import org.apache.jena.sparql.engine.QueryIterator ;
import org.apache.jena.sparql.engine.binding.Binding ;
-import org.apache.jena.sparql.engine.join.JoinKey ;
+import org.apache.jena.sparql.expr.ExprList ;
import org.apache.jena.sparql.resultset.ResultSetCompare ;
import org.apache.jena.sparql.sse.SSE ;
import org.junit.Assert ;
/** Tests for inner/equi joins */
public abstract class AbstractTestJoin extends Assert {
+
+ protected static Table table0() { return parseTableInt("(table)") ; }
+
+ // Table of one row and no colums.
+ protected static Table table1() {
+ return parseTableInt("(table (row))") ; }
+
+ protected static Table tableD1() {
+ return parseTableInt("(table",
+ " (row (?a 1) (?b 2))",
+ " (row (?a 1) (?b 3))",
+ " (row (?a 1) (?b 2))",
+ ")") ;
+ }
+
+ protected static Table tableD2() {
+ return parseTableInt("(table",
+ " (row (?a 0) (?d 8))",
+ " (row (?a 1) (?c 9))",
+ ")") ;
+ }
+
+ protected static Table tableD3() {
+ return parseTableInt("(table",
+ " (row (?a 1) (?c 9) (?b 2))",
+ " (row (?a 1) (?c 9) (?b 3))",
+ " (row (?a 1) (?c 9) (?b 2))",
+ ")") ;
+ }
+
+ protected static Table tableD3_LJ() {
+ return parseTableInt("(table",
+ " (row (?d 8) (?a 0))",
+ " (row (?a 1) (?c 9) (?b 2))",
+ " (row (?a 1) (?c 9) (?b 3))",
+ " (row (?a 1) (?c 9) (?b 2))",
+
+ ")") ;
+ }
+
+ protected static Table tableD4() {
+ return parseTableInt("(table",
+ " (row (?a 1) (?b 2))",
+ " (row (?a 1) (?b 3))",
+ " (row (?a 4) (?b 4))",
+ " (row (?a 4) (?b 5))",
+ ")") ;
+ }
+
+ protected static Table tableD5() {
+ return parseTableInt("(table",
+ " (row (?a 4) (?c 4))",
+ " (row (?a 4) (?c 5))",
+ " (row (?a 6) (?c 5))",
+ ")") ;
+ }
+
+ protected static Table tableD6() {
+ return parseTableInt("(table",
+ " (row (?a 1) (?c 2))",
+ " (row (?a 1) (?c 3))",
+ " (row (?a 4) (?c 4))",
+ " (row (?a 4) (?c 5))",
+ ")") ;
+ }
+
+ protected static Table tableD4x5() {
+ return parseTableInt("(table",
+ " (row (?a 4) (?c 4) (?b 4))",
+ " (row (?a 4) (?c 4) (?b 5))",
+ " (row (?a 4) (?c 5) (?b 4))",
+ " (row (?a 4) (?c 5) (?b 5))",
+ ")") ;
+ }
+
+ protected static Table tableD4x5_LJ() {
+ return parseTableInt("(table",
+ " (row (?a 4) (?c 4) (?b 4))",
+ " (row (?a 4) (?c 4) (?b 5))",
+ " (row (?a 4) (?c 5) (?b 4))",
+ " (row (?a 4) (?c 5) (?b 5))",
+ " (row (?b 2) (?a 1))",
+ " (row (?b 3) (?a 1))",
+ ")") ;
+ }
+
+ protected static Table tableD5x4_LJ() {
+ return parseTableInt("(table",
+ " (row (?a 4) (?c 4) (?b 4))",
+ " (row (?a 4) (?c 4) (?b 5))",
+ " (row (?a 4) (?c 5) (?b 4))",
+ " (row (?a 4) (?c 5) (?b 5))",
+ " (row (?a 6) (?c 5))",
+ ")") ;
+ }
+
+ protected static Table tableD4x6() {
+ return parseTableInt("(table",
+ " (row (?a 1) (?c 2) (?b 2))",
+ " (row (?a 1) (?c 2) (?b 3))",
+ " (row (?a 1) (?c 3) (?b 2))",
+ " (row (?a 1) (?c 3) (?b 3))",
+ " (row (?a 4) (?c 4) (?b 4))",
+ " (row (?a 4) (?c 4) (?b 5))",
+ " (row (?a 4) (?c 5) (?b 4))",
+ " (row (?a 4) (?c 5) (?b 5))",
+ ")") ;
+ }
+
+ // Disjoint.
+ protected static Table tableD8() {
+ return parseTableInt("(table",
+ " (row (?x 10))",
+ " (row (?z 11))",
+ ")") ;
+ }
+
+ // Table8 crossproduct table2
+ protected static Table tableD8x2() {
+ return parseTableInt("(table",
+ " (row (?a 0) (?d 8) (?z 11))",
+ " (row (?a 0) (?d 8) (?x 10))",
+ " (row (?a 1) (?c 9) (?z 11))",
+ " (row (?a 1) (?c 9) (?x 10))",
+ ")") ;
+ }
+
+ // Left join data tables.
+ protected static Table tableL1() {
+ return parseTableInt("(table",
+ " (row (?a 0) (?d 8))",
+ " (row (?a 3) (?d 9))",
+ ")") ;
+ }
+
+ protected static Table tableL2() {
+ return parseTableInt("(table",
+ " (row (?a 0) (?z 11))",
+ " (row (?a 1) (?c 9) (?z 11))",
+ ")") ;
+ }
+
+ // L3 := L1 leftjoin L2
+ protected static Table table1LJ2() {
+ return parseTableInt("(table",
+ " (row (?a 0) (?d 8) (?z 11))",
+ " (row (?a 3) (?d 9))",
+ ")") ;
+ }
+
+ protected static Table tableL4() {
+ return parseTableInt("(table",
+ " (row (?a 0) (?z 11))",
+ " (row (?a 0) (?z 12))",
+ " (row (?r 99))",
+ " (row (?c 9) (?z 11))",
+ ")") ;
+ }
+
+ protected static Table tableL5() {
+ return parseTableInt("(table",
+ " (row (?a 0) (?d 8))",
+ " (row (?a 1) (?c 9) (?z 11))",
+ ")") ;
+ }
+
+ // L3 := L1 leftjoin L2
+ protected static Table table4LJ5() {
+ return parseTableInt("(table",
+ " (row (?a 0) (?d 8) (?z 11))",
+ " (row (?a 0) (?d 8) (?z 12))",
+
+ " (row (?a 0) (?d 8) (?r 99))",
+ " (row (?a 1) (?c 9) (?z 11) (?r 99))",
+
+ " (row (?a 0) (?d 8) (?c 9) (?z 11))",
+ " (row (?a 1) (?c 9) (?z 11))",
+ ")") ;
+ }
+
+ // Code
+
protected static Table parseTableInt(String... strings) {
String x = StrUtils.strjoinNL(strings) ;
return SSE.parseTable(x) ;
}
protected void testJoin(String var, Table left, Table right, Table tableOut) {
+ testJoin(var, left, right, null, tableOut);
+ }
+
+ protected void testJoin(String var, Table left, Table right, ExprList conditions, Table tableOut) {
JoinKey joinKey ;
if ( var != null ) {
if ( var.startsWith("?") )
@@ -53,38 +239,49 @@ public abstract class AbstractTestJoin extends Assert {
joinKey = new JoinKey.Builder().build() ;
}
- executeTest(joinKey, left, right, tableOut) ;
+ executeTest(joinKey, left, right, null, tableOut) ;
}
- protected abstract void executeTest(JoinKey joinKey, Table left, Table right, Table expectedResults) ;
-
+ // Any kind of join (choose by abstract join() operation).
+ protected abstract void executeTest(JoinKey joinKey, Table left, Table right, ExprList conditions, Table expectedResults) ;
private List<Binding> toList(Table table) {
return Iter.toList(table.rows()) ;
}
- protected void executeTestJoin(String num, JoinKey joinKey, Table left, Table right, Table expectedResults) {
- Table x1 = joinMaterialize(joinKey, left, right) ;
- assertNotNull("Null table from join ("+num+")", x1) ;
- check("Results not equal ("+num+")", joinKey, left, right, expectedResults, x1) ;
+ protected void executeTestJoin(String msg, JoinKey joinKey, Table left, Table right, ExprList conditions, Table expectedResults) {
+ Table x1 = joinMaterialize(joinKey, left, right, conditions) ;
+ assertNotNull("Null table from join ("+msg+")", x1) ;
+ if ( false ) {
+ System.out.println("Test : "+msg) ;
+ System.out.println("Joinkey: "+joinKey) ;
+ System.out.println("Left: \n"+left) ;
+ System.out.println("Right: \n"+right) ;
+ System.out.println("Expected: \n"+expectedResults) ;
+ System.out.println("Actual: \n"+x1) ;
+ System.out.println() ;
+ }
+
+ check("Results not equal ("+msg+")", joinKey, left, right, expectedResults, x1) ;
}
- private Table joinMaterialize(JoinKey joinKey, Table left, Table right) {
- QueryIterator qIter = join(joinKey, left , right) ;
+ private Table joinMaterialize(JoinKey joinKey, Table left, Table right, ExprList conditions) {
+ QueryIterator qIter = join(joinKey, left , right, null) ;
return TableFactory.create(qIter) ;
}
- public abstract QueryIterator join(JoinKey joinKey , Table left , Table right) ;
+ public abstract QueryIterator join(JoinKey joinKey, Table left , Table right, ExprList conditions) ;
private static void check(String msg, JoinKey joinKey, Table left, Table right, Table expected, Table actual) {
boolean b = equalTables(expected, actual) ;
if ( ! b ) {
- System.out.println("Joinkey: "+joinKey) ;
- System.out.println("Left: \n"+left) ;
- System.out.println("Right: \n"+right) ;
- System.out.println("Expected: \n"+expected) ;
- System.out.println("Actual: \n"+actual) ;
- System.out.println() ;
+ System.out.flush() ;
+ System.err.println("Joinkey: "+joinKey) ;
+ System.err.println("Left: \n"+left) ;
+ System.err.println("Right: \n"+right) ;
+ System.err.println("Expected: \n"+expected) ;
+ System.err.println("Actual: \n"+actual) ;
+ System.err.println() ;
}
assertTrue(msg, b) ;
http://git-wip-us.apache.org/repos/asf/jena/blob/b2ece9ad/jena-arq/src/test/java/org/apache/jena/sparql/engine/join/AbstractTestLeftJoin.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/test/java/org/apache/jena/sparql/engine/join/AbstractTestLeftJoin.java b/jena-arq/src/test/java/org/apache/jena/sparql/engine/join/AbstractTestLeftJoin.java
index 57756ff..2786bed 100644
--- a/jena-arq/src/test/java/org/apache/jena/sparql/engine/join/AbstractTestLeftJoin.java
+++ b/jena-arq/src/test/java/org/apache/jena/sparql/engine/join/AbstractTestLeftJoin.java
@@ -19,146 +19,55 @@
package org.apache.jena.sparql.engine.join;
import org.apache.jena.sparql.algebra.Table ;
-import org.apache.jena.sparql.core.Var ;
-import org.apache.jena.sparql.engine.join.JoinKey ;
+import org.apache.jena.sparql.expr.ExprList ;
import org.junit.Test ;
public abstract class AbstractTestLeftJoin extends AbstractTestJoin {
- @Override
- protected void executeTest(JoinKey joinKey, Table left, Table right, Table expectedResults) {
- executeTestJoin("LJ", joinKey, left, right, expectedResults) ;
- }
- static Var var_a = Var.alloc("a") ;
- static Var var_b = Var.alloc("b") ;
- static Var var_c = Var.alloc("c") ;
- static Var var_d = Var.alloc("d") ;
-
- static Table table0() { return parseTableInt("(table)") ; }
-
- // Table of one row and no colums.
- static Table table1() {
- return parseTableInt("(table (row))") ; }
-
- static Table tableD1() {
- return parseTableInt("(table",
- " (row (?a 1) (?b 2))",
- " (row (?a 1) (?b 3))",
- " (row (?a 1) (?b 2))",
- ")") ;
- }
-
- static Table tableD2() {
- return parseTableInt("(table",
- " (row (?a 0) (?d 8))",
- " (row (?a 1) (?c 9))",
- ")") ;
- }
-
- static Table tableD3() {
- return parseTableInt("(table",
- " (row (?a 1) (?c 9) (?b 2))",
- " (row (?a 1) (?c 9) (?b 3))",
- " (row (?a 1) (?c 9) (?b 2))",
- ")") ;
- }
-
- static Table tableD4() {
- return parseTableInt("(table",
- " (row (?a 1) (?b 2))",
- " (row (?a 1) (?b 3))",
- " (row (?a 4) (?b 4))",
- " (row (?a 4) (?b 5))",
- ")") ;
- }
-
- static Table tableD5() {
- return parseTableInt("(table",
- " (row (?a 4) (?c 4))",
- " (row (?a 4) (?c 5))",
- " (row (?a 6) (?c 5))",
- ")") ;
- }
-
- static Table tableD6() {
- return parseTableInt("(table",
- " (row (?a 1) (?c 2))",
- " (row (?a 1) (?c 3))",
- " (row (?a 4) (?c 4))",
- " (row (?a 4) (?c 5))",
- ")") ;
- }
-
- static Table tableD4x5() {
- return parseTableInt("(table",
- " (row (?a 4) (?c 4) (?b 4))",
- " (row (?a 4) (?c 4) (?b 5))",
- " (row (?a 4) (?c 5) (?b 4))",
- " (row (?a 4) (?c 5) (?b 5))",
- ")") ;
- }
-
- static Table tableD4x6() {
- return parseTableInt("(table",
- " (row (?a 1) (?c 2) (?b 2))",
- " (row (?a 1) (?c 2) (?b 3))",
- " (row (?a 1) (?c 3) (?b 2))",
- " (row (?a 1) (?c 3) (?b 3))",
- " (row (?a 4) (?c 4) (?b 4))",
- " (row (?a 4) (?c 4) (?b 5))",
- " (row (?a 4) (?c 5) (?b 4))",
- " (row (?a 4) (?c 5) (?b 5))",
- ")") ;
- }
-
- // Disjoint.
- static Table tableD8() {
- return parseTableInt("(table",
- " (row (?x 10))",
- " (row (?z 11))",
- ")") ;
- }
-
- // Table8 crossproduct table2
- static Table tableD8x2() {
- return parseTableInt("(table",
- " (row (?a 0) (?d 8) (?z 11))",
- " (row (?a 0) (?d 8) (?x 10))",
- " (row (?a 1) (?c 9) (?z 11))",
- " (row (?a 1) (?c 9) (?x 10))",
- ")") ;
+ @Override
+ protected void executeTest(JoinKey joinKey, Table left, Table right, ExprList conditions, Table expectedResults) {
+ executeTestJoin("LJ", joinKey, left, right, conditions, expectedResults) ;
}
// XXX And conditions.
- @Test public void leftjoin_00() { testJoin("a", table0(), table0(), table0()) ; }
- @Test public void leftjoin_00a() { testJoin("a", table1(), table0(), table0()) ; }
- @Test public void leftjoin_00b() { testJoin("a", tableD1(), table1(), tableD1()) ; }
- @Test public void leftjoin_00c() { testJoin("z", tableD1(), table1(), tableD1()) ; }
+ @Test public void leftjoin_basic_1() { testJoin("a", table0(), table0(), table0()) ; }
+ @Test public void leftjoin_basic_2() { testJoin("a", table1(), table0(), table1()) ; }
+ @Test public void leftjoin_basic_3() { testJoin("a", tableD1(), table1(), tableD1()) ; }
+ @Test public void leftjoin_basic_4() { testJoin("z", tableD1(), table1(), tableD1()) ; }
+
+ @Test public void leftjoin_01() { testJoin("a", tableL1(), tableL2(), table1LJ2()) ; }
+ @Test public void leftjoin_02() { testJoin("a", tableL4(), tableL5(), table4LJ5()) ; }
+
+ @Test public void leftjoin_03() { testJoin("z", tableL1(), tableL2(), table1LJ2()) ; }
+ @Test public void leftjoin_04() { testJoin("z", tableL4(), tableL5(), table4LJ5()) ; }
+
+ @Test public void leftjoin_J01() { testJoin("a", tableD1(), table1(), tableD1()) ; }
+ @Test public void leftjoin_J01a() { testJoin("z", tableD1(), table1(), tableD1()) ; }
- @Test public void leftjoin_01() { testJoin("a", table0(), tableD2(), table0()) ; }
- @Test public void leftjoin_02() { testJoin("a", tableD1(), table0(), tableD1()) ; }
- @Test public void leftjoin_03() { testJoin("a", tableD1(), tableD2(), tableD3()) ; }
+ @Test public void leftjoin_J02() { testJoin("a", tableD1(), table0(), tableD1()) ; }
+ @Test public void leftjoin_J03() { testJoin("a", tableD1(), tableD2(), tableD3()) ; }
// Identity.
- @Test public void leftjoin_04() { testJoin("a", tableD2(), table1(), tableD2()) ; }
- @Test public void leftjoin_05() { testJoin("a", table1(), tableD2(), tableD2()) ; }
+ @Test public void leftjoin_J04() { testJoin("a", tableD2(), table1(), tableD2()) ; }
+ @Test public void leftjoin_J05() { testJoin("a", table1(), tableD2(), tableD2()) ; }
// Identity, keymiss
- @Test public void leftjoin_06() { testJoin("z", table1(), tableD2(), tableD2()) ; }
- @Test public void leftjoin_07() { testJoin("z", tableD2(), table1(), tableD2()) ; }
+ @Test public void leftjoin_J06() { testJoin("z", table1(), tableD2(), tableD2()) ; }
+ @Test public void leftjoin_J07() { testJoin("z", tableD2(), table1(), tableD2()) ; }
- @Test public void leftjoin_08() { testJoin("a", tableD4(), tableD5(), tableD4x5()) ; }
- @Test public void leftjoin_09() { testJoin("a", tableD5(), tableD4(), tableD4x5()) ; }
+ @Test public void leftjoin_J08() { testJoin("a", tableD4(), tableD5(), tableD4x5_LJ()) ; }
+ @Test public void leftjoin_J09() { testJoin("a", tableD5(), tableD4(), tableD5x4_LJ()) ; }
- @Test public void leftjoin_10() { testJoin("a", tableD4(), tableD6(), tableD4x6()) ; }
- @Test public void leftjoin_11() { testJoin("a", tableD6(), tableD4(), tableD4x6()) ; }
+ @Test public void leftjoin_J10() { testJoin("a", tableD4(), tableD6(), tableD4x6()) ; }
+ @Test public void leftjoin_J11() { testJoin("a", tableD6(), tableD4(), tableD4x6()) ; }
// Not the right join key - should still work albeit less efficiently.
- @Test public void leftjoin_12() { testJoin("z", tableD1(), tableD2(), tableD3()) ; }
- @Test public void leftjoin_13() { testJoin("z", tableD2(), tableD1(), tableD3()) ; }
+ @Test public void leftjoin_J12() { testJoin("z", tableD1(), tableD2(), tableD3()) ; }
+ @Test public void leftjoin_J13() { testJoin("z", tableD2(), tableD1(), tableD3_LJ()) ; }
// No key.
- @Test public void leftjoin_14() { testJoin(null, tableD1(), tableD2(), tableD3()) ; }
+
+ @Test public void leftjoin_14() { testJoin(null, tableD1(), tableD2(), tableD3()) ; }
// Disjoint tables.
http://git-wip-us.apache.org/repos/asf/jena/blob/b2ece9ad/jena-arq/src/test/java/org/apache/jena/sparql/engine/join/TS_Join.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/test/java/org/apache/jena/sparql/engine/join/TS_Join.java b/jena-arq/src/test/java/org/apache/jena/sparql/engine/join/TS_Join.java
index 69b5fb4..bd00872 100644
--- a/jena-arq/src/test/java/org/apache/jena/sparql/engine/join/TS_Join.java
+++ b/jena-arq/src/test/java/org/apache/jena/sparql/engine/join/TS_Join.java
@@ -28,6 +28,11 @@ import org.junit.runners.Suite.SuiteClasses ;
, TestJoinNestedLoopSimple.class // Real simple materializing version.
, TestJoinNestedLoop.class
, TestHashJoin.class
+
+ , TestLeftJoinSimple.class
+ , TestLeftJoinNestedLoopSimple.class // Real simple materializing version.
+ , TestLeftJoinNestedLoop.class
+ //, TestLeftHashJoin.class
})
public class TS_Join { }
http://git-wip-us.apache.org/repos/asf/jena/blob/b2ece9ad/jena-arq/src/test/java/org/apache/jena/sparql/engine/join/TestHashJoin.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/test/java/org/apache/jena/sparql/engine/join/TestHashJoin.java b/jena-arq/src/test/java/org/apache/jena/sparql/engine/join/TestHashJoin.java
index 4a4bd6f..6aa9eaa 100644
--- a/jena-arq/src/test/java/org/apache/jena/sparql/engine/join/TestHashJoin.java
+++ b/jena-arq/src/test/java/org/apache/jena/sparql/engine/join/TestHashJoin.java
@@ -26,11 +26,12 @@ import org.apache.jena.sparql.engine.binding.Binding ;
import org.apache.jena.sparql.engine.iterator.QueryIterPlainWrapper ;
import org.apache.jena.sparql.engine.join.Join ;
import org.apache.jena.sparql.engine.join.JoinKey ;
+import org.apache.jena.sparql.expr.ExprList ;
public class TestHashJoin extends AbstractTestInnerJoin {
@Override
- public QueryIterator join(JoinKey joinKey, Table left, Table right) {
+ public QueryIterator join(JoinKey joinKey, Table left, Table right, ExprList conditions) {
Iterator<Binding> data = Join.hashJoin(joinKey, left.iterator(null), right.iterator(null), null) ;
QueryIterator qIter = new QueryIterPlainWrapper(data) ;
return qIter ;
http://git-wip-us.apache.org/repos/asf/jena/blob/b2ece9ad/jena-arq/src/test/java/org/apache/jena/sparql/engine/join/TestJoinNestedLoop.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/test/java/org/apache/jena/sparql/engine/join/TestJoinNestedLoop.java b/jena-arq/src/test/java/org/apache/jena/sparql/engine/join/TestJoinNestedLoop.java
index c844ea2..31530a4 100644
--- a/jena-arq/src/test/java/org/apache/jena/sparql/engine/join/TestJoinNestedLoop.java
+++ b/jena-arq/src/test/java/org/apache/jena/sparql/engine/join/TestJoinNestedLoop.java
@@ -22,12 +22,13 @@ import org.apache.jena.sparql.algebra.Table ;
import org.apache.jena.sparql.engine.QueryIterator ;
import org.apache.jena.sparql.engine.join.Join ;
import org.apache.jena.sparql.engine.join.JoinKey ;
+import org.apache.jena.sparql.expr.ExprList ;
public class TestJoinNestedLoop extends AbstractTestInnerJoin {
@Override
- public QueryIterator join(JoinKey joinKey, Table left, Table right) {
- return Join.innerLoopJoin(left.iterator(null), right.iterator(null), null) ;
+ public QueryIterator join(JoinKey joinKey, Table left, Table right, ExprList conditions) {
+ return Join.nestedLoopJoin(left.iterator(null), right.iterator(null), null) ;
}
}
http://git-wip-us.apache.org/repos/asf/jena/blob/b2ece9ad/jena-arq/src/test/java/org/apache/jena/sparql/engine/join/TestJoinNestedLoopSimple.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/test/java/org/apache/jena/sparql/engine/join/TestJoinNestedLoopSimple.java b/jena-arq/src/test/java/org/apache/jena/sparql/engine/join/TestJoinNestedLoopSimple.java
index 0d9db54..64206cb 100644
--- a/jena-arq/src/test/java/org/apache/jena/sparql/engine/join/TestJoinNestedLoopSimple.java
+++ b/jena-arq/src/test/java/org/apache/jena/sparql/engine/join/TestJoinNestedLoopSimple.java
@@ -22,12 +22,13 @@ import org.apache.jena.sparql.algebra.Table ;
import org.apache.jena.sparql.engine.QueryIterator ;
import org.apache.jena.sparql.engine.join.Join ;
import org.apache.jena.sparql.engine.join.JoinKey ;
+import org.apache.jena.sparql.expr.ExprList ;
public class TestJoinNestedLoopSimple extends AbstractTestInnerJoin {
@Override
- public QueryIterator join(JoinKey joinKey, Table left, Table right) {
- return Join.innerLoopJoinBasic(left.iterator(null), right.iterator(null), null) ;
+ public QueryIterator join(JoinKey joinKey, Table left, Table right, ExprList conditions) {
+ return Join.nestedLoopJoinBasic(left.iterator(null), right.iterator(null), null) ;
}
}
http://git-wip-us.apache.org/repos/asf/jena/blob/b2ece9ad/jena-arq/src/test/java/org/apache/jena/sparql/engine/join/TestJoinSimple.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/test/java/org/apache/jena/sparql/engine/join/TestJoinSimple.java b/jena-arq/src/test/java/org/apache/jena/sparql/engine/join/TestJoinSimple.java
index d091168..f89fa87 100644
--- a/jena-arq/src/test/java/org/apache/jena/sparql/engine/join/TestJoinSimple.java
+++ b/jena-arq/src/test/java/org/apache/jena/sparql/engine/join/TestJoinSimple.java
@@ -22,11 +22,12 @@ import org.apache.jena.sparql.algebra.Table ;
import org.apache.jena.sparql.engine.QueryIterator ;
import org.apache.jena.sparql.engine.join.JoinKey ;
import org.apache.jena.sparql.engine.ref.TableJoin ;
+import org.apache.jena.sparql.expr.ExprList ;
public class TestJoinSimple extends AbstractTestInnerJoin {
@Override
- public QueryIterator join(JoinKey joinKey, Table left, Table right) {
+ public QueryIterator join(JoinKey joinKey, Table left, Table right, ExprList conditions) {
return TableJoin.join(left.iterator(null), right, null, null) ;
}
http://git-wip-us.apache.org/repos/asf/jena/blob/b2ece9ad/jena-arq/src/test/java/org/apache/jena/sparql/engine/join/TestLeftJoinNestedLoop.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/test/java/org/apache/jena/sparql/engine/join/TestLeftJoinNestedLoop.java b/jena-arq/src/test/java/org/apache/jena/sparql/engine/join/TestLeftJoinNestedLoop.java
new file mode 100644
index 0000000..a5053a7
--- /dev/null
+++ b/jena-arq/src/test/java/org/apache/jena/sparql/engine/join/TestLeftJoinNestedLoop.java
@@ -0,0 +1,35 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.jena.sparql.engine.join;
+
+import org.apache.jena.sparql.algebra.Table ;
+import org.apache.jena.sparql.engine.QueryIterator ;
+import org.apache.jena.sparql.engine.join.Join ;
+import org.apache.jena.sparql.engine.join.JoinKey ;
+import org.apache.jena.sparql.expr.ExprList ;
+
+public class TestLeftJoinNestedLoop extends AbstractTestLeftJoin {
+
+ @Override
+ public QueryIterator join(JoinKey joinKey, Table left, Table right, ExprList conditions) {
+ return Join.nestedLoopLeftJoin(left.iterator(null), right.iterator(null), conditions, null) ;
+ }
+
+}
+
http://git-wip-us.apache.org/repos/asf/jena/blob/b2ece9ad/jena-arq/src/test/java/org/apache/jena/sparql/engine/join/TestLeftJoinNestedLoopSimple.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/test/java/org/apache/jena/sparql/engine/join/TestLeftJoinNestedLoopSimple.java b/jena-arq/src/test/java/org/apache/jena/sparql/engine/join/TestLeftJoinNestedLoopSimple.java
new file mode 100644
index 0000000..44d2d7d
--- /dev/null
+++ b/jena-arq/src/test/java/org/apache/jena/sparql/engine/join/TestLeftJoinNestedLoopSimple.java
@@ -0,0 +1,35 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.jena.sparql.engine.join;
+
+import org.apache.jena.sparql.algebra.Table ;
+import org.apache.jena.sparql.engine.QueryIterator ;
+import org.apache.jena.sparql.engine.join.Join ;
+import org.apache.jena.sparql.engine.join.JoinKey ;
+import org.apache.jena.sparql.expr.ExprList ;
+
+public class TestLeftJoinNestedLoopSimple extends AbstractTestLeftJoin {
+
+ @Override
+ public QueryIterator join(JoinKey joinKey, Table left, Table right, ExprList conditions) {
+ return Join.nestedLoopLeftJoinBasic(left.iterator(null), right.iterator(null), conditions,null) ;
+ }
+
+}
+
http://git-wip-us.apache.org/repos/asf/jena/blob/b2ece9ad/jena-arq/src/test/java/org/apache/jena/sparql/engine/join/TestLeftJoinSimple.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/test/java/org/apache/jena/sparql/engine/join/TestLeftJoinSimple.java b/jena-arq/src/test/java/org/apache/jena/sparql/engine/join/TestLeftJoinSimple.java
index 041dfe5..f9fc763 100644
--- a/jena-arq/src/test/java/org/apache/jena/sparql/engine/join/TestLeftJoinSimple.java
+++ b/jena-arq/src/test/java/org/apache/jena/sparql/engine/join/TestLeftJoinSimple.java
@@ -22,13 +22,13 @@ import org.apache.jena.sparql.algebra.Table ;
import org.apache.jena.sparql.engine.QueryIterator ;
import org.apache.jena.sparql.engine.join.JoinKey ;
import org.apache.jena.sparql.engine.ref.TableJoin ;
+import org.apache.jena.sparql.expr.ExprList ;
public class TestLeftJoinSimple extends AbstractTestLeftJoin {
@Override
- public QueryIterator join(JoinKey joinKey, Table left, Table right) {
- return TableJoin.leftJoin(left.iterator(null), right, null, null) ;
+ public QueryIterator join(JoinKey joinKey, Table left, Table right, ExprList conditions) {
+ return TableJoin.leftJoin(left.iterator(null), right, conditions, null) ;
}
-
}
[02/20] jena git commit: Rename to make clearer
Posted by an...@apache.org.
Rename to make clearer
Project: http://git-wip-us.apache.org/repos/asf/jena/repo
Commit: http://git-wip-us.apache.org/repos/asf/jena/commit/804f2be8
Tree: http://git-wip-us.apache.org/repos/asf/jena/tree/804f2be8
Diff: http://git-wip-us.apache.org/repos/asf/jena/diff/804f2be8
Branch: refs/heads/master
Commit: 804f2be8038f19d56e958247fa1c2edaf57123ea
Parents: c7dafa2
Author: Andy Seaborne <an...@apache.org>
Authored: Tue Sep 8 10:22:29 2015 +0100
Committer: Andy Seaborne <an...@apache.org>
Committed: Tue Sep 8 10:22:29 2015 +0100
----------------------------------------------------------------------
.../jena/sparql/engine/ref/TestTableJoin.java | 120 +++++++++++++++++++
1 file changed, 120 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/jena/blob/804f2be8/jena-arq/src/test/java/org/apache/jena/sparql/engine/ref/TestTableJoin.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/test/java/org/apache/jena/sparql/engine/ref/TestTableJoin.java b/jena-arq/src/test/java/org/apache/jena/sparql/engine/ref/TestTableJoin.java
new file mode 100644
index 0000000..b52d532
--- /dev/null
+++ b/jena-arq/src/test/java/org/apache/jena/sparql/engine/ref/TestTableJoin.java
@@ -0,0 +1,120 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.jena.sparql.engine.ref;
+
+import java.util.HashSet ;
+import java.util.Set ;
+
+import org.apache.jena.atlas.junit.BaseTest ;
+import org.apache.jena.query.ARQ ;
+import org.apache.jena.query.ResultSet ;
+import org.apache.jena.query.ResultSetFactory ;
+import org.apache.jena.sparql.algebra.Table ;
+import org.apache.jena.sparql.algebra.table.TableEmpty ;
+import org.apache.jena.sparql.algebra.table.TableN ;
+import org.apache.jena.sparql.algebra.table.TableUnit ;
+import org.apache.jena.sparql.engine.ExecutionContext ;
+import org.apache.jena.sparql.engine.QueryIterator ;
+import org.apache.jena.sparql.engine.ref.TableJoin ;
+import org.apache.jena.sparql.expr.ExprList ;
+import org.apache.jena.sparql.resultset.ResultSetCompare ;
+import org.apache.jena.sparql.sse.SSE ;
+import org.junit.Test ;
+
+/** Tests on tables and the simple nest loop join (TableJoin) used by the reference query engine */
+public class TestTableJoin extends BaseTest
+{
+ Table unit = new TableUnit() ;
+ Table zero = new TableEmpty() ;
+ Table zeroData = SSE.parseTable("(table)") ;
+ Table unitData = SSE.parseTable("(table (row))") ;
+ Table data1 = SSE.parseTable("(table (row (?a 1) (?b 2)))") ;
+ Table data2 = SSE.parseTable("(table (row (?a 1) (?c 3)) (row (?a 9) (?c 5)) )") ;
+ Table data3 = SSE.parseTable("(table (row (?a 1) (?c 3)) (row (?a 1) (?c 4)) (row (?a 9) (?c 5)) )") ;
+
+ Table data1J2 = SSE.parseTable("(table (row (?a 1) (?b 2) (?c 3)) )") ;
+ Table data1LJ2 = SSE.parseTable("(table (row (?a 1) (?b 2) (?c 3)) (row (?a 9) (?c 5)) )") ;
+ Table data2LJ1 = SSE.parseTable("(table (row (?a 1) (?b 2) (?c 3)) )") ;
+
+ Table data1J3 = SSE.parseTable("(table (row (?a 1) (?b 2) (?c 3)) (row (?a 1) (?b 2) (?c 4)) )") ;
+
+ @Test public void table_01() { test(unit, zero, true, null, zero) ; }
+ @Test public void table_02() { test(zero, unit, true, null, zero) ; }
+ @Test public void table_03() { test(unit, zero, false, null, unit) ; }
+ @Test public void table_04() { test(zero, unit, false, null, zero) ; }
+ // Same again but with non-special tables.
+ @Test public void table_05() { test(unitData, zeroData, true, null, zeroData) ; }
+ @Test public void table_06() { test(zeroData, unitData, true, null, zeroData) ; }
+ @Test public void table_07() { test(unitData, zeroData, false, null, unitData) ; }
+ @Test public void table_08() { test(zeroData, unitData, false, null, zeroData) ; }
+
+ @Test public void table_10() { test(data1, zero, true, null, zero) ; }
+ @Test public void table_11() { test(zero, data1, true, null, zero) ; }
+ @Test public void table_12() { test(data1, zero, false, null, data1) ; }
+ @Test public void table_13() { test(zero, data1, false, null, zero) ; }
+
+ @Test public void table_14() { test(data1, zeroData, true, null, zeroData) ; }
+ @Test public void table_15() { test(zeroData, data1, true, null, zeroData) ; }
+ @Test public void table_16() { test(data1, zeroData, false, null, data1) ; }
+ @Test public void table_17() { test(zeroData, data1, false, null, zeroData) ; }
+
+ @Test public void table_18() { test(data2, unitData, true, null, data2) ; }
+ @Test public void table_19() { test(unitData, data2, true, null, data2) ; }
+
+ @Test public void table_20() { test(data1, data2, true, null, data1J2) ; }
+ @Test public void table_21() { test(data2, data1, true, null, data1J2) ; }
+ @Test public void table_22() { test(data1, data2, false, null, data1LJ2) ; }
+ @Test public void table_23() { test(data2, data1, false, null, data2LJ1) ; }
+
+ @Test public void table_24() { test(data1, data3, true, null, data1J3) ; }
+ @Test public void table_25() { test(data3, data1, true, null, data1J3) ; }
+
+ private void test(Table left, Table right, boolean normalJoin, ExprList exprs, Table expected) {
+ ExecutionContext execCxt = new ExecutionContext(ARQ.getContext(), null, null, null) ;
+ QueryIterator leftIter = left.iterator(execCxt) ;
+ QueryIterator qIter = normalJoin
+ ? TableJoin.join(leftIter, right, exprs, execCxt)
+ : TableJoin.leftJoin(leftIter, right, exprs, execCxt) ;
+
+ // Order issues
+
+ Set<String> vars1 = new HashSet<>() ;
+ vars1.addAll(left.getVarNames()) ;
+ vars1.addAll(right.getVarNames()) ;
+
+ TableN results = new TableN(qIter) ;
+ boolean b = TableCompare.equalsByTerm(expected, results) ;
+ if ( !b ) {
+ System.out.println("** Expected") ;
+ System.out.println(expected) ;
+ System.out.println("** Actual") ;
+ System.out.println(results) ;
+ }
+ assertTrue(b) ;
+ }
+
+ static class TableCompare {
+ public static boolean equalsByTerm(Table table1, Table table2) {
+ ResultSet rs1 = ResultSetFactory.create(table1.iterator(null), table1.getVarNames()) ;
+ ResultSet rs2 = ResultSetFactory.create(table2.iterator(null), table2.getVarNames()) ;
+ return ResultSetCompare.equalsByTerm(rs1, rs2) ;
+ }
+ }
+
+}
[05/20] jena git commit: Fix test data
Posted by an...@apache.org.
Fix test data
Project: http://git-wip-us.apache.org/repos/asf/jena/repo
Commit: http://git-wip-us.apache.org/repos/asf/jena/commit/8a4a285d
Tree: http://git-wip-us.apache.org/repos/asf/jena/tree/8a4a285d
Diff: http://git-wip-us.apache.org/repos/asf/jena/diff/8a4a285d
Branch: refs/heads/master
Commit: 8a4a285d62642cbdba787464c9e2a64e808eda60
Parents: 985c132
Author: Andy Seaborne <an...@apache.org>
Authored: Tue Sep 8 11:46:19 2015 +0100
Committer: Andy Seaborne <an...@apache.org>
Committed: Tue Sep 8 11:46:19 2015 +0100
----------------------------------------------------------------------
.../java/org/apache/jena/sparql/engine/ref/TestTableJoin.java | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/jena/blob/8a4a285d/jena-arq/src/test/java/org/apache/jena/sparql/engine/ref/TestTableJoin.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/test/java/org/apache/jena/sparql/engine/ref/TestTableJoin.java b/jena-arq/src/test/java/org/apache/jena/sparql/engine/ref/TestTableJoin.java
index b52d532..1a2fbde 100644
--- a/jena-arq/src/test/java/org/apache/jena/sparql/engine/ref/TestTableJoin.java
+++ b/jena-arq/src/test/java/org/apache/jena/sparql/engine/ref/TestTableJoin.java
@@ -44,13 +44,14 @@ public class TestTableJoin extends BaseTest
Table zero = new TableEmpty() ;
Table zeroData = SSE.parseTable("(table)") ;
Table unitData = SSE.parseTable("(table (row))") ;
+
Table data1 = SSE.parseTable("(table (row (?a 1) (?b 2)))") ;
Table data2 = SSE.parseTable("(table (row (?a 1) (?c 3)) (row (?a 9) (?c 5)) )") ;
Table data3 = SSE.parseTable("(table (row (?a 1) (?c 3)) (row (?a 1) (?c 4)) (row (?a 9) (?c 5)) )") ;
-
+
Table data1J2 = SSE.parseTable("(table (row (?a 1) (?b 2) (?c 3)) )") ;
- Table data1LJ2 = SSE.parseTable("(table (row (?a 1) (?b 2) (?c 3)) (row (?a 9) (?c 5)) )") ;
- Table data2LJ1 = SSE.parseTable("(table (row (?a 1) (?b 2) (?c 3)) )") ;
+ Table data1LJ2 = SSE.parseTable("(table (row (?a 1) (?b 2) (?c 3)) )") ;
+ Table data2LJ1 = SSE.parseTable("(table (row (?a 1) (?b 2) (?c 3)) (row (?a 9) (?c 5)) )") ;
Table data1J3 = SSE.parseTable("(table (row (?a 1) (?b 2) (?c 3)) (row (?a 1) (?b 2) (?c 4)) )") ;
[06/20] jena git commit: Rename PLAIN as INNER.
Posted by an...@apache.org.
Rename PLAIN as INNER.
Project: http://git-wip-us.apache.org/repos/asf/jena/repo
Commit: http://git-wip-us.apache.org/repos/asf/jena/commit/c6288c34
Tree: http://git-wip-us.apache.org/repos/asf/jena/tree/c6288c34
Diff: http://git-wip-us.apache.org/repos/asf/jena/diff/c6288c34
Branch: refs/heads/master
Commit: c6288c341df813e461af5465faa8304e90a3b267
Parents: 8a4a285
Author: Andy Seaborne <an...@apache.org>
Authored: Tue Sep 8 14:17:24 2015 +0100
Committer: Andy Seaborne <an...@apache.org>
Committed: Tue Sep 8 14:17:24 2015 +0100
----------------------------------------------------------------------
.../main/java/org/apache/jena/sparql/algebra/JoinType.java | 9 ++++++++-
.../org/apache/jena/sparql/engine/ref/EvaluatorSimple.java | 2 +-
2 files changed, 9 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/jena/blob/c6288c34/jena-arq/src/main/java/org/apache/jena/sparql/algebra/JoinType.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/main/java/org/apache/jena/sparql/algebra/JoinType.java b/jena-arq/src/main/java/org/apache/jena/sparql/algebra/JoinType.java
index 0dc0b5b..e0bd489 100644
--- a/jena-arq/src/main/java/org/apache/jena/sparql/algebra/JoinType.java
+++ b/jena-arq/src/main/java/org/apache/jena/sparql/algebra/JoinType.java
@@ -18,4 +18,11 @@
package org.apache.jena.sparql.algebra;
-public enum JoinType { PLAIN, LEFT /*, RIGHT , /*FULL* /OUTER*/}
+public enum JoinType {
+ INNER /* Normal, plain equijoin*/
+ , LEFT
+ //, RIGHT
+ //, OUTER // Full outer join
+ //, ANTI // Anti-join: rows in LHS where there is no matching tuple in RHS
+ //, SEMI // All tuples in LHS where there is a matching tuple in RHS
+}
http://git-wip-us.apache.org/repos/asf/jena/blob/c6288c34/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 0f22aed..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
@@ -270,7 +270,7 @@ public class EvaluatorSimple implements Evaluator
private Table joinWorker(Table tableLeft, Table tableRight, boolean leftJoin, ExprList conditions)
{
QueryIterator left = tableLeft.iterator(execCxt) ;
- JoinType joinType = (leftJoin? JoinType.LEFT : JoinType.PLAIN ) ;
+ JoinType joinType = (leftJoin? JoinType.LEFT : JoinType.INNER ) ;
QueryIterator qIter = TableJoin.joinWorker(left, tableRight, joinType, conditions, execCxt) ;
tableLeft.close() ;
tableRight.close() ;