Skip to content

Instantly share code, notes, and snippets.

@sujee
Created August 27, 2011 00:21
Show Gist options
  • Save sujee/1174761 to your computer and use it in GitHub Desktop.
Save sujee/1174761 to your computer and use it in GitHub Desktop.
HBase utilities : Bytes.add
// ---------- Bytes.add() : creating composite keys ---------
// rowkey = int + long
int i = 0;
long timestamp = System.currentTimeMillis();
byte [] rowkey2 = Bytes.add(Bytes.toBytes(i), Bytes.toBytes(timestamp));
System.out.println ("rowkey2 (" + rowkey2.length + ") : " + Arrays.toString(rowkey2));
// add also supports adding 3 byte arrays
// rowkey = int + str + long
byte[] rowkey3 = Bytes.add(Bytes.toBytes(0) , Bytes.toBytes("hello"), Bytes.toBytes(timestamp));
System.out.println ("rowkey3 (" + rowkey3.length + ") : " + Arrays.toString(rowkey3));
/* output:
rowkey2 (12) : [0, 0, 0, 0, 0, 0, 1, 50, 8, -101, 99, -41]
rowkey3 (17) : [0, 0, 0, 0, 104, 101, 108, 108, 111, 0, 0, 1, 50, 8, -101, 99, -41]
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment