Return-Path: Delivered-To: apmail-cassandra-user-archive@www.apache.org Received: (qmail 90880 invoked from network); 14 Oct 2010 18:41:18 -0000 Received: from unknown (HELO mail.apache.org) (140.211.11.3) by 140.211.11.9 with SMTP; 14 Oct 2010 18:41:18 -0000 Received: (qmail 78140 invoked by uid 500); 14 Oct 2010 18:41:15 -0000 Delivered-To: apmail-cassandra-user-archive@cassandra.apache.org Received: (qmail 78073 invoked by uid 500); 14 Oct 2010 18:41:15 -0000 Mailing-List: contact user-help@cassandra.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: user@cassandra.apache.org Delivered-To: mailing list user@cassandra.apache.org Received: (qmail 78058 invoked by uid 99); 14 Oct 2010 18:41:15 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 14 Oct 2010 18:41:15 +0000 X-ASF-Spam-Status: No, hits=0.7 required=10.0 tests=SPF_NEUTRAL X-Spam-Check-By: apache.org Received-SPF: neutral (nike.apache.org: local policy) Received: from [67.192.241.151] (HELO smtp151.dfw.emailsrvr.com) (67.192.241.151) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 14 Oct 2010 18:41:08 +0000 Received: from localhost (localhost.localdomain [127.0.0.1]) by smtp5.relay.dfw1a.emailsrvr.com (SMTP Server) with ESMTP id E470258B02; Thu, 14 Oct 2010 14:40:47 -0400 (EDT) X-Orig-To: dev@cassandra.apache.org X-Orig-To: user@cassandra.apache.org X-Orig-To: wickedj2010@gmail.com X-Virus-Scanned: OK Received: by smtp5.relay.dfw1a.emailsrvr.com (Authenticated sender: eevans-AT-racklabs.com) with ESMTPSA id 7A9E65854E; Thu, 14 Oct 2010 14:40:47 -0400 (EDT) Subject: Re: Need help to overcome: InvalidRequestException(why:UUIDs must be exactly 16 bytes) From: Eric Evans Reply-To: user@cassandra.apache.org To: dev@cassandra.apache.org Cc: Wicked J , user@cassandra.apache.org In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" Date: Thu, 14 Oct 2010 13:42:21 -0500 Message-ID: <1287081741.10982.50.camel@erebus.lan> Mime-Version: 1.0 X-Mailer: Evolution 2.30.3 Content-Transfer-Encoding: 7bit X-Virus-Checked: Checked by ClamAV on apache.org This list is for the development of Cassandra directly, your question is better posed on user@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:* > > .. > > .. > > *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 eevans@rackspace.com