[Mulgara-svn] r1299 - trunk/src/jar/tuples/java/org/mulgara/store/tuples
alexhall at mulgara.org
alexhall at mulgara.org
Thu Oct 9 19:43:24 UTC 2008
Author: alexhall
Date: 2008-10-09 12:43:22 -0700 (Thu, 09 Oct 2008)
New Revision: 1299
Modified:
trunk/src/jar/tuples/java/org/mulgara/store/tuples/Tuples.java
trunk/src/jar/tuples/java/org/mulgara/store/tuples/TuplesOperations.java
trunk/src/jar/tuples/java/org/mulgara/store/tuples/TuplesOperationsUnitTest.java
Log:
Fixed an error that was occurring in the re-sort of the optional part in an optional join. The javadoc for Tuples.getColumnIndex(Variable) incorrectly stated that the method returns Tuples.UNBOUND if the variable is not in the Tuples, when it will really throw a TuplesException (Tuples.UNBOUND = 0, which is a valid return value).
The TuplesOperations.reSort() method was checking the return value from getColumnIndex against Tuples.UNBOUND and throwing an exception, which is incorrect behavior and rejects certain valid arguments. I removed the offending line, and corrected the Tuples javadoc.
Modified: trunk/src/jar/tuples/java/org/mulgara/store/tuples/Tuples.java
===================================================================
--- trunk/src/jar/tuples/java/org/mulgara/store/tuples/Tuples.java 2008-10-08 22:40:03 UTC (rev 1298)
+++ trunk/src/jar/tuples/java/org/mulgara/store/tuples/Tuples.java 2008-10-09 19:43:22 UTC (rev 1299)
@@ -109,15 +109,11 @@
public long getRowCount() throws TuplesException;
/**
- * Accessor for the binding of a given variable within the current product
- * term (row).
+ * Accessor for the column index of a given variable in this Tuple.
*
- * @param variable the variable binding to query
- * @return the bound value, or {@link Tuples#UNBOUND} if there is no binding
- * within the current product term (row)
- * @throws TuplesException if there is no current row (before first or after
- * last) or if <var>variable</var> isn't an element of {@link
- * #getVariables}
+ * @param variable The column variable to query
+ * @return The index of the named column. Columns are indexed starting at 0.
+ * @throws TuplesException if <var>variable</var> isn't an element of {@link #getVariables()}
*/
public int getColumnIndex(Variable variable) throws TuplesException;
Modified: trunk/src/jar/tuples/java/org/mulgara/store/tuples/TuplesOperations.java
===================================================================
--- trunk/src/jar/tuples/java/org/mulgara/store/tuples/TuplesOperations.java 2008-10-08 22:40:03 UTC (rev 1298)
+++ trunk/src/jar/tuples/java/org/mulgara/store/tuples/TuplesOperations.java 2008-10-09 19:43:22 UTC (rev 1299)
@@ -387,7 +387,9 @@
}
// yes, there are extra variables
- logger.debug("sorting on the common variables");
+ if (logger.isDebugEnabled()) {
+ logger.debug("sorting on the common variables: " + matchingVars);
+ }
// re-sort the optional according to the matching variables
// reorder the optional as necessary
Tuples sortedOptional = reSort(optional, new ArrayList<Variable>(matchingVars));
@@ -913,7 +915,6 @@
Variable var = variableList.get(varCol);
// get the index of the variable in the tuples
int ti = tuples.getColumnIndex(var);
- if (ti == Tuples.UNBOUND) throw new IllegalArgumentException("Variables to sort by not found in Tuples");
// check that it is within the prefix columns. If not, then sorting is needed
if (ti >= varMap.length) sortNeeded = true;
// map the tuples index of the variable to the column index
Modified: trunk/src/jar/tuples/java/org/mulgara/store/tuples/TuplesOperationsUnitTest.java
===================================================================
--- trunk/src/jar/tuples/java/org/mulgara/store/tuples/TuplesOperationsUnitTest.java 2008-10-08 22:40:03 UTC (rev 1298)
+++ trunk/src/jar/tuples/java/org/mulgara/store/tuples/TuplesOperationsUnitTest.java 2008-10-09 19:43:22 UTC (rev 1299)
@@ -28,13 +28,14 @@
package org.mulgara.store.tuples;
// JUnit
-import junit.framework.*; // JUnit
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
-// Log4J
import org.apache.log4j.Logger;
-
-// Mulgara
import org.mulgara.query.Variable;
+import static org.mulgara.query.filter.value.Bool.TRUE;
+import static org.mulgara.store.tuples.Tuples.UNBOUND;
/**
* Test case for {@link TuplesOperationsUnitTest}.
@@ -82,6 +83,7 @@
TestSuite suite = new TestSuite();
suite.addTest(new TuplesOperationsUnitTest("testReorderedAppend"));
+ suite.addTest(new TuplesOperationsUnitTest("testOptionalJoin"));
return suite;
}
@@ -143,4 +145,35 @@
TuplesTestingUtil.closeTuples(new Tuples[] { join });
}
+
+ public void testOptionalJoin() throws Exception {
+
+ LiteralTuples standard = new LiteralTuples(new String[] {"x", "y"}, true);
+ LiteralTuples optional = new LiteralTuples(new String[] {"y", "z"}, true);
+
+ standard.appendTuple(new long[] { 1, 2 });
+ standard.appendTuple(new long[] { 1, 3 });
+ standard.appendTuple(new long[] { 2, 3 });
+ standard.appendTuple(new long[] { 4, 1 });
+ standard.appendTuple(new long[] { 4, 5 });
+
+ optional.appendTuple(new long[] { 1, 6 });
+ optional.appendTuple(new long[] { 1, 7 });
+ optional.appendTuple(new long[] { 3, 8 });
+
+ Tuples optionalJoin = TuplesOperations.optionalJoin(standard, optional, TRUE, null);
+
+ optionalJoin.beforeFirst();
+
+ TuplesTestingUtil.testTuplesRow(optionalJoin, new long[] { 1, 2, UNBOUND });
+ TuplesTestingUtil.testTuplesRow(optionalJoin, new long[] { 1, 3, 8 });
+ TuplesTestingUtil.testTuplesRow(optionalJoin, new long[] { 2, 3, 8 });
+ TuplesTestingUtil.testTuplesRow(optionalJoin, new long[] { 4, 1, 6 });
+ TuplesTestingUtil.testTuplesRow(optionalJoin, new long[] { 4, 1, 7 });
+ TuplesTestingUtil.testTuplesRow(optionalJoin, new long[] { 4, 5, UNBOUND });
+
+ assertFalse(optionalJoin.next());
+
+ TuplesTestingUtil.closeTuples(new Tuples[] { optionalJoin });
+ }
}
More information about the Mulgara-svn
mailing list