@Override public byte[] getFamilyArray() { return CellUtil.cloneFamily(this); }
@Override public byte[] getFamilyArray() { return CellUtil.cloneFamily(this); }
@Override public byte[] getFamilyArray() { if (this.buf.hasArray()) { return this.buf.array(); } return CellUtil.cloneFamily(this); }
@Override public ByteBuffer getFamilyByteBuffer() { if (cell instanceof ByteBufferExtendedCell) { return ((ByteBufferExtendedCell) this.cell).getFamilyByteBuffer(); } else { return ByteBuffer.wrap(CellUtil.cloneFamily(this.cell)); } }
@InterfaceAudience.Private public WALEdit add(Cell cell) { // We clone Family each time we add a Cell. Expensive but safe. For CPU savings, use // add(Map) or add(Cell, family). return add(cell, CellUtil.cloneFamily(cell)); }
/** * @see #applyToMemStore(HStore, List, boolean, MemStoreSizing) */ private void applyToMemStore(HStore store, Cell cell, MemStoreSizing memstoreAccounting) throws IOException { // Any change in how we update Store/MemStore needs to also be done in other applyToMemStore!!!! if (store == null) { checkFamily(CellUtil.cloneFamily(cell)); // Unreachable because checkFamily will throw exception } store.add(cell, memstoreAccounting); }
/** * Constructor from KeyValue * @param cell */ public CellModel(org.apache.hadoop.hbase.Cell cell) { this(CellUtil.cloneFamily(cell), CellUtil.cloneQualifier(cell), cell.getTimestamp(), CellUtil .cloneValue(cell)); }
/** * Decrement the timestamp. For tests (currently wasteful) * * Remember timestamps are sorted reverse chronologically. * @param in * @return previous key */ public static KeyValue previousKey(final KeyValue in) { return createFirstOnRow(CellUtil.cloneRow(in), CellUtil.cloneFamily(in), CellUtil.cloneQualifier(in), in.getTimestamp() - 1); }
@Override public Cell filterCell(Entry entry, Cell cell) { NavigableMap<byte[], Integer> scopes = entry.getKey().getReplicationScopes(); if (scopes == null || scopes.isEmpty()) { return null; } byte[] family = CellUtil.cloneFamily(cell); if (CellUtil.matchingColumn(cell, WALEdit.METAFAMILY, WALEdit.BULK_LOAD)) { return bulkLoadFilter.filterCell(cell, new Predicate<byte[]>() { @Override public boolean apply(byte[] family) { return !hasGlobalScope(scopes, family); } }); } return hasGlobalScope(scopes, family) ? cell : null; } }
private CellSetModel createModelFromResults(Result[] results) { CellSetModel cellSetModel = new CellSetModel(); for (Result rs : results) { byte[] rowKey = rs.getRow(); RowModel rModel = new RowModel(rowKey); List<Cell> kvs = rs.listCells(); for (Cell kv : kvs) { rModel.addCell(new CellModel(CellUtil.cloneFamily(kv), CellUtil.cloneQualifier(kv), kv .getTimestamp(), CellUtil.cloneValue(kv))); } cellSetModel.addRow(rModel); } return cellSetModel; } }
private void assertKey(Cell key, byte [] row, byte [] family, byte [] qualifier, byte [] value) throws Exception { assertTrue("Expected row [" + Bytes.toString(row) + "] " + "Got row [" + Bytes.toString(CellUtil.cloneRow(key)) +"]", equals(row, CellUtil.cloneRow(key))); assertTrue("Expected family [" + Bytes.toString(family) + "] " + "Got family [" + Bytes.toString(CellUtil.cloneFamily(key)) + "]", equals(family, CellUtil.cloneFamily(key))); assertTrue("Expected qualifier [" + Bytes.toString(qualifier) + "] " + "Got qualifier [" + Bytes.toString(CellUtil.cloneQualifier(key)) + "]", equals(qualifier, CellUtil.cloneQualifier(key))); assertTrue("Expected value [" + Bytes.toString(value) + "] " + "Got value [" + Bytes.toString(CellUtil.cloneValue(key)) + "]", equals(value, CellUtil.cloneValue(key))); }
protected CellSetModel buildModelFromPut(Put put) { RowModel row = new RowModel(put.getRow()); long ts = put.getTimestamp(); for (List<Cell> cells: put.getFamilyCellMap().values()) { for (Cell cell: cells) { row.addCell(new CellModel(CellUtil.cloneFamily(cell), CellUtil.cloneQualifier(cell), ts != HConstants.LATEST_TIMESTAMP ? ts : cell.getTimestamp(), CellUtil.cloneValue(cell))); } } CellSetModel model = new CellSetModel(); model.addRow(row); return model; }
/** * Assert that the passed in Cell has expected contents for the specified row, * column & timestamp. */ private void checkOneCell(Cell kv, byte[] cf, int rowIdx, int colIdx, long ts) { String ctx = "rowIdx=" + rowIdx + "; colIdx=" + colIdx + "; ts=" + ts; assertEquals("Row mismatch which checking: " + ctx, "row:" + rowIdx, Bytes.toString(CellUtil.cloneRow(kv))); assertEquals("ColumnFamily mismatch while checking: " + ctx, Bytes.toString(cf), Bytes.toString(CellUtil.cloneFamily(kv))); assertEquals("Column qualifier mismatch while checking: " + ctx, "column:" + colIdx, Bytes.toString(CellUtil.cloneQualifier(kv))); assertEquals("Timestamp mismatch while checking: " + ctx, ts, kv.getTimestamp()); assertEquals("Value mismatch while checking: " + ctx, "value-version-" + ts, Bytes.toString(CellUtil.cloneValue(kv))); }
private void verify(final Table table) throws IOException { Scan scan = new Scan(); scan.addColumn(FAMILY_NAME, COLUMN_NAME); scan.setMaxVersions(1); ResultScanner scanner = table.getScanner(scan); for (Result r: scanner) { for (Cell kv : r.listCells()) { log.debug(Bytes.toString(r.getRow()) + "\t" + Bytes.toString(CellUtil.cloneFamily(kv)) + "\t" + Bytes.toString(CellUtil.cloneQualifier(kv)) + "\t" + kv.getTimestamp() + "\t" + Bytes.toBoolean(CellUtil.cloneValue(kv))); org.junit.Assert.assertEquals(TIMESTAMP.get(kv.getTimestamp()), Bytes.toBoolean(CellUtil.cloneValue(kv))); } } scanner.close(); }
static void assertIncrementKey(Cell key, byte [] row, byte [] family, byte [] qualifier, long value) throws Exception { assertTrue("Expected row [" + Bytes.toString(row) + "] " + "Got row [" + Bytes.toString(CellUtil.cloneRow(key)) +"]", equals(row, CellUtil.cloneRow(key))); assertTrue("Expected family [" + Bytes.toString(family) + "] " + "Got family [" + Bytes.toString(CellUtil.cloneFamily(key)) + "]", equals(family, CellUtil.cloneFamily(key))); assertTrue("Expected qualifier [" + Bytes.toString(qualifier) + "] " + "Got qualifier [" + Bytes.toString(CellUtil.cloneQualifier(key)) + "]", equals(qualifier, CellUtil.cloneQualifier(key))); assertTrue("Expected value [" + value + "] " + "Got value [" + Bytes.toLong(CellUtil.cloneValue(key)) + "]", Bytes.toLong(CellUtil.cloneValue(key)) == value); }
/** * Assert the value is not store in mob. */ private static void assertNotMobReference(Cell cell, byte[] row, byte[] family, byte[] value) throws IOException { Assert.assertArrayEquals(row, CellUtil.cloneRow(cell)); Assert.assertArrayEquals(family, CellUtil.cloneFamily(cell)); Assert.assertArrayEquals(value, CellUtil.cloneValue(cell)); }
private static void assertResult(Result result, byte[] expectedValue) { assertFalse(result.isEmpty()); for (Cell c : result.rawCells()) { assertTrue(c.toString(), Bytes.equals(ROW, CellUtil.cloneRow(c))); assertTrue(c.toString(), Bytes.equals(FAMILY, CellUtil.cloneFamily(c))); assertTrue(c.toString(), Bytes.equals(expectedValue, CellUtil.cloneValue(c))); } }
/** * Compare two Cells only for their row family qualifier value */ public static void assertCellEquals(Cell firstKeyValue, Cell secondKeyValue) { Assert.assertArrayEquals(CellUtil.cloneRow(firstKeyValue), CellUtil.cloneRow(secondKeyValue)); Assert.assertArrayEquals(CellUtil.cloneFamily(firstKeyValue), CellUtil.cloneFamily(secondKeyValue)); Assert.assertArrayEquals(CellUtil.cloneQualifier(firstKeyValue), CellUtil.cloneQualifier(secondKeyValue)); Assert.assertArrayEquals(CellUtil.cloneValue(firstKeyValue), CellUtil.cloneValue(secondKeyValue)); }
private static void assertResult(Result result, byte[] expectedValue, byte[] expectedFromCp) { assertFalse(result.isEmpty()); for (Cell c : result.rawCells()) { assertTrue(c.toString(), Bytes.equals(ROW, CellUtil.cloneRow(c))); assertTrue(c.toString(), Bytes.equals(FAMILY, CellUtil.cloneFamily(c))); if (Bytes.equals(QUALIFIER, CellUtil.cloneQualifier(c))) { assertTrue(c.toString(), Bytes.equals(expectedValue, CellUtil.cloneValue(c))); } else if (Bytes.equals(QUALIFIER_FROM_CP, CellUtil.cloneQualifier(c))) { assertTrue(c.toString(), Bytes.equals(expectedFromCp, CellUtil.cloneValue(c))); } else { fail("No valid qualifier"); } } }
@Test public void testAppendIteration() throws IOException { Append a = new Append(ROW); for (int i = 0; i < COUNT; i++) { byte [] bytes = Bytes.toBytes(i); a.addColumn(bytes, bytes, bytes); } int index = 0; for (CellScanner cellScanner = a.cellScanner(); cellScanner.advance();) { Cell cell = cellScanner.current(); byte [] bytes = Bytes.toBytes(index++); KeyValue kv = (KeyValue)cell; assertTrue(Bytes.equals(CellUtil.cloneFamily(kv), bytes)); assertTrue(Bytes.equals(CellUtil.cloneValue(kv), bytes)); } assertEquals(COUNT, index); }