@Override public void write(final DataOutput out) throws IOException { ProtobufUtil.toMutationNoData(MutationType.PUT, put).writeDelimitedTo(DataOutputOutputStream.from(out)); out.writeInt(put.size()); CellScanner scanner = put.cellScanner(); while(scanner.advance()) { KeyValue kv = KeyValueUtil.ensureKeyValue(scanner.current()); KeyValue.write(kv, out); } } }
@Test public void testPutIteration() throws IOException { Put p = new Put(ROW); for (int i = 0; i < COUNT; i++) { byte [] bytes = Bytes.toBytes(i); p.addColumn(bytes, bytes, TIMESTAMP, bytes); } int index = 0; for (CellScanner cellScanner = p.cellScanner(); cellScanner.advance();) { Cell cell = cellScanner.current(); byte [] bytes = Bytes.toBytes(index++); cell.equals(new KeyValue(ROW, bytes, bytes, TIMESTAMP, bytes)); } assertEquals(COUNT, index); }
@Test (expected = ConcurrentModificationException.class) public void testPutConcurrentModificationOnIteration() throws IOException { Put p = new Put(ROW); for (int i = 0; i < COUNT; i++) { byte [] bytes = Bytes.toBytes(i); p.addColumn(bytes, bytes, TIMESTAMP, bytes); } int index = 0; int trigger = 3; for (CellScanner cellScanner = p.cellScanner(); cellScanner.advance();) { Cell cell = cellScanner.current(); byte [] bytes = Bytes.toBytes(index++); // When we hit the trigger, try inserting a new KV; should trigger exception if (trigger == 3) p.addColumn(bytes, bytes, TIMESTAMP, bytes); cell.equals(new KeyValue(ROW, bytes, bytes, TIMESTAMP, bytes)); } assertEquals(COUNT, index); }
TableName.META_TABLE_NAME, System.currentTimeMillis(), mvcc, scopes); WALEdit edit = new WALEdit(); CellScanner CellScanner = put.cellScanner(); assertTrue(CellScanner.advance()); edit.add(CellScanner.current());
CellScanner cs = p.cellScanner(); while (cs.advance()) { edits.add(cs.current());
public static void main(String[] args) throws Exception { // vv CellScannerExample Put put = new Put(Bytes.toBytes("testrow")); put.addColumn(Bytes.toBytes("fam-1"), Bytes.toBytes("qual-1"), Bytes.toBytes("val-1")); put.addColumn(Bytes.toBytes("fam-1"), Bytes.toBytes("qual-2"), Bytes.toBytes("val-2")); put.addColumn(Bytes.toBytes("fam-2"), Bytes.toBytes("qual-3"), Bytes.toBytes("val-3")); CellScanner scanner = put.cellScanner(); while (scanner.advance()) { Cell cell = scanner.current(); System.out.println("Cell: " + cell); } // ^^ CellScannerExample } }
@Override public void postGetOp(ObserverContext<RegionCoprocessorEnvironment> e, Get get, List<Cell> results) throws IOException { Put put = new Put(get.getRow()); put.addColumn(get.getRow(), FIXED_COLUMN, Bytes.toBytes(counter.get())); CellScanner scanner = put.cellScanner(); scanner.advance(); Cell cell = scanner.current(); LOG.debug("Adding fake cell: " + cell); results.add(cell); }
CellScanner scanner = put.cellScanner(); while (scanner.advance()) { Cell cell = scanner.current();
@Override public void preGetOp(ObserverContext<RegionCoprocessorEnvironment> e, Get get, List<Cell> results) throws IOException { // ^^ RegionObserverExample LOG.debug("Got preGet for row: " + Bytes.toStringBinary(get.getRow())); // vv RegionObserverExample if (Bytes.equals(get.getRow(), FIXED_ROW)) { // co RegionObserverExample-1-Check Check if the request row key matches a well known one. Put put = new Put(get.getRow()); put.addColumn(FIXED_ROW, FIXED_ROW, // co RegionObserverExample-2-Cell Create cell indirectly using a Put instance. Bytes.toBytes(System.currentTimeMillis())); CellScanner scanner = put.cellScanner(); scanner.advance(); Cell cell = scanner.current(); // co RegionObserverExample-3-Current Get first cell from Put using the CellScanner instance. // ^^ RegionObserverExample LOG.debug("Had a match, adding fake cell: " + cell); // vv RegionObserverExample results.add(cell); // co RegionObserverExample-4-Create Create a special KeyValue instance containing just the current time on the server. } } }
@Override public void write(final DataOutput out) throws IOException { ProtobufUtil.toMutationNoData(MutationType.PUT, put).writeDelimitedTo(DataOutputOutputStream.from(out)); out.writeInt(put.size()); CellScanner scanner = put.cellScanner(); while(scanner.advance()) { KeyValue kv = KeyValueUtil.ensureKeyValue(scanner.current()); KeyValue.write(kv, out); } } }
@Test public void testPutIteration() throws IOException { Put p = new Put(ROW); for (int i = 0; i < COUNT; i++) { byte [] bytes = Bytes.toBytes(i); p.addColumn(bytes, bytes, TIMESTAMP, bytes); } int index = 0; for (CellScanner cellScanner = p.cellScanner(); cellScanner.advance();) { Cell cell = cellScanner.current(); byte [] bytes = Bytes.toBytes(index++); cell.equals(new KeyValue(ROW, bytes, bytes, TIMESTAMP, bytes)); } assertEquals(COUNT, index); }
@Test (expected = ConcurrentModificationException.class) public void testPutConcurrentModificationOnIteration() throws IOException { Put p = new Put(ROW); for (int i = 0; i < COUNT; i++) { byte [] bytes = Bytes.toBytes(i); p.addColumn(bytes, bytes, TIMESTAMP, bytes); } int index = 0; int trigger = 3; for (CellScanner cellScanner = p.cellScanner(); cellScanner.advance();) { Cell cell = cellScanner.current(); byte [] bytes = Bytes.toBytes(index++); // When we hit the trigger, try inserting a new KV; should trigger exception if (trigger == 3) p.addColumn(bytes, bytes, TIMESTAMP, bytes); cell.equals(new KeyValue(ROW, bytes, bytes, TIMESTAMP, bytes)); } assertEquals(COUNT, index); }
TableName.META_TABLE_NAME, System.currentTimeMillis(), mvcc, scopes); WALEdit edit = new WALEdit(); CellScanner CellScanner = put.cellScanner(); assertTrue(CellScanner.advance()); edit.add(CellScanner.current());
CellScanner cs = p.cellScanner(); while (cs.advance()) { edits.add(cs.current());