本文整理了Java中org.apache.hadoop.hbase.Cell.getValueArray()
方法的一些代码示例,展示了Cell.getValueArray()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Cell.getValueArray()
方法的具体详情如下:
包路径:org.apache.hadoop.hbase.Cell
类名称:Cell
方法名:getValueArray
[英]Contiguous raw bytes that may start at any index in the containing array. Max length is Integer.MAX_VALUE which is 2,147,483,647 bytes.
[中]可以从包含数组中的任何索引开始的连续原始字节。最大长度是整数。最大值为2147483647字节。
代码示例来源:origin: apache/hbase
public static ByteBuffer getValueBufferShallowCopy(Cell cell) {
ByteBuffer buffer =
ByteBuffer.wrap(cell.getValueArray(), cell.getValueOffset(), cell.getValueLength());
return buffer;
}
代码示例来源:origin: apache/kylin
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++;
}
代码示例来源: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
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);
}
代码示例来源: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
assertTrue(cell0.getQualifierArray() == qualifier0);
assertTrue(cell0.getValueArray() == value0);
assertTrue(cell1.getQualifierArray() == qualifier1);
assertTrue(cell1.getValueArray() == value1);
代码示例来源:origin: apache/kylin
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;
}
代码示例来源: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
@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
/**
* 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 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;
}
}
代码示例来源:origin: apache/hbase
public static ByteRange fillValueRange(Cell cell, ByteRange range) {
return range.set(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
/**
* 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/kylin
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()));
}
代码示例来源:origin: apache/hbase
private static long getReplicationBarrier(Cell c) {
return Bytes.toLong(c.getValueArray(), c.getValueOffset(), c.getValueLength());
}
代码示例来源: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());
}
代码示例来源: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
@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()));
}
代码示例来源: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();
}
内容来源于网络,如有侵权,请联系作者删除!