@Override public int getTagsLength() { return this.cell.getTagsLength(); }
@Override public int getTagsLength() { return cell.getTagsLength(); }
public static byte[] cloneTags(Cell cell) { byte[] output = new byte[cell.getTagsLength()]; copyTagsTo(cell, output, 0); return output; }
/** * Whether the current cell is a mob reference cell. * @param cell The current cell. * @return True if the cell has a mob reference tag, false if it doesn't. */ public static boolean isMobReferenceCell(Cell cell) { if (cell.getTagsLength() > 0) { Optional<Tag> tag = PrivateCellUtil.getTag(cell, TagType.MOB_REFERENCE_TAG_TYPE); if (tag.isPresent()) { return true; } } return false; }
/** * Gets the table name tag. * @param cell The current cell. * @return The table name tag. */ public static Tag getTableNameTag(Cell cell) { if (cell.getTagsLength() > 0) { Optional<Tag> tag = PrivateCellUtil.getTag(cell, TagType.MOB_TABLE_NAME_TAG_TYPE); if (tag.isPresent()) { return tag.get(); } } return null; }
public static ByteRange fillTagRange(Cell cell, ByteRange range) { return range.set(cell.getTagsArray(), cell.getTagsOffset(), cell.getTagsLength()); }
/** * 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()); } }
/** * 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()); }
/**************** copy key and value *********************/ public static int appendToByteArray(Cell cell, byte[] output, int offset, boolean withTags) { int pos = offset; pos = Bytes.putInt(output, pos, keyLength(cell)); pos = Bytes.putInt(output, pos, cell.getValueLength()); pos = appendKeyTo(cell, output, pos); pos = CellUtil.copyValueTo(cell, output, pos); if (withTags && (cell.getTagsLength() > 0)) { pos = Bytes.putAsShort(output, pos, cell.getTagsLength()); pos = PrivateCellUtil.copyTagsTo(cell, output, pos); } return pos; }
/** * 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; }
/** * Clone the passed cell by copying its data into the passed buf and create a cell with a chunkid * out of it * @see #copyBBECToChunkCell(ByteBufferExtendedCell, ByteBuffer, int, int) */ private static Cell copyToChunkCell(Cell cell, ByteBuffer buf, int offset, int len) { int tagsLen = cell.getTagsLength(); if (cell instanceof ExtendedCell) { ((ExtendedCell) cell).write(buf, offset); } else { // Normally all Cell impls within Server will be of type ExtendedCell. Just considering the // other case also. The data fragments within Cell is copied into buf as in KeyValue // serialization format only. KeyValueUtil.appendTo(cell, buf, offset, true); } return createChunkCell(buf, offset, len, tagsLen, cell.getSequenceId()); }
private static Map<String, Object> toStringMap(Cell cell) { Map<String, Object> stringMap = new HashMap<>(); stringMap.put("row", Bytes.toStringBinary(cell.getRowArray(), cell.getRowOffset(), cell.getRowLength())); stringMap.put("family", Bytes.toStringBinary(cell.getFamilyArray(), cell.getFamilyOffset(), cell.getFamilyLength())); stringMap.put("qualifier", Bytes.toStringBinary(cell.getQualifierArray(), cell.getQualifierOffset(), cell.getQualifierLength())); stringMap.put("timestamp", cell.getTimestamp()); stringMap.put("vlen", cell.getValueLength()); if (cell.getTagsLength() > 0) { List<String> tagsString = new ArrayList<>(); Iterator<Tag> tagsIterator = PrivateCellUtil.tagsIterator(cell); while (tagsIterator.hasNext()) { Tag tag = tagsIterator.next(); tagsString .add((tag.getType()) + ":" + Bytes.toStringBinary(Tag.cloneValue(tag))); } stringMap.put("tag", tagsString); } return stringMap; }
public static int getSerializedSize(Cell cell, boolean withTags) { if (withTags) { return cell.getSerializedSize(); } if (cell instanceof ExtendedCell) { return ((ExtendedCell) cell).getSerializedSize(withTags); } return length(cell.getRowLength(), cell.getFamilyLength(), cell.getQualifierLength(), cell.getValueLength(), cell.getTagsLength(), withTags); }
/** * 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; }
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; }
public int write(Cell cell) throws IOException { // We write tags seperately because though there is no tag in KV // if the hfilecontext says include tags we need the tags length to be // written int size = KeyValueUtil.oswrite(cell, out, false); // Write the additional tag into the stream if (encodingCtx.getHFileContext().isIncludesTags()) { int tagsLength = cell.getTagsLength(); out.writeShort(tagsLength); if (tagsLength > 0) { PrivateCellUtil.writeTags(out, cell, tagsLength); } size += tagsLength + KeyValue.TAGS_LENGTH_SIZE; } if (encodingCtx.getHFileContext().isIncludesMvcc()) { WritableUtils.writeVLong(out, cell.getSequenceId()); size += WritableUtils.getVIntSize(cell.getSequenceId()); } return size; }
@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())); }
/** * Copy the Cell content into the passed buf in KeyValue serialization format. */ public static int appendTo(Cell cell, ByteBuffer buf, int offset, boolean withTags) { offset = ByteBufferUtils.putInt(buf, offset, keyLength(cell));// Key length offset = ByteBufferUtils.putInt(buf, offset, cell.getValueLength());// Value length offset = appendKeyTo(cell, buf, offset); offset = CellUtil.copyValueTo(cell, buf, offset);// Value bytes int tagsLength = cell.getTagsLength(); if (withTags && (tagsLength > 0)) { offset = ByteBufferUtils.putAsShort(buf, offset, tagsLength);// Tags length offset = PrivateCellUtil.copyTagsTo(cell, buf, offset);// Tags bytes } return offset; }
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(); }
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; }