14. A case for TypedTable
Put p = new Put(Bytes.toBytes(u.user));
p.add(INFO_FAM, USER_COL, Bytes.toBytes(u.user));
p.add(INFO_FAM, NAME_COL, Bytes.toBytes(u.name));
p.add(INFO_FAM, EMAIL_COL, Bytes.toBytes(u.email));
p.add(INFO_FAM, PASS_COL, Bytes.toBytes(u.password));
Licensed
under
a
Crea3ve
Commons
A8ribu3on-‐ShareAlike
3.0
Unported
License.
2014-‐11-‐18
14
15. A case for TypedTable!
static final RawString ENC_STR = new RawString();!
static final RawLong ENC_LONG = new RawLong();!
--!
!
SimplePositionedByteRange pbr =!
new SimplePositionedByteRange(100);!
ENC_STR.encode(pbr, u.user);!
Put p = new Put(Bytes.copy(pbr.getBytes(), pbr.getOffset(),
pbr.getPosition()));!
p.add(INFO_FAM, USER_COL, Bytes.copy(pbr.getBytes(), ...);!
pbr.setPosition(0);!
ENC_STR.encode(pbr, u.name);!
p.add(INFO_FAM, NAME_COL, Bytes.copy(pbr.getBytes(), ...);!
...!
2014-‐11-‐18
15
Licensed
under
a
Crea3ve
Commons
A8ribu3on-‐ShareAlike
3.0
Unported
License.
16. Structs: writing
!
!
!
Struct struct = new StructBuilder()!
.add(OrderedNumeric.ASCENDING)!
.add(OrderedString.ASCENDING)!
.toStruct();!
PositionedByteRange buf1 =!
new SimplePositionedByteRange(7);!
struct.encode(buf1,!
new Object[] { BigDecimal.ONE, "foo" });!
!
Licensed
under
a
Crea3ve
Commons
A8ribu3on-‐ShareAlike
3.0
Unported
License.
2014-‐11-‐18
16
17. Structs: reading
!
!
!
!
buf1.setPosition(0);!
StructIterator it = longer.iterator(buf1);!
while (it.hasNext()) {!
System.out.print(it.next() + ", ");!
}!
!
> BigDecimal.ONE, foo!
Licensed
under
a
Crea3ve
Commons
A8ribu3on-‐ShareAlike
3.0
Unported
License.
2014-‐11-‐18
17
18. Structs: schema migration
Struct addedFields = new StructBuilder()!
.add(OrderedNumeric.ASCENDING)!
.add(OrderedString.ASCENDING)!
.add(OrderedString.ASCENDING)!
.add(OrderedNumeric.ASCENDING)!
.toStruct();!
!
buf1.setPosition(0);!
StructIterator it = longer.iterator(buf1);!
while (it.hasNext()) {!
System.out.print(it.next() + ", ");!
}!
> BigDecimal.ONE, foo, null, null!
!2014-‐11-‐18
18
Licensed
under
a
Crea3ve
Commons
A8ribu3on-‐ShareAlike
3.0
Unported
License.
19. Protobuf (HBASE-11161)
!
class PBKeyValue extends PBType<CellProtos.KeyValue> {!
!
@Override!
public int encode(PositionedByteRange dst, KeyValue val) {!
CodedOutputStream os = outputStreamFromByteRange(dst);!
int before = os.spaceLeft(), after, written;!
val.writeTo(os);!
after = os.spaceLeft();!
written = before - after;!
dst.setPosition(dst.getPosition() + written);!
return written;!
}!
2014-‐11-‐18
19
Licensed
under
a
Crea3ve
Commons
A8ribu3on-‐ShareAlike
3.0
Unported
License.
21. Thanks!
M A N N I N G
Nick Dimiduk
Amandeep Khurana
FOREWORD BY
Michael Stack
hbaseinaction.com
Nick Dimiduk
github.com/ndimiduk
@xefyr
n10k.com
http://s.apache.org/bGN
Licensed
under
a
Crea3ve
Commons
A8ribu3on-‐ShareAlike
3.0
Unported
License.
2014-‐11-‐18
21