@Override public byte[] getQualifierArray() { return CellUtil.cloneQualifier(this); }
@Override public byte[] getQualifierArray() { return CellUtil.cloneQualifier(this); }
@Override public byte[] getQualifierArray() { if (this.buf.hasArray()) { return this.buf.array(); } return CellUtil.cloneQualifier(this); }
@Override public ByteBuffer getQualifierByteBuffer() { if (cell instanceof ByteBufferExtendedCell) { return ((ByteBufferExtendedCell) this.cell).getQualifierByteBuffer(); } else { return ByteBuffer.wrap(CellUtil.cloneQualifier(this.cell)); } }
@Override public List<Values> toValues(ITuple tuple, Result result) throws Exception { List<Values> values = new ArrayList<Values>(); Cell[] cells = result.rawCells(); for (Cell cell : cells) { Values value = new Values(Bytes.toString(CellUtil.cloneQualifier(cell)), Bytes.toLong(CellUtil.cloneValue(cell))); values.add(value); } return values; }
/** * 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)); }
private static String getRowQualStr(Cell kv) { String rowStr = Bytes.toString(CellUtil.cloneRow(kv)); String qualStr = Bytes.toString(CellUtil.cloneQualifier(kv)); return rowStr + "_" + qualStr; }
/** * 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); }
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))); }
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); }
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(); }
private void assertSingleResult(Result result, byte[] row, byte[] family, byte[] qualifier, long value) throws Exception { assertTrue( "Expected row [" + Bytes.toString(row) + "] " + "Got row [" + Bytes.toString(result.getRow()) + "]", equals(row, result.getRow())); assertTrue("Expected a single key but result contains " + result.size(), result.size() == 1); Cell kv = result.rawCells()[0]; assertTrue( "Expected family [" + Bytes.toString(family) + "] " + "Got family [" + Bytes.toString(CellUtil.cloneFamily(kv)) + "]", equals(family, CellUtil.cloneFamily(kv))); assertTrue("Expected qualifier [" + Bytes.toString(qualifier) + "] " + "Got qualifier [" + Bytes.toString(CellUtil.cloneQualifier(kv)) + "]", equals(qualifier, CellUtil.cloneQualifier(kv))); assertTrue( "Expected value [" + value + "] " + "Got value [" + Bytes.toLong(CellUtil.cloneValue(kv)) + "]", value == Bytes.toLong(CellUtil.cloneValue(kv))); }
/** * 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 testAppendWithoutWAL() throws Exception { List<Result> resultsWithWal = doAppend(true); List<Result> resultsWithoutWal = doAppend(false); assertEquals(resultsWithWal.size(), resultsWithoutWal.size()); for (int i = 0; i != resultsWithWal.size(); ++i) { Result resultWithWal = resultsWithWal.get(i); Result resultWithoutWal = resultsWithoutWal.get(i); assertEquals(resultWithWal.rawCells().length, resultWithoutWal.rawCells().length); for (int j = 0; j != resultWithWal.rawCells().length; ++j) { Cell cellWithWal = resultWithWal.rawCells()[j]; Cell cellWithoutWal = resultWithoutWal.rawCells()[j]; assertTrue(Bytes.equals(CellUtil.cloneRow(cellWithWal), CellUtil.cloneRow(cellWithoutWal))); assertTrue(Bytes.equals(CellUtil.cloneFamily(cellWithWal), CellUtil.cloneFamily(cellWithoutWal))); assertTrue(Bytes.equals(CellUtil.cloneQualifier(cellWithWal), CellUtil.cloneQualifier(cellWithoutWal))); assertTrue(Bytes.equals(CellUtil.cloneValue(cellWithWal), CellUtil.cloneValue(cellWithoutWal))); } } }
private Cell newCellWithNotExistColumnFamily(Cell cell) { return ExtendedCellBuilderFactory.create(CellBuilderType.SHALLOW_COPY) .setRow(cell.getRowArray(), cell.getRowOffset(), cell.getRowLength()) .setFamily(CF_NOT_EXIST_BYTES, 0, CF_NOT_EXIST_BYTES.length) .setQualifier(CellUtil.cloneQualifier(cell)).setTimestamp(cell.getTimestamp()) .setType(cell.getType().getCode()).setValue(CellUtil.cloneValue(cell)).build(); }
private Cell newCellWithDifferentColumnFamily(Cell cell) { return ExtendedCellBuilderFactory.create(CellBuilderType.SHALLOW_COPY) .setRow(cell.getRowArray(), cell.getRowOffset(), cell.getRowLength()) .setFamily(CF2_BYTES, 0, CF2_BYTES.length).setQualifier(CellUtil.cloneQualifier(cell)) .setTimestamp(cell.getTimestamp()).setType(cell.getType().getCode()) .setValue(CellUtil.cloneValue(cell)).build(); }