@Test public void testEmptyStuff() throws IOException { SortedMap<Key,Value> map = new TreeMap<>(); SortedMap<Key,Value> map2 = new TreeMap<>(); final Map<Text,Boolean> toInclude = new HashMap<>(); map.put(new Key(new Text("r1"), new Text("cf1"), new Text("cq1"), new Text("cv1"), 1L), new Value("val1")); map.put(new Key(new Text("r1"), new Text("cf1"), new Text("cq2"), new Text("cv1"), 2L), new Value("val2")); map.put(new Key(new Text("r2"), new Text("cf1"), new Text("cq1"), new Text("cv1"), 3L), new Value("val3")); map.put(new Key(new Text("r2"), new Text("cf2"), new Text("cq1"), new Text("cv1"), 4L), new Value("val4")); map.put(new Key(new Text("r3"), new Text("cf1"), new Text("cq1"), new Text("cv1"), 5L), new Value("val4")); map.put(new Key(new Text("r3"), new Text("cf1"), new Text("cq1"), new Text("cv2"), 6L), new Value("val4")); map.put(new Key(new Text("r4"), new Text("cf1"), new Text("cq1"), new Text("cv1"), 7L), new Value("")); map.put(new Key(new Text("r4"), new Text("cf1"), new Text("cq1"), new Text(""), 8L), new Value("val1")); map.put(new Key(new Text("r4"), new Text("cf1"), new Text(""), new Text("cv1"), 9L), new Value("val1")); map.put(new Key(new Text("r4"), new Text(""), new Text("cq1"), new Text("cv1"), 10L), new Value("val1")); map.put(new Key(new Text(""), new Text("cf1"), new Text("cq1"), new Text("cv1"), 11L), new Value("val1")); boolean b = true; int trueCount = 0; for (Key k : map.keySet()) { if (toInclude.containsKey(k.getRow())) { if (toInclude.get(k.getRow())) { map2.put(k, map.get(k)); } continue; } b = !b; toInclude.put(k.getRow(), b); if (b) { trueCount++; map2.put(k, map.get(k)); } } SortedMapIterator source = new SortedMapIterator(map); WholeRowIterator iter = new WholeRowIterator(source); SortedMap<Key,Value> resultMap = new TreeMap<>(); iter.seek(new Range(), new ArrayList<>(), false); int numRows = 0; while (iter.hasTop()) { numRows++; Key rowKey = iter.getTopKey(); Value rowValue = iter.getTopValue(); resultMap.putAll(WholeRowIterator.decodeRow(rowKey, rowValue)); iter.next(); } assertEquals(5, numRows); assertEquals(resultMap, map); WholeRowIterator iter2 = new WholeRowIterator(source) { @Override public boolean filter(Text row, List<Key> keys, List<Value> values) { return toInclude.get(row); } }; resultMap.clear(); iter2.seek(new Range(), new ArrayList<>(), false); numRows = 0; while (iter2.hasTop()) { numRows++; Key rowKey = iter2.getTopKey(); Value rowValue = iter2.getTopValue(); resultMap.putAll(WholeRowIterator.decodeRow(rowKey, rowValue)); iter2.next(); } assertEquals(numRows, trueCount); assertEquals(resultMap, map2); }
public static final SortedMap<Key,Value> decodeRow(Key rowKey, Value rowValue) throws IOException { SortedMap<Key,Value> map = new TreeMap<>(); ByteArrayInputStream in = new ByteArrayInputStream(rowValue.get()); DataInputStream din = new DataInputStream(in); int numKeys = din.readInt(); for (int i = 0; i < numKeys; i++) { byte[] cf = readField(din); byte[] cq = readField(din); byte[] cv = readField(din); long timestamp = din.readLong(); byte[] valBytes = readField(din); map.put(new Key(rowKey.getRowData().toArray(), cf, cq, cv, timestamp, false, false), new Value(valBytes, false)); } return map; }
WholeRowIterator extends RowEncodingIterator { public static final SortedMap<Key,Value> decodeRow(Key rowKey, Value rowValue) throws IOException { SortedMap<Key,Value> map = new TreeMap<>(); ByteArrayInputStream in = new ByteArrayInputStream(rowValue.get()); DataInputStream din = new DataInputStream(in); int numKeys = din.readInt(); for (int i = 0; i < numKeys; i++) { byte[] cf = readField(din); byte[] cq = readField(din); byte[] cv = readField(din); long timestamp = din.readLong(); byte[] valBytes = readField(din); map.put(new Key(rowKey.getRowData().toArray(), cf, cq, cv, timestamp, false, false), new Value(valBytes, false)); } return map; } }
WholeRowIterator extends RowEncodingIterator { public static final SortedMap<Key,Value> decodeRow(Key rowKey, Value rowValue) throws IOException { SortedMap<Key,Value> map = new TreeMap<>(); ByteArrayInputStream in = new ByteArrayInputStream(rowValue.get()); DataInputStream din = new DataInputStream(in); int numKeys = din.readInt(); for (int i = 0; i < numKeys; i++) { byte[] cf = readField(din); byte[] cq = readField(din); byte[] cv = readField(din); long timestamp = din.readLong(); byte[] valBytes = readField(din); map.put(new Key(rowKey.getRowData().toArray(), cf, cq, cv, timestamp, false, false), new Value(valBytes, false)); } return map; } WholeRowIterator();   WholeRowIterator(SortedKeyValueIterator<Key,Value> source); }
WholeRowIterator extends RowEncodingIterator { public static final SortedMap<Key,Value> decodeRow(Key rowKey, Value rowValue) throws IOException { SortedMap<Key,Value> map = new TreeMap<>(); ByteArrayInputStream in = new ByteArrayInputStream(rowValue.get()); DataInputStream din = new DataInputStream(in); int numKeys = din.readInt(); for (int i = 0; i < numKeys; i++) { byte[] cf = readField(din); byte[] cq = readField(din); byte[] cv = readField(din); long timestamp = din.readLong(); byte[] valBytes = readField(din); map.put(new Key(rowKey.getRowData().toArray(), cf, cq, cv, timestamp, false, false), new Value(valBytes, false)); } return map; } WholeRowIterator();   WholeRowIterator(SortedKeyValueIterator<Key,Value> source); @Override SortedMap<Key,Value> rowDecoder(Key rowKey, Value rowValue); @Override Value rowEncoder(List<Key> keys, List<Value> values); static final SortedMap<Key,Value> decodeRow(Key rowKey, Value rowValue); static final Value encodeRow(List<Key> keys, List<Value> values); }
WholeRowIterator extends RowEncodingIterator { public static final SortedMap<Key,Value> decodeRow(Key rowKey, Value rowValue) throws IOException { SortedMap<Key,Value> map = new TreeMap<>(); ByteArrayInputStream in = new ByteArrayInputStream(rowValue.get()); DataInputStream din = new DataInputStream(in); int numKeys = din.readInt(); for (int i = 0; i < numKeys; i++) { byte[] cf = readField(din); byte[] cq = readField(din); byte[] cv = readField(din); long timestamp = din.readLong(); byte[] valBytes = readField(din); map.put(new Key(rowKey.getRowData().toArray(), cf, cq, cv, timestamp, false, false), new Value(valBytes, false)); } return map; } WholeRowIterator();   WholeRowIterator(SortedKeyValueIterator<Key,Value> source); @Override SortedMap<Key,Value> rowDecoder(Key rowKey, Value rowValue); @Override Value rowEncoder(List<Key> keys, List<Value> values); static final SortedMap<Key,Value> decodeRow(Key rowKey, Value rowValue); static final Value encodeRow(List<Key> keys, List<Value> values);  }