This list is for the development of Cassandra directly, your question is better posed on u...@cassandra.apache.org (moving it there).
Before following up though, you might want to check the wiki and list archives, questions about creating TimeUUIDs from Java have been pretty common. For example: http://wiki.apache.org/cassandra/FAQ#working_with_timeuuid_in_java On Thu, 2010-10-14 at 11:34 -0700, Wicked J wrote: > Hi, > I'm having issues with inserting data of TimeUUIDType in Cassandra v0.6.4. > The exception that I'm getting is: *InvalidRequestException(why:UUIDs must > be exactly 16 bytes)* > > My objective is I want to insert comments and retrieve them in the order > they were inserted. My storage-conf.xml and code snippets are mentioned > below. Seems like the method "insert" in Cassandra.Client takes a String as > the id and in my case this value is actually a UUID and in the process of > converting the UUID (though 16 bytes in size) to String, the string value is > larger than 16 bytes which is causing the exception. My question is how do I > insert an UUID value as String without violating the 16 bytes limit in a > column family? Or any other ideas? Any help is sincerely appreciated. > > *Storage-Conf.xml Snippet:* > > .. > <ColumnFamily CompareWith="TimeUUIDType" Name="Comments"/> > .. > > *Code Example:* > > public class AddComment { > > public static final String ENCODING = "utf-8"; > private static final String KEYSPACE = "blog"; > private static final String COLUMN_FAMILY = "Comments"; > private static TTransport cassandraTransport = null; > > public static void main(String args[]) throws Exception { > Cassandra.Client client = setupConnection(); > UUID *uid1* = AddComment.getTimeUUID(); > byte[] *uidByteArray1* = AddComment.asByteArray(uid1); > add(client, *String.valueOf(uidByteArray1)*, "Testing insertion > comment order"); > closeConnection(); > } > > private static void add(Cassandra.Client client, String id, String > comment) { > try { > ColumnPath colPathname = new ColumnPath(COLUMN_FAMILY); > colPathname.setColumn("comment".getBytes(ENCODING)); > client.*insert*(KEYSPACE, *id*, colPathname, > comment.getBytes(ENCODING), System.currentTimeMillis(), > ConsistencyLevel.ONE); > } catch (Exception exception) { > exception.printStackTrace(); > } > } > > * //From Cassandra FAQ Wiki* > public static byte[] asByteArray(java.util.UUID uuid) { > long msb = uuid.getMostSignificantBits(); > long lsb = uuid.getLeastSignificantBits(); > byte[] buffer = new byte[16]; > > for (int i = 0; i < 8; i++) { > buffer[i] = (byte) (msb >>> 8 * (7 - i)); > } > for (int i = 8; i < 16; i++) { > buffer[i] = (byte) (lsb >>> 8 * (7 - i)); > } > > return buffer; > } > > * //From Cassandra FAQ Wiki* > public static java.util.UUID getTimeUUID() { > return java.util.UUID.fromString(new > com.eaio.uuid.UUID().toString()); > } > > private static Cassandra.Client setupConnection() throws > TTransportException { > try { > cassandraTransport = new TSocket("localhost", 9160); > TProtocol proto = new TBinaryProtocol(cassandraTransport); > Cassandra.Client client = new Cassandra.Client(proto); > cassandraTransport.open(); > return client; > } catch (TTransportException exception) { > exception.printStackTrace(); > } > return null; > } > > private static void closeConnection() { > try { > cassandraTransport.flush(); > cassandraTransport.close(); > } catch (TTransportException exception) { > exception.printStackTrace(); > } > } > > } -- Eric Evans eev...@rackspace.com