@Override public String toString() { return Objects.toStringHelper(this.getClass()) .add("Prefix", String.format("%02X", PREFIX)) .add("TableId", tableId) .add("UUID", uuid == null ? "" : Util.generateHexString(Util.UUIDToBytes(uuid))) .toString(); }
@Override public String toString() { return Objects.toStringHelper(this.getClass()) .add("Prefix", String.format("%02X", prefix)) .add("TableId", tableId) .add("IndexId", indexId) .add("Records", records == null ? "" : recordValueStrings()) .add("UUID", uuid == null ? "" : Util.generateHexString(Util.UUIDToBytes(uuid))) .toString(); }
/** * Set UUID to a new random UUID */ public void setRandomUUID() { row.setUuid(new UUIDContainer(Util.UUIDToBytes(UUID.randomUUID()))); }
@Override public byte[] encode() { final byte[] prefixBytes = {prefix}; final List<byte[]> encodedParts = Lists.newArrayList(); encodedParts.add(prefixBytes); encodedParts.add(VarEncoder.encodeULong(tableId)); encodedParts.add(VarEncoder.encodeULong(indexId)); if (records != null) { for (final byte[] record : records) { if (record == null) { encodedParts.add(nullBytes); } else { encodedParts.add(notNullBytes); encodedParts.add(record); } } if (uuid != null) { encodedParts.add(Util.UUIDToBytes(uuid)); } } return VarEncoder.appendByteArrays(encodedParts); }
public void setUUID(UUID uuid) { row.setUuid(new UUIDContainer(Util.UUIDToBytes(uuid))); }
@Override public int compareTo(RowKey o) { int typeCompare = getPrefix() - o.getPrefix(); if (typeCompare != 0) { return typeCompare; } DataRowKey row2 = (DataRowKey) o; return ComparisonChain.start() .compare(getTableId(), row2.getTableId()) .compare(Util.UUIDToBytes(getUuid()), Util.UUIDToBytes(row2.getUuid()), new Bytes.ByteArrayComparator()) .result(); } }
} else { return new Bytes.ByteArrayComparator().compare( Util.UUIDToBytes(uuid), Util.UUIDToBytes(row2.uuid));
@Override public byte[] encode() { if( uuid != null ) { return VarEncoder.appendByteArraysWithPrefix(PREFIX, VarEncoder.encodeULong(tableId), Util.UUIDToBytes(uuid)); } return VarEncoder.appendByteArraysWithPrefix(PREFIX, VarEncoder.encodeULong(tableId)); }
/** * Construct a new Row with specified records and UUID. * * @param records Map of column name to record value * @param uuid UUID representing the unique position of the Row */ public Row(Map<String, ByteBuffer> records, UUID uuid) { checkNotNull(records, "records must not be null."); // uuid nullity will be checked by UUIDToBytes row = AvroRow.newBuilder() .setUuid(new UUIDContainer(Util.UUIDToBytes(uuid))) .setRecords(records) .build(); }
@Test public void testUUIDBytes() throws Exception { for (UUID uuid : Iterables.toIterable(new UUIDGenerator())) { Assert.assertEquals(uuid, Util.bytesToUUID(Util.UUIDToBytes(uuid))); } } }