if (cursor.size() == 0) {
for (byte[] key : keysToLookup) {
KeyValue<Row> kv = new KeyValue<Row>();
kv.setKey(key);
kv.setValue(null);
ByteArray b = new ByteArray(key);
map.put(b, kv);
cache.cacheRow(cf, key, kv.getValue());
}
} else {
while (cursor.hasNext()) {
DBObject mdbrow = cursor.next();
KeyValue<Row> kv = new KeyValue<Row>();
byte[] mdbRowKey = StandardConverters.convertToBytes(mdbrow
.get("_id"));
kv.setKey(mdbRowKey);
if (!mdbrow.keySet().isEmpty()) {
Row r = rowProvider.get();
r.setKey(mdbRowKey);
MongoDbUtil.processColumns(mdbrow, r);
kv.setValue(r);
}
ByteArray b = new ByteArray(mdbRowKey);
map.put(b, kv);
cache.cacheRow(cf, mdbRowKey, kv.getValue());
}
// Now put the remaining keys which are not in MongoDB's cursor.
// This is because Cassandra returns all the rows with rowkeys while Mongodb doesn't
for (byte[] key : keysToLookup) {
ByteArray baKey = new ByteArray(key);
if (!map.containsKey(baKey)) {
KeyValue<Row> kv = new KeyValue<Row>();
kv.setKey(key);
kv.setValue(null);
// ByteArray b = new ByteArray(key);