Last active
December 12, 2015 08:09
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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