Skip to content

Instantly share code, notes, and snippets.

@xstevens
Last active December 12, 2015 08:09
Show Gist options
  • Save xstevens/4742126 to your computer and use it in GitHub Desktop.
Save xstevens/4742126 to your computer and use it in GitHub Desktop.
Snippet for creating an hbase shell compatible ID from a UUID and given date. Modify to suit your needs.
public static String hbaseShellId(String id, Date d) throws IOException {
byte[] idBytes = IdUtil.nonRandByteBucketizeId(id, d);
StringBuilder sb = new StringBuilder("\"\\x");
sb.append(String.format("%02x", idBytes[0]));
sb.append((new String(idBytes)).substring(1));
sb.append("\"");
return sb.toString();
}
public static void main(String[] args) throws IOException {
String id = UUID.randomUUID().toString();
Calendar cal = Calendar.getInstance();
cal.set(2013, Calendar.FEBRUARY, 8);
System.out.println(IdUtil.hbaseShellId(id, cal.getTime()));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment