@Override public byte[] getTagsArray() { return this.cell.getTagsArray(); }
@Override public byte[] getTagsArray() { return cell.getTagsArray(); }
public static ByteRange fillTagRange(Cell cell, ByteRange range) { return range.set(cell.getTagsArray(), cell.getTagsOffset(), cell.getTagsLength()); }
/** * Writes the tag 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 tagsLength the tag length * @throws IOException */ public static void writeTags(OutputStream out, Cell cell, int tagsLength) throws IOException { if (cell instanceof ByteBufferExtendedCell) { ByteBufferUtils.copyBufferToStream(out, ((ByteBufferExtendedCell) cell).getTagsByteBuffer(), ((ByteBufferExtendedCell) cell).getTagsPosition(), tagsLength); } else { out.write(cell.getTagsArray(), cell.getTagsOffset(), tagsLength); } }
tagLen = Bytes.readAsInt(cell.getTagsArray(), pos, TAG_LENGTH_SIZE); if (cell.getTagsArray()[pos + TAG_LENGTH_SIZE] == type) { return Optional .of(new ArrayBackedTag(cell.getTagsArray(), pos, tagLen + TAG_LENGTH_SIZE));
/** Returns a string representation of the cell */ public static String toString(Cell cell, boolean verbose) { if (cell == null) { return ""; } StringBuilder builder = new StringBuilder(); String keyStr = getCellKeyAsString(cell); String tag = null; String value = null; if (verbose) { // TODO: pretty print tags as well if (cell.getTagsLength() > 0) { tag = Bytes.toStringBinary(cell.getTagsArray(), cell.getTagsOffset(), cell.getTagsLength()); } if (!(cell instanceof KeyValue.KeyOnlyKeyValue)) { value = Bytes.toStringBinary(cell.getValueArray(), cell.getValueOffset(), cell.getValueLength()); } } builder.append(keyStr); if (tag != null && !tag.isEmpty()) { builder.append("/").append(tag); } if (value != null) { builder.append("/").append(value); } return builder.toString(); }
/** * Copies the tags info into the tag portion of the cell * @param cell * @param destination * @param destinationOffset * @return position after tags */ public static int copyTagsTo(Cell cell, byte[] destination, int destinationOffset) { int tlen = cell.getTagsLength(); if (cell instanceof ByteBufferExtendedCell) { ByteBufferUtils .copyFromBufferToArray(destination, ((ByteBufferExtendedCell) cell).getTagsByteBuffer(), ((ByteBufferExtendedCell) cell).getTagsPosition(), destinationOffset, tlen); } else { System .arraycopy(cell.getTagsArray(), cell.getTagsOffset(), destination, destinationOffset, tlen); } return destinationOffset + tlen; }
/** * Copies the tags info into the tag portion of the cell * @param cell * @param destination * @param destinationOffset * @return the position after tags */ public static int copyTagsTo(Cell cell, ByteBuffer destination, int destinationOffset) { int tlen = cell.getTagsLength(); if (cell instanceof ByteBufferExtendedCell) { ByteBufferUtils.copyFromBufferToBuffer(((ByteBufferExtendedCell) cell).getTagsByteBuffer(), destination, ((ByteBufferExtendedCell) cell).getTagsPosition(), destinationOffset, tlen); } else { ByteBufferUtils.copyFromArrayToBuffer(destination, destinationOffset, cell.getTagsArray(), cell.getTagsOffset(), tlen); } return destinationOffset + tlen; }
/** * Compresses the tags to the given outputstream using the TagcompressionContext * @param out the outputstream to which the compression should happen * @param cell the cell which has tags * @param tagCompressionContext the TagCompressionContext * @throws IOException can throw IOException if the compression encounters issue */ public static void compressTags(OutputStream out, Cell cell, TagCompressionContext tagCompressionContext) throws IOException { if (cell instanceof ByteBufferExtendedCell) { tagCompressionContext.compressTags(out, ((ByteBufferExtendedCell) cell).getTagsByteBuffer(), ((ByteBufferExtendedCell) cell).getTagsPosition(), cell.getTagsLength()); } else { tagCompressionContext.compressTags(out, cell.getTagsArray(), cell.getTagsOffset(), cell.getTagsLength()); } }
public static byte[] concatTags(byte[] tags, Cell cell) { int cellTagsLen = cell.getTagsLength(); if (cellTagsLen == 0) { // If no Tags, return early. return tags; } byte[] b = new byte[tags.length + cellTagsLen]; int pos = Bytes.putBytes(b, 0, tags, 0, tags.length); if (cell instanceof ByteBufferExtendedCell) { ByteBufferUtils.copyFromBufferToArray(b, ((ByteBufferExtendedCell) cell).getTagsByteBuffer(), ((ByteBufferExtendedCell) cell).getTagsPosition(), pos, cellTagsLen); } else { Bytes.putBytes(b, pos, cell.getTagsArray(), cell.getTagsOffset(), cellTagsLen); } return b; }
out.write(cell.getTagsArray(), cell.getTagsOffset(), tlen); size += tlen + KeyValue.TAGS_LENGTH_SIZE;
/** * Util method to iterate through the tags in the given cell. * @param cell The Cell over which tags iterator is needed. * @return iterator for the tags */ public static Iterator<Tag> tagsIterator(final Cell cell) { final int tagsLength = cell.getTagsLength(); // Save an object allocation where we can if (tagsLength == 0) { return TagUtil.EMPTY_TAGS_ITR; } if (cell instanceof ByteBufferExtendedCell) { return tagsIterator(((ByteBufferExtendedCell) cell).getTagsByteBuffer(), ((ByteBufferExtendedCell) cell).getTagsPosition(), tagsLength); } return CellUtil.tagsIterator(cell.getTagsArray(), cell.getTagsOffset(), cell.getTagsLength()); }
@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()); // Tags write(cell.getTagsArray(), cell.getTagsOffset(), cell.getTagsLength()); // MvccVersion this.out.write(Bytes.toBytes(cell.getSequenceId())); }
.setType(reference.getTypeByte()) .setValue(HConstants.EMPTY_BYTE_ARRAY) .setTags(reference.getTagsArray(), reference.getTagsOffset(), reference.getTagsLength()) .build();
public KeyValue(Cell c) { this(c.getRowArray(), c.getRowOffset(), c.getRowLength(), c.getFamilyArray(), c.getFamilyOffset(), c.getFamilyLength(), c.getQualifierArray(), c.getQualifierOffset(), c.getQualifierLength(), c.getTimestamp(), Type.codeToType(c.getTypeByte()), c.getValueArray(), c.getValueOffset(), c.getValueLength(), c.getTagsArray(), c.getTagsOffset(), c.getTagsLength()); this.seqId = c.getSequenceId(); }
Bytes.copy(kv1.getValueArray(), kv1.getValueOffset(), kv1.getValueLength()); byte[] tagsArrayInKV = Bytes.copy(kv1.getTagsArray(), kv1.getTagsOffset(), kv1.getTagsLength()); assertArrayEquals(qualifierArrayInKV, ic1.getQualifierArray()); assertArrayEquals(valueArrayInKV , ic1.getValueArray()); assertArrayEquals(tagsArrayInKV , ic1.getTagsArray());
private ResultCell getResultCell(Cell cell) { final ResultCell resultCell = new ResultCell(); resultCell.setRowArray(cell.getRowArray()); resultCell.setRowOffset(cell.getRowOffset()); resultCell.setRowLength(cell.getRowLength()); resultCell.setFamilyArray(cell.getFamilyArray()); resultCell.setFamilyOffset(cell.getFamilyOffset()); resultCell.setFamilyLength(cell.getFamilyLength()); resultCell.setQualifierArray(cell.getQualifierArray()); resultCell.setQualifierOffset(cell.getQualifierOffset()); resultCell.setQualifierLength(cell.getQualifierLength()); resultCell.setTimestamp(cell.getTimestamp()); resultCell.setTypeByte(cell.getTypeByte()); resultCell.setSequenceId(cell.getSequenceId()); resultCell.setValueArray(cell.getValueArray()); resultCell.setValueOffset(cell.getValueOffset()); resultCell.setValueLength(cell.getValueLength()); resultCell.setTagsArray(cell.getTagsArray()); resultCell.setTagsOffset(cell.getTagsOffset()); resultCell.setTagsLength(cell.getTagsLength()); return resultCell; }
private ResultCell getResultCell(Cell cell) { final ResultCell resultCell = new ResultCell(); resultCell.setRowArray(cell.getRowArray()); resultCell.setRowOffset(cell.getRowOffset()); resultCell.setRowLength(cell.getRowLength()); resultCell.setFamilyArray(cell.getFamilyArray()); resultCell.setFamilyOffset(cell.getFamilyOffset()); resultCell.setFamilyLength(cell.getFamilyLength()); resultCell.setQualifierArray(cell.getQualifierArray()); resultCell.setQualifierOffset(cell.getQualifierOffset()); resultCell.setQualifierLength(cell.getQualifierLength()); resultCell.setTimestamp(cell.getTimestamp()); resultCell.setTypeByte(cell.getTypeByte()); resultCell.setSequenceId(cell.getSequenceId()); resultCell.setValueArray(cell.getValueArray()); resultCell.setValueOffset(cell.getValueOffset()); resultCell.setValueLength(cell.getValueLength()); resultCell.setTagsArray(cell.getTagsArray()); resultCell.setTagsOffset(cell.getTagsOffset()); resultCell.setTagsLength(cell.getTagsLength()); return resultCell; }
@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()); } }
@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()); }