results.put(override, tr);
}
if (log.isDebugEnabled())
log.debug("Querying global index table: " + tableName + ", range: " + rangeSuperSet.toString() + " colf: " + specificFieldName);
BatchScanner bs = this.c.createBatchScanner(tableName, this.auths, this.queryThreads);
bs.setRanges(rangeSuperSet);
if (null != specificFieldName) {
bs.fetchColumnFamily(new Text(specificFieldName));
}
for (Entry<Key,Value> entry : bs) {
if (log.isDebugEnabled()) {
log.debug("Index entry: " + entry.getKey().toString());
}
String fieldValue = null;
if (!isReverse) {
fieldValue = entry.getKey().getRow().toString();
} else {
StringBuilder buf = new StringBuilder(entry.getKey().getRow().toString());
fieldValue = buf.reverse().toString();
}
String fieldName = entry.getKey().getColumnFamily().toString();
// Get the shard id and datatype from the colq
String colq = entry.getKey().getColumnQualifier().toString();
int separator = colq.indexOf(EvaluatingIterator.NULL_BYTE_STRING);
String shardId = null;
String datatype = null;
if (separator != -1) {
shardId = colq.substring(0, separator);
datatype = colq.substring(separator + 1);
} else {
shardId = colq;
}
// Skip this entry if the type is not correct
if (null != datatype && null != typeFilter && !typeFilter.contains(datatype))
continue;
// Parse the UID.List object from the value
Uid.List uidList = null;
try {
uidList = Uid.List.parseFrom(entry.getValue().get());
} catch (InvalidProtocolBufferException e) {
// Don't add UID information, at least we know what shards
// it is located in.
}
// Add the count for this shard to the total count for the term.
long count = 0;
Long storedCount = termCardinalities.get(fieldName);
if (null == storedCount || 0 == storedCount) {
count = uidList.getCOUNT();
} else {
count = uidList.getCOUNT() + storedCount;
}
termCardinalities.put(fieldName, count);
this.indexEntries.put(fieldName, fieldValue);
if (null == override)
this.indexValues.put(fieldValue, fieldValue);
else
this.indexValues.put(fieldValue, override.getOriginalQueryValue());
// Create the keys
Text shard = new Text(shardId);
if (uidList.getIGNORE()) {
// Then we create a scan range that is the entire shard
if (null == override)
results.get(new MapKey(fieldName, fieldValue)).add(new Range(shard));
else
results.get(override).add(new Range(shard));
} else {
// We should have UUIDs, create event ranges
for (String uuid : uidList.getUIDList()) {
Text cf = new Text(datatype);
TextUtil.textAppend(cf, uuid);
Key startKey = new Key(shard, cf);
Key endKey = new Key(shard, new Text(cf.toString() + EvaluatingIterator.NULL_BYTE_STRING));
Range eventRange = new Range(startKey, true, endKey, false);
if (null == override)
results.get(new MapKey(fieldName, fieldValue)).add(eventRange);
else
results.get(override).add(eventRange);
}
}
}
bs.close();
return results;
}