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

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

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

Cell.getValueOffset介绍

暂无

代码示例

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

public static ByteBuffer getValueBufferShallowCopy(Cell cell) {
 ByteBuffer buffer =
   ByteBuffer.wrap(cell.getValueArray(), cell.getValueOffset(), cell.getValueLength());
 return buffer;
}

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

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

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

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

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

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

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

public static ByteRange fillValueRange(Cell cell, ByteRange range) {
 return range.set(cell.getValueArray(), cell.getValueOffset(), cell.getValueLength());
}

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

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

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

private static long getReplicationBarrier(Cell c) {
 return Bytes.toLong(c.getValueArray(), c.getValueOffset(), c.getValueLength());
}

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

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

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

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

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

public static boolean matchingValue(final Cell left, final Cell right, int lvlength,
  int rvlength) {
 if (left instanceof ByteBufferExtendedCell && right instanceof ByteBufferExtendedCell) {
  return ByteBufferUtils.equals(((ByteBufferExtendedCell) left).getValueByteBuffer(),
   ((ByteBufferExtendedCell) left).getValuePosition(), lvlength,
   ((ByteBufferExtendedCell) right).getValueByteBuffer(),
   ((ByteBufferExtendedCell) right).getValuePosition(), rvlength);
 }
 if (left instanceof ByteBufferExtendedCell) {
  return ByteBufferUtils.equals(((ByteBufferExtendedCell) left).getValueByteBuffer(),
   ((ByteBufferExtendedCell) left).getValuePosition(), lvlength, right.getValueArray(),
   right.getValueOffset(), rvlength);
 }
 if (right instanceof ByteBufferExtendedCell) {
  return ByteBufferUtils.equals(((ByteBufferExtendedCell) right).getValueByteBuffer(),
   ((ByteBufferExtendedCell) right).getValuePosition(), rvlength, left.getValueArray(),
   left.getValueOffset(), lvlength);
 }
 return Bytes.equals(left.getValueArray(), left.getValueOffset(), lvlength,
  right.getValueArray(), right.getValueOffset(), rvlength);
}

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

private static Optional<TableState> getTableState(Result r) throws IOException {
 Cell cell = r.getColumnLatestCell(getTableFamily(), getStateColumn());
 if (cell == null) return Optional.empty();
 try {
  return Optional.of(TableState.parseFrom(
   TableName.valueOf(r.getRow()),
   Arrays.copyOfRange(cell.getValueArray(), cell.getValueOffset(), cell.getValueOffset()
     + cell.getValueLength())));
 } catch (DeserializationException e) {
  throw new IOException("Failed to parse table state from result: " + r, e);
 }
}

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

public static boolean matchingValue(final Cell left, final Cell right, int lvlength,
  int rvlength) {
 if (left instanceof ByteBufferExtendedCell && right instanceof ByteBufferExtendedCell) {
  return ByteBufferUtils.equals(((ByteBufferExtendedCell) left).getValueByteBuffer(),
    ((ByteBufferExtendedCell) left).getValuePosition(), lvlength,
    ((ByteBufferExtendedCell) right).getValueByteBuffer(),
    ((ByteBufferExtendedCell) right).getValuePosition(), rvlength);
 }
 if (left instanceof ByteBufferExtendedCell) {
  return ByteBufferUtils.equals(((ByteBufferExtendedCell) left).getValueByteBuffer(),
    ((ByteBufferExtendedCell) left).getValuePosition(), lvlength, right.getValueArray(),
    right.getValueOffset(), rvlength);
 }
 if (right instanceof ByteBufferExtendedCell) {
  return ByteBufferUtils.equals(((ByteBufferExtendedCell) right).getValueByteBuffer(),
    ((ByteBufferExtendedCell) right).getValuePosition(), rvlength, left.getValueArray(),
    left.getValueOffset(), lvlength);
 }
 return Bytes
   .equals(left.getValueArray(), left.getValueOffset(), lvlength, right.getValueArray(),
     right.getValueOffset(), rvlength);
}

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

@Override
public WALItem next() {
 Result next = it.next();
 List<Cell> cells = next.listCells();
 byte[] buf = cells.get(0).getValueArray();
 int len = cells.get(0).getValueLength();
 int offset = cells.get(0).getValueOffset();
 String backupId = new String(buf, offset, len);
 buf = cells.get(1).getValueArray();
 len = cells.get(1).getValueLength();
 offset = cells.get(1).getValueOffset();
 String walFile = new String(buf, offset, len);
 buf = cells.get(2).getValueArray();
 len = cells.get(2).getValueLength();
 offset = cells.get(2).getValueOffset();
 String backupRoot = new String(buf, offset, len);
 return new WALItem(backupId, walFile, backupRoot);
}

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

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

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

/**
 * Returns the value wrapped in a new <code>ByteBuffer</code>.
 *
 * @param family family name
 * @param foffset family offset
 * @param flength family length
 * @param qualifier column qualifier
 * @param qoffset qualifier offset
 * @param qlength qualifier length
 *
 * @return the latest version of the column, or <code>null</code> if none found
 */
public ByteBuffer getValueAsByteBuffer(byte [] family, int foffset, int flength,
  byte [] qualifier, int qoffset, int qlength) {
 Cell kv = getColumnLatestCell(family, foffset, flength, qualifier, qoffset, qlength);
 if (kv == null) {
  return null;
 }
 return ByteBuffer.wrap(kv.getValueArray(), kv.getValueOffset(), kv.getValueLength()).
  asReadOnlyBuffer();
}

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

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

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

/**
 * Returns the RegionInfo object from the column {@link HConstants#CATALOG_FAMILY} and
 * <code>qualifier</code> of the catalog table result.
 * @param r a Result object from the catalog table scan
 * @param qualifier Column family qualifier
 * @return An RegionInfo instance.
 */
private static Optional<RegionInfo> getHRegionInfo(final Result r, byte[] qualifier) {
 Cell cell = r.getColumnLatestCell(getCatalogFamily(), qualifier);
 if (cell == null) return Optional.empty();
 return Optional.ofNullable(RegionInfo.parseFromOrNull(cell.getValueArray(),
  cell.getValueOffset(), cell.getValueLength()));
}

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

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

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

/**
 * Loads the latest version of the specified column into the provided <code>ByteBuffer</code>.
 * <p>
 * Does not clear or flip the buffer.
 *
 * @param family family name
 * @param foffset family offset
 * @param flength family length
 * @param qualifier column qualifier
 * @param qoffset qualifier offset
 * @param qlength qualifier length
 * @param dst the buffer where to write the value
 *
 * @return <code>true</code> if a value was found, <code>false</code> otherwise
 *
 * @throws BufferOverflowException there is insufficient space remaining in the buffer
 */
public boolean loadValue(byte [] family, int foffset, int flength,
  byte [] qualifier, int qoffset, int qlength, ByteBuffer dst)
    throws BufferOverflowException {
 Cell kv = getColumnLatestCell(family, foffset, flength, qualifier, qoffset, qlength);
 if (kv == null) {
  return false;
 }
 dst.put(kv.getValueArray(), kv.getValueOffset(), kv.getValueLength());
 return true;
}

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

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

相关文章