KeyValue kv = row.get(0);
final byte[] qual = kv.qualifier();
if (qual.length % 2 != 0 || qual.length == 0) {
// This could be a row with only an annotation in it
if ((qual[0] | Annotation.PREFIX()) == Annotation.PREFIX()) {
final Annotation note = JSON.parseToObject(kv.value(),
Annotation.class);
annotations.add(note);
}
return null;
}
final byte[] val = kv.value();
if (qual.length == 2 && Internal.floatingPointValueToFix(qual[1], val)) {
// Fix up old, incorrectly encoded floating point value.
final byte[] newval = Internal.fixFloatingPointValue(qual[1], val);
final byte[] newqual = new byte[] { qual[0],
Internal.fixQualifierFlags(qual[1], newval.length) };
kv = new KeyValue(kv.key(), kv.family(), newqual, newval);
}
compacted[0] = kv;
}
return null;
}
// We know we have at least 2 cells. We need to go through all the cells
// to determine what kind of compaction we're going to do. If each cell
// contains a single individual data point, then we can do a trivial
// compaction. Otherwise, we have a partially compacted row, and the
// logic required to compact it is more complex.
boolean write = true; // Do we need to write a compacted cell?
final KeyValue compact;
{
boolean trivial = true; // Are we doing a trivial compaction?
boolean ms_in_row = false;
boolean s_in_row = false;
int qual_len = 0; // Pre-compute the size of the qualifier we'll need.
int val_len = 1; // Reserve an extra byte for meta-data.
KeyValue longest = row.get(0); // KV with the longest qualifier.
int longest_idx = 0; // Index of `longest'.
int nkvs = row.size();
for (int i = 0; i < nkvs; i++) {
final KeyValue kv = row.get(i);
final byte[] qual = kv.qualifier();
// If the qualifier length isn't 2, this row might have already
// been compacted, potentially partially, so we need to merge the
// partially compacted set of cells, with the rest.
final int len = qual.length;
if (len != 2 && len != 4) {
// Datapoints and compacted columns should have qualifiers with an
// even number of bytes. If we find one with an odd number, or an
// empty qualifier (which is possible), we need to remove it from the
// compaction queue.
if (len % 2 != 0 || len == 0) {
// if the qualifier is 3 bytes and starts with the Annotation prefix,
// parse it out.
if ((qual[0] | Annotation.PREFIX()) == Annotation.PREFIX()) {
final Annotation note = JSON.parseToObject(kv.value(),
Annotation.class);
annotations.add(note);
}
row.remove(i); // This is O(n) but should happen *very* rarely.