public static ByteBuffer getValueBufferShallowCopy(Cell cell) { ByteBuffer buffer = ByteBuffer.wrap(cell.getValueArray(), cell.getValueOffset(), cell.getValueLength()); return buffer; }
private void consume(Result r, int nBytesToConsume) { Cell cell = r.getColumnLatestCell(CF, QN); byte mix = 0; byte[] valueArray = cell.getValueArray(); int n = Math.min(nBytesToConsume, cell.getValueLength()); for (int i = 0; i < n; i++) { mix ^= valueArray[i]; bytesRead++; } discard(mix); rowsRead++; }
/** * Writes the value from the given cell to the output stream * @param out The outputstream to which the data has to be written * @param cell The cell whose contents has to be written * @param vlength the value length * @throws IOException */ public static void writeValue(OutputStream out, Cell cell, int vlength) throws IOException { if (cell instanceof ByteBufferExtendedCell) { ByteBufferUtils.copyBufferToStream(out, ((ByteBufferExtendedCell) cell).getValueByteBuffer(), ((ByteBufferExtendedCell) cell).getValuePosition(), vlength); } else { out.write(cell.getValueArray(), cell.getValueOffset(), vlength); } }
protected Pair<Map<String, Integer>, Map<String, List<Integer>>> extractLabelsAndAuths( List<List<Cell>> labelDetails) { Map<String, Integer> labels = new HashMap<>(); Map<String, List<Integer>> userAuths = new HashMap<>(); for (List<Cell> cells : labelDetails) { for (Cell cell : cells) { if (CellUtil.matchingQualifier(cell, LABEL_QUALIFIER)) { labels.put( Bytes.toString(cell.getValueArray(), cell.getValueOffset(), cell.getValueLength()), PrivateCellUtil.getRowAsInt(cell)); } else { // These are user cells who has authorization for this label String user = Bytes.toString(cell.getQualifierArray(), cell.getQualifierOffset(), cell.getQualifierLength()); List<Integer> auths = userAuths.get(user); if (auths == null) { auths = new ArrayList<>(); userAuths.put(user, auths); } auths.add(PrivateCellUtil.getRowAsInt(cell)); } } } return new Pair<>(labels, userAuths); }
@Test public void testCellBuilderWithShallowCopy() { byte[] row = new byte[]{OLD_DATA}; byte[] family = new byte[]{OLD_DATA}; byte[] qualifier = new byte[]{OLD_DATA}; byte[] value = new byte[]{OLD_DATA}; Cell cell = CellBuilderFactory.create(CellBuilderType.SHALLOW_COPY) .setRow(row) .setFamily(family) .setQualifier(qualifier) .setType(Cell.Type.Put) .setValue(value) .build(); row[0] = NEW_DATA; family[0] = NEW_DATA; qualifier[0] = NEW_DATA; value[0] = NEW_DATA; assertEquals(NEW_DATA, cell.getRowArray()[cell.getRowOffset()]); assertEquals(NEW_DATA, cell.getFamilyArray()[cell.getFamilyOffset()]); assertEquals(NEW_DATA, cell.getQualifierArray()[cell.getQualifierOffset()]); assertEquals(NEW_DATA, cell.getValueArray()[cell.getValueOffset()]); }
assertTrue(cell0.getQualifierArray() == qualifier0); assertTrue(cell0.getValueArray() == value0); assertTrue(cell1.getQualifierArray() == qualifier1); assertTrue(cell1.getValueArray() == value1);
public static ByteBuffer getValueAsByteBuffer(Result hbaseRow, byte[] cf, byte[] cq) { List<Cell> cells = hbaseRow.listCells(); if (cells == null || cells.size() == 0) { return null; } else { for (Cell c : cells) { if (Bytes.compareTo(cf, 0, cf.length, c.getFamilyArray(), c.getFamilyOffset(), c.getFamilyLength()) == 0 && // Bytes.compareTo(cq, 0, cq.length, c.getQualifierArray(), c.getQualifierOffset(), c.getQualifierLength()) == 0) { return ByteBuffer.wrap(c.getValueArray(), c.getValueOffset(), c.getValueLength()); } } } return null; }
/** * Gets the mob file name from the mob ref cell. * A mob ref cell has a mob reference tag. * The value of a mob ref cell consists of two parts, real mob value length and mob file name. * The real mob value length takes 4 bytes. * The remaining part is the mob file name. * @param cell The mob ref cell. * @return The mob file name. */ public static String getMobFileName(Cell cell) { return Bytes.toString(cell.getValueArray(), cell.getValueOffset() + Bytes.SIZEOF_INT, cell.getValueLength() - Bytes.SIZEOF_INT); }
@Test public void testCellBuilderWithDeepCopy() { byte[] row = new byte[]{OLD_DATA}; byte[] family = new byte[]{OLD_DATA}; byte[] qualifier = new byte[]{OLD_DATA}; byte[] value = new byte[]{OLD_DATA}; Cell cell = CellBuilderFactory.create(CellBuilderType.DEEP_COPY) .setRow(row) .setFamily(family) .setQualifier(qualifier) .setType(Cell.Type.Put) .setValue(value) .build(); row[0] = NEW_DATA; family[0] = NEW_DATA; qualifier[0] = NEW_DATA; value[0] = NEW_DATA; assertEquals(OLD_DATA, cell.getRowArray()[cell.getRowOffset()]); assertEquals(OLD_DATA, cell.getFamilyArray()[cell.getFamilyOffset()]); assertEquals(OLD_DATA, cell.getQualifierArray()[cell.getQualifierOffset()]); assertEquals(OLD_DATA, cell.getValueArray()[cell.getValueOffset()]); }
/** * Converts the value bytes of the given cell into a long value * @param cell * @return value as long */ public static long getValueAsLong(Cell cell) { if (cell instanceof ByteBufferExtendedCell) { return ByteBufferUtils.toLong(((ByteBufferExtendedCell) cell).getValueByteBuffer(), ((ByteBufferExtendedCell) cell).getValuePosition()); } return Bytes.toLong(cell.getValueArray(), cell.getValueOffset()); }
public void hashResult(Result result) { if (!batchStarted) { throw new RuntimeException("Cannot add to batch that has not been started."); } for (Cell cell : result.rawCells()) { int rowLength = cell.getRowLength(); int familyLength = cell.getFamilyLength(); int qualifierLength = cell.getQualifierLength(); int valueLength = cell.getValueLength(); digest.update(cell.getRowArray(), cell.getRowOffset(), rowLength); digest.update(cell.getFamilyArray(), cell.getFamilyOffset(), familyLength); digest.update(cell.getQualifierArray(), cell.getQualifierOffset(), qualifierLength); long ts = cell.getTimestamp(); for (int i = 8; i > 0; i--) { digest.update((byte) ts); ts >>>= 8; } digest.update(cell.getValueArray(), cell.getValueOffset(), valueLength); batchSize += rowLength + familyLength + qualifierLength + 8 + valueLength; } }
public static ByteRange fillValueRange(Cell cell, ByteRange range) { return range.set(cell.getValueArray(), cell.getValueOffset(), cell.getValueLength()); }
@Test public void testExtendedCellBuilderWithDeepCopy() { byte[] row = new byte[]{OLD_DATA}; byte[] family = new byte[]{OLD_DATA}; byte[] qualifier = new byte[]{OLD_DATA}; byte[] value = new byte[]{OLD_DATA}; byte[] tags = new byte[]{OLD_DATA}; long seqId = 999; Cell cell = ExtendedCellBuilderFactory.create(CellBuilderType.DEEP_COPY) .setRow(row) .setFamily(family) .setQualifier(qualifier) .setType(KeyValue.Type.Put.getCode()) .setValue(value) .setTags(tags) .setSequenceId(seqId) .build(); row[0] = NEW_DATA; family[0] = NEW_DATA; qualifier[0] = NEW_DATA; value[0] = NEW_DATA; tags[0] = NEW_DATA; assertEquals(OLD_DATA, cell.getRowArray()[cell.getRowOffset()]); assertEquals(OLD_DATA, cell.getFamilyArray()[cell.getFamilyOffset()]); assertEquals(OLD_DATA, cell.getQualifierArray()[cell.getQualifierOffset()]); assertEquals(OLD_DATA, cell.getValueArray()[cell.getValueOffset()]); assertEquals(OLD_DATA, cell.getTagsArray()[cell.getTagsOffset()]); assertEquals(seqId, cell.getSequenceId()); } }
/** * Converts the value bytes of the given cell into a int value * @param cell * @return value as int */ public static int getValueAsInt(Cell cell) { if (cell instanceof ByteBufferExtendedCell) { return ByteBufferUtils.toInt(((ByteBufferExtendedCell) cell).getValueByteBuffer(), ((ByteBufferExtendedCell) cell).getValuePosition()); } return Bytes.toInt(cell.getValueArray(), cell.getValueOffset()); }
private void loadRecord(Result r) { Cell[] cells = r.rawCells(); Cell cell = cells[0]; if (Bytes.compareTo(CF_B, 0, CF_B.length, cell.getFamilyArray(), cell.getFamilyOffset(), cell.getFamilyLength()) != 0 // || Bytes.compareTo(COL_B, 0, COL_B.length, cell.getQualifierArray(), cell.getQualifierOffset(), cell.getQualifierLength()) != 0) throw new IllegalStateException(); rec.loadCellBlock(0, ByteBuffer.wrap(cell.getRowArray(), cell.getRowOffset() + ID_LEN, cell.getRowLength() - ID_LEN)); rec.loadCellBlock(1, ByteBuffer.wrap(cell.getValueArray(), cell.getValueOffset(), cell.getValueLength())); }
private static long getReplicationBarrier(Cell c) { return Bytes.toLong(c.getValueArray(), c.getValueOffset(), c.getValueLength()); }
@Test public void testExtendedCellBuilderWithShallowCopy() { byte[] row = new byte[]{OLD_DATA}; byte[] family = new byte[]{OLD_DATA}; byte[] qualifier = new byte[]{OLD_DATA}; byte[] value = new byte[]{OLD_DATA}; byte[] tags = new byte[]{OLD_DATA}; long seqId = 999; Cell cell = ExtendedCellBuilderFactory.create(CellBuilderType.SHALLOW_COPY) .setRow(row) .setFamily(family) .setQualifier(qualifier) .setType(KeyValue.Type.Put.getCode()) .setValue(value) .setTags(tags) .setSequenceId(seqId) .build(); row[0] = NEW_DATA; family[0] = NEW_DATA; qualifier[0] = NEW_DATA; value[0] = NEW_DATA; tags[0] = NEW_DATA; assertEquals(NEW_DATA, cell.getRowArray()[cell.getRowOffset()]); assertEquals(NEW_DATA, cell.getFamilyArray()[cell.getFamilyOffset()]); assertEquals(NEW_DATA, cell.getQualifierArray()[cell.getQualifierOffset()]); assertEquals(NEW_DATA, cell.getValueArray()[cell.getValueOffset()]); assertEquals(NEW_DATA, cell.getTagsArray()[cell.getTagsOffset()]); assertEquals(seqId, cell.getSequenceId()); }
/** * Converts the value bytes of the given cell into a double value * @param cell * @return value as double */ public static double getValueAsDouble(Cell cell) { if (cell instanceof ByteBufferExtendedCell) { return ByteBufferUtils.toDouble(((ByteBufferExtendedCell) cell).getValueByteBuffer(), ((ByteBufferExtendedCell) cell).getValuePosition()); } return Bytes.toDouble(cell.getValueArray(), cell.getValueOffset()); }
@Override public void write(Cell cell) throws IOException { checkFlushed(); // Row write(cell.getRowArray(), cell.getRowOffset(), cell.getRowLength()); // Column family write(cell.getFamilyArray(), cell.getFamilyOffset(), cell.getFamilyLength()); // Qualifier write(cell.getQualifierArray(), cell.getQualifierOffset(), cell.getQualifierLength()); // Version this.out.write(Bytes.toBytes(cell.getTimestamp())); // Type this.out.write(cell.getTypeByte()); // Value write(cell.getValueArray(), cell.getValueOffset(), cell.getValueLength()); // MvccVersion this.out.write(Bytes.toBytes(cell.getSequenceId())); }
/** * Returns the value wrapped in a new <code>ByteBuffer</code>. * * @param family family name * @param qualifier column qualifier * * @return the latest version of the column, or <code>null</code> if none found */ public ByteBuffer getValueAsByteBuffer(byte [] family, byte [] qualifier) { Cell kv = getColumnLatestCell(family, 0, family.length, qualifier, 0, qualifier.length); if (kv == null) { return null; } return ByteBuffer.wrap(kv.getValueArray(), kv.getValueOffset(), kv.getValueLength()). asReadOnlyBuffer(); }