本文整理了Java中org.apache.hadoop.hbase.KeyValue.write()
方法的一些代码示例,展示了KeyValue.write()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。KeyValue.write()
方法的具体详情如下:
包路径:org.apache.hadoop.hbase.KeyValue
类名称:KeyValue
方法名:write
[英]Write out a KeyValue in the manner in which we used to when KeyValue was a Writable.
[中]当KeyValue是可写的时,按照我们习惯的方式写出一个KeyValue。
代码示例来源:origin: apache/hbase
/**
* Write out a KeyValue in the manner in which we used to when KeyValue was a Writable but do
* not require a {@link DataOutput}, just take plain {@link OutputStream}
* Named <code>oswrite</code> so does not clash with {@link #write(KeyValue, DataOutput)}
* @param kv
* @param out
* @param withTags
* @return Length written on stream
* @throws IOException
* @see #create(DataInput) for the inverse function
* @see #write(KeyValue, DataOutput)
* @see KeyValueUtil#oswrite(Cell, OutputStream, boolean)
* @deprecated As of release 2.0.0, this will be removed in HBase 3.0.0.
* Instead use {@link #write(OutputStream, boolean)}
*/
@Deprecated
public static long oswrite(final KeyValue kv, final OutputStream out, final boolean withTags)
throws IOException {
ByteBufferUtils.putInt(out, kv.getSerializedSize(withTags));
return (long) kv.write(out, withTags) + Bytes.SIZEOF_INT;
}
代码示例来源:origin: apache/hive
@Override
public void write(final DataOutput out)
throws IOException {
ProtobufUtil.toResultNoData(result).writeDelimitedTo(DataOutputOutputStream.from(out));
out.writeInt(result.size());
for(Cell cell : result.listCells()) {
KeyValue kv = KeyValueUtil.ensureKeyValue(cell);
KeyValue.write(kv, out);
}
}
}
代码示例来源:origin: apache/hive
@Override
public void write(final DataOutput out)
throws IOException {
ProtobufUtil.toMutationNoData(MutationType.PUT, put).writeDelimitedTo(DataOutputOutputStream.from(out));
out.writeInt(put.size());
CellScanner scanner = put.cellScanner();
while(scanner.advance()) {
KeyValue kv = KeyValueUtil.ensureKeyValue(scanner.current());
KeyValue.write(kv, out);
}
}
}
代码示例来源:origin: apache/hbase
/**
* Verify KeyValue format related functions: write() and getSerializedSize().
* Should have the same behaviors as {@link KeyValue}.
*/
@Test
public void testWriteIntoKeyValueFormat() throws IOException {
// Verify getSerializedSize().
assertEquals(kv0.getSerializedSize(true), ic0.getSerializedSize(true)); // with tags
assertEquals(kv0.getSerializedSize(false), ic0.getSerializedSize(false)); // without tags
// Verify writing into ByteBuffer.
ByteBuffer bbufIC = ByteBuffer.allocate(ic0.getSerializedSize(true));
ic0.write(bbufIC, 0);
ByteBuffer bbufKV = ByteBuffer.allocate(kv0.getSerializedSize(true));
kv0.write(bbufKV, 0);
assertTrue(bbufIC.equals(bbufKV));
// Verify writing into OutputStream.
testWriteIntoOutputStream(ic0, kv0, true); // with tags
testWriteIntoOutputStream(ic0, kv0, false); // without tags
}
代码示例来源:origin: apache/hbase
/**
* @param ic An instance of IndividualBytesFieldCell to compare.
* @param kv An instance of KeyValue to compare.
* @param withTags Whether to write tags.
*/
private void testWriteIntoOutputStream(IndividualBytesFieldCell ic, KeyValue kv, boolean withTags)
throws IOException {
ByteArrayOutputStream outIC = new ByteArrayOutputStream(ic.getSerializedSize(withTags));
ByteArrayOutputStream outKV = new ByteArrayOutputStream(kv.getSerializedSize(withTags));
// compare the number of bytes written
assertEquals(kv.write(outKV, withTags), ic.write(outIC, withTags));
// compare the underlying byte array
assertArrayEquals(outKV.getBuffer(), outIC.getBuffer());
}
代码示例来源:origin: apache/phoenix
/**
* Write a {@link KeyValue} or an {@link IndexedKeyValue} to the output stream. These can be read
* back via {@link #readKeyValue(DataInput)} or {@link #readKeyValues(DataInput)}.
* @param out to write to
* @param kv {@link KeyValue} to which to write
* @throws IOException if there is an error writing
*/
public static void write(DataOutput out, KeyValue kv) throws IOException {
if (kv instanceof IndexedKeyValue) {
out.writeInt(INDEX_TYPE_LENGTH_MARKER);
((IndexedKeyValue) kv).writeData(out);
} else {
KeyValue.write(kv, out);
}
}
}
代码示例来源:origin: forcedotcom/phoenix
/**
* Write a {@link KeyValue} or an {@link IndexedKeyValue} to the output stream. These can be read
* back via {@link #readKeyValue(DataInput)} or {@link #readKeyValues(DataInput)}.
* @param out to write to
* @param kv {@link KeyValue} to which to write
* @throws IOException if there is an error writing
*/
public static void write(DataOutput out, KeyValue kv) throws IOException {
if (kv instanceof IndexedKeyValue) {
out.writeInt(INDEX_TYPE_LENGTH_MARKER);
((IndexedKeyValue) kv).writeData(out);
} else {
kv.write(out);
}
}
}
代码示例来源:origin: harbby/presto-connectors
@Override
public void serialize(KeyValue kv) throws IOException {
KeyValue.write(kv, this.dos);
}
}
代码示例来源:origin: org.apache.hbase/hbase-mapreduce
@Override
public void write(DataOutput out) throws IOException {
KeyValue.write(kv, out);
}
代码示例来源:origin: com.aliyun.hbase/alihbase-mapreduce
@Override
public void write(DataOutput out) throws IOException {
KeyValue.write(kv, out);
}
代码示例来源:origin: org.apache.crunch/crunch-hbase
public static BytesWritable keyValueToBytes(KeyValue kv) {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
DataOutputStream dos = new DataOutputStream(baos);
try {
KeyValue.write(kv, dos);
return new BytesWritable(baos.toByteArray());
} catch (Exception e) {
throw new CrunchRuntimeException(e);
}
}
代码示例来源:origin: apache/crunch
public static BytesWritable keyValueToBytes(KeyValue kv) {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
DataOutputStream dos = new DataOutputStream(baos);
try {
KeyValue.write(kv, dos);
return new BytesWritable(baos.toByteArray());
} catch (Exception e) {
throw new CrunchRuntimeException(e);
}
}
代码示例来源:origin: com.aliyun.phoenix/ali-phoenix-core
/**
* Write a {@link KeyValue} or an {@link IndexedKeyValue} to the output stream. These can be read
* back via {@link #readKeyValue(DataInput)} or {@link #readKeyValues(DataInput)}.
* @param out to write to
* @param kv {@link KeyValue} to which to write
* @throws IOException if there is an error writing
*/
public static void write(DataOutput out, KeyValue kv) throws IOException {
if (kv instanceof IndexedKeyValue) {
out.writeInt(INDEX_TYPE_LENGTH_MARKER);
((IndexedKeyValue) kv).writeData(out);
} else {
KeyValue.write(kv, out);
}
}
}
代码示例来源:origin: org.apache.phoenix/phoenix-core
/**
* Write a {@link KeyValue} or an {@link IndexedKeyValue} to the output stream. These can be read
* back via {@link #readKeyValue(DataInput)} or {@link #readKeyValues(DataInput)}.
* @param out to write to
* @param kv {@link KeyValue} to which to write
* @throws IOException if there is an error writing
*/
public static void write(DataOutput out, KeyValue kv) throws IOException {
if (kv instanceof IndexedKeyValue) {
out.writeInt(INDEX_TYPE_LENGTH_MARKER);
((IndexedKeyValue) kv).writeData(out);
} else {
KeyValue.write(kv, out);
}
}
}
代码示例来源:origin: co.cask.hbase/hbase
public void write(final DataOutput out) throws IOException {
out.writeByte(DELETE_VERSION);
Bytes.writeByteArray(out, this.row);
out.writeLong(this.ts);
out.writeLong(this.lockId);
out.writeBoolean(this.writeToWAL);
out.writeInt(familyMap.size());
for(Map.Entry<byte [], List<KeyValue>> entry : familyMap.entrySet()) {
Bytes.writeByteArray(out, entry.getKey());
List<KeyValue> list = entry.getValue();
out.writeInt(list.size());
for(KeyValue kv : list) {
kv.write(out);
}
}
writeAttributes(out);
}
}
代码示例来源:origin: com.github.hyukjinkwon/hive-hbase-handler
@Override
public void write(final DataOutput out)
throws IOException {
ProtobufUtil.toResultNoData(result).writeDelimitedTo(DataOutputOutputStream.from(out));
out.writeInt(result.size());
for(KeyValue kv : result.list()) {
KeyValue.write(kv, out);
}
}
代码示例来源:origin: forcedotcom/phoenix
private void validate(KeyValue kv, byte[] row, byte[] family, byte[] qualifier, long ts,
Type type, byte[] value) throws IOException {
DataOutputBuffer out = new DataOutputBuffer();
kv.write(out);
out.close();
byte[] data = out.getData();
// read it back in
KeyValue read = new KeyValue();
DataInputBuffer in = new DataInputBuffer();
in.reset(data, data.length);
read.readFields(in);
in.close();
// validate that its the same
assertTrue("Row didn't match!", Bytes.equals(row, read.getRow()));
assertTrue("Family didn't match!", Bytes.equals(family, read.getFamily()));
assertTrue("Qualifier didn't match!", Bytes.equals(qualifier, read.getQualifier()));
assertTrue("Value didn't match!", Bytes.equals(value, read.getValue()));
assertEquals("Timestamp didn't match", ts, read.getTimestamp());
assertEquals("Type didn't match", type.getCode(), read.getType());
}
代码示例来源:origin: com.github.hyukjinkwon/hive-hbase-handler
@Override
public void write(final DataOutput out)
throws IOException {
ProtobufUtil.toMutationNoData(MutationType.PUT, put).writeDelimitedTo(DataOutputOutputStream.from(out));
out.writeInt(put.size());
CellScanner scanner = put.cellScanner();
while(scanner.advance()) {
KeyValue kv = KeyValueUtil.ensureKeyValue(scanner.current());
KeyValue.write(kv, out);
}
}
}
代码示例来源:origin: org.apache.hbase/hbase-common
/**
* @param ic An instance of IndividualBytesFieldCell to compare.
* @param kv An instance of KeyValue to compare.
* @param withTags Whether to write tags.
*/
private void testWriteIntoOutputStream(IndividualBytesFieldCell ic, KeyValue kv, boolean withTags)
throws IOException {
ByteArrayOutputStream outIC = new ByteArrayOutputStream(ic.getSerializedSize(withTags));
ByteArrayOutputStream outKV = new ByteArrayOutputStream(kv.getSerializedSize(withTags));
// compare the number of bytes written
assertEquals(kv.write(outKV, withTags), ic.write(outIC, withTags));
// compare the underlying byte array
assertArrayEquals(outKV.getBuffer(), outIC.getBuffer());
}
代码示例来源:origin: com.aliyun.hbase/alihbase-common
/**
* @param ic An instance of IndividualBytesFieldCell to compare.
* @param kv An instance of KeyValue to compare.
* @param withTags Whether to write tags.
*/
private void testWriteIntoOutputStream(IndividualBytesFieldCell ic, KeyValue kv, boolean withTags)
throws IOException {
ByteArrayOutputStream outIC = new ByteArrayOutputStream(ic.getSerializedSize(withTags));
ByteArrayOutputStream outKV = new ByteArrayOutputStream(kv.getSerializedSize(withTags));
// compare the number of bytes written
assertEquals(kv.write(outKV, withTags), ic.write(outIC, withTags));
// compare the underlying byte array
assertArrayEquals(outKV.getBuffer(), outIC.getBuffer());
}
内容来源于网络,如有侵权,请联系作者删除!