org.apache.hadoop.hbase.Cell.getTagsLength()方法的使用及代码示例

x33g5p2x  于2022-01-18 转载在 其他  
字(10.9k)|赞(0)|评价(0)|浏览(153)

本文整理了Java中org.apache.hadoop.hbase.Cell.getTagsLength()方法的一些代码示例,展示了Cell.getTagsLength()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Cell.getTagsLength()方法的具体详情如下:
包路径:org.apache.hadoop.hbase.Cell
类名称:Cell
方法名:getTagsLength

Cell.getTagsLength介绍

[英]HBase internally uses 2 bytes to store tags length in Cell. As the tags length is always a non-negative number, to make good use of the sign bit, the max of tags length is defined 2 * Short.MAX_VALUE + 1 = 65535. As a result, the return type is int, because a short is not capable of handling that. Please note that even if the return type is int, the max tags length is far less than Integer.MAX_VALUE.
[中]HBase在内部使用2个字节在单元中存储标记长度。由于标签长度始终为非负数,为了充分利用符号位,标签长度的最大值定义为2*短。最大值+1=65535。因此,返回类型为int,因为short无法处理该类型。请注意,即使返回类型为int,max tags length也远小于Integer。最大值。

代码示例

代码示例来源:origin: apache/hbase

@Override
public int getTagsLength() {
 return this.cell.getTagsLength();
}

代码示例来源:origin: apache/hbase

@Override
public int getTagsLength() {
 return cell.getTagsLength();
}

代码示例来源:origin: apache/hbase

public static byte[] cloneTags(Cell cell) {
 byte[] output = new byte[cell.getTagsLength()];
 copyTagsTo(cell, output, 0);
 return output;
}

代码示例来源:origin: apache/hbase

/**
 * 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;
}

代码示例来源:origin: apache/hbase

/**
 * 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;
}

代码示例来源:origin: apache/hbase

public static ByteRange fillTagRange(Cell cell, ByteRange range) {
 return range.set(cell.getTagsArray(), cell.getTagsOffset(), cell.getTagsLength());
}

代码示例来源:origin: apache/hbase

/**
 * 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());
 }
}

代码示例来源:origin: apache/hbase

/**
 * 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());
}

代码示例来源:origin: apache/hbase

/**************** 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;
}

代码示例来源:origin: apache/hbase

/**
 * 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;
}

代码示例来源:origin: apache/hbase

/**
 * 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());
}

代码示例来源:origin: apache/hbase

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;
}

代码示例来源:origin: apache/hbase

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);
}

代码示例来源:origin: apache/hbase

/**
 * 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;
}

代码示例来源:origin: apache/hbase

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;
}

代码示例来源:origin: apache/hbase

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;
}

代码示例来源:origin: apache/hbase

@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()));
}

代码示例来源:origin: apache/hbase

/**
 * 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;
}

代码示例来源:origin: apache/hbase

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();
}

代码示例来源:origin: apache/nifi

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;
}

相关文章