@SuppressWarnings("unchecked")
private static <K> K[] reshuffleSamples(K[] samples, String indexName, RawComparator<K> comparator, int numPartitions) {
ArrayList<K> shuffledSamples = new ArrayList<K>(samples.length);
for (K sample : samples) {
if ( sample instanceof LongQuadWritable ) {
LongQuadWritable q = (LongQuadWritable)sample;
if ( (( q.get(3) != -1L ) && (indexName.length() == 4)) || (( q.get(3) == -1L ) && (indexName.length() == 3)) ) {
LongQuadWritable shuffledQuad = null;
if ( indexName.equals("GSPO") ) shuffledQuad = new LongQuadWritable(q.get(3), q.get(0), q.get(1), q.get(2));
else if ( indexName.equals("GPOS") ) shuffledQuad = new LongQuadWritable(q.get(3), q.get(1), q.get(2), q.get(0));
else if ( indexName.equals("GOSP") ) shuffledQuad = new LongQuadWritable(q.get(3), q.get(2), q.get(0), q.get(1));
else if ( indexName.equals("SPOG") ) shuffledQuad = new LongQuadWritable(q.get(0), q.get(1), q.get(2), q.get(3));
else if ( indexName.equals("POSG") ) shuffledQuad = new LongQuadWritable(q.get(1), q.get(2), q.get(0), q.get(3));
else if ( indexName.equals("OSPG") ) shuffledQuad = new LongQuadWritable(q.get(2), q.get(0), q.get(1), q.get(3));
else if ( indexName.equals("SPO") ) shuffledQuad = new LongQuadWritable(q.get(0), q.get(1), q.get(2), -1L);
else if ( indexName.equals("POS") ) shuffledQuad = new LongQuadWritable(q.get(1), q.get(2), q.get(0), -1L);
else if ( indexName.equals("OSP") ) shuffledQuad = new LongQuadWritable(q.get(2), q.get(0), q.get(1), -1L);
shuffledSamples.add((K)shuffledQuad);
}
}
}
// This is to ensure we always have the same amount of split points
int size = shuffledSamples.size();
if ( size < numPartitions ) {
log.debug("Found only {} samples for {} partitions...", shuffledSamples.size(), numPartitions);
for (int i = 0; i < numPartitions - size; i++) {
long id = 100L * (i + 1);
K key = (K)new LongQuadWritable (id, id, id, indexName.length() == 3 ? -1L : id );
log.debug("Added fake sample: {}", key);
shuffledSamples.add(key);
}
}