[Mulgara-svn] r854 - branches/mgr-61-sparql/src/jar/tuples/java/org/mulgara/store/tuples
pag at mulgara.org
pag at mulgara.org
Fri Apr 25 04:16:49 UTC 2008
Author: pag
Date: 2008-04-24 21:16:48 -0700 (Thu, 24 Apr 2008)
New Revision: 854
Modified:
branches/mgr-61-sparql/src/jar/tuples/java/org/mulgara/store/tuples/TuplesOperations.java
Log:
Reworked the reSort method to use standard operations, abandoning the PartialColumnComparator. Added a new optionalJoin operation to recursively handle lists of operators.
Modified: branches/mgr-61-sparql/src/jar/tuples/java/org/mulgara/store/tuples/TuplesOperations.java
===================================================================
--- branches/mgr-61-sparql/src/jar/tuples/java/org/mulgara/store/tuples/TuplesOperations.java 2008-04-25 04:14:34 UTC (rev 853)
+++ branches/mgr-61-sparql/src/jar/tuples/java/org/mulgara/store/tuples/TuplesOperations.java 2008-04-25 04:16:48 UTC (rev 854)
@@ -335,11 +335,28 @@
logger.warn("RuntimeException thrown in subtraction", re);
throw re;
} catch (TuplesException te) {
- logger.warn("TuplesException thrown in substraction", te);
+ logger.warn("TuplesException thrown in subtraction", te);
throw te;
}
}
+ /**
+ * Does a left-associative optionalJoin along a list of arguments.
+ * @param args The arguments to operate on.
+ * @return A tuples containing all of the entries from args.get(0) and matching
+ * entries from the remainder of the list. All variables from the entire list
+ * will be present in the result.
+ * @throws TuplesException On error accessing elements in any argument.
+ */
+ public static Tuples optionalJoin(LinkedList<Tuples> args) throws TuplesException {
+ // check for termination. The first couple are for <NIL> syntax elements in the query
+ if (args.size() == 0) return empty();
+ if (args.size() == 1) return args.get(0);
+ if (args.size() == 2) return optionalJoin(args.get(0), args.get(1));
+ // join the head of the list, and then iterate
+ args.addFirst(optionalJoin(args.removeFirst(), args.removeFirst()));
+ return optionalJoin(args);
+ }
/**
* Does a left-outer-join between two tuples. Parameters are not closed during this
@@ -914,17 +931,32 @@
varMap[varCol++] = ti;
}
- if (logger.isDebugEnabled()) logger.debug("No sort needed on tuples.");
- if (!sortNeeded) return tuples;
+ if (!sortNeeded) {
+ if (logger.isDebugEnabled()) logger.debug("No sort needed on tuples.");
+ return tuples;
+ }
if (logger.isDebugEnabled()) logger.debug("Sorting on " + variableList);
- // Perform the actual sort
+ // append the remaining variables to the list of variables to sort on
+ List<Variable> fullVarList = new ArrayList<Variable>(variableList);
+ for (Variable v: tuples.getVariables()) {
+ if (!variableList.contains(v)) fullVarList.add(v);
+ }
+ assert fullVarList.containsAll(Arrays.asList(tuples.getVariables()));
+
+ // Reorder the columns - the projection here does not remove any columns
Tuples oldTuples = tuples;
- tuples = tuplesFactory.newTuples(tuples, new PartialColumnComparator(varMap));
+ tuples = new UnorderedProjection(tuples, fullVarList);
assert tuples != oldTuples;
oldTuples.close();
+ // Perform the actual sort
+ oldTuples = tuples;
+ tuples = tuplesFactory.newTuples(tuples);
+ assert tuples != oldTuples;
+ oldTuples.close();
+
return tuples;
} catch (TuplesException e) {
throw new TuplesException("Couldn't perform projection", e);
More information about the Mulgara-svn
mailing list