Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I insert a row with a TimeUUIDType column in Cassandra?

In Cassandra, I have the following Column Family:

<ColumnFamily CompareWith="TimeUUIDType" Name="Posts"/>

I'm trying to insert a record into it as follows using a C++ generated function generated by Thrift:

ColumnPath new_col;
new_col.__isset.column = true; /* this is required! */
new_col.column_family.assign("Posts");
new_col.super_column.assign("");
new_col.column.assign("1968ec4a-2a73-11df-9aca-00012e27a270");
client.insert("Keyspace1", "somekey", new_col, "Random Value", 1234, ONE);

However, I'm getting the following error: "UUIDs must be exactly 16 bytes"

I've even tried the Cassandra CLI with the following command:

set Keyspace1.Posts['somekey']['1968ec4a-2a73-11df-9aca-00012e27a270'] = 'Random Value'

but I still get the following error:

Exception null
InvalidRequestException(why:UUIDs must be exactly 16 bytes)
 at org.apache.cassandra.thrift.Cassandra$insert_result.read(Cassandra.java:11994)
 at org.apache.cassandra.thrift.Cassandra$Client.recv_insert(Cassandra.java:659)
 at org.apache.cassandra.thrift.Cassandra$Client.insert(Cassandra.java:632)
 at org.apache.cassandra.cli.CliClient.executeSet(CliClient.java:420)
 at org.apache.cassandra.cli.CliClient.executeCLIStmt(CliClient.java:80)
 at org.apache.cassandra.cli.CliMain.processCLIStmt(CliMain.java:132)
 at org.apache.cassandra.cli.CliMain.main(CliMain.java:173)
like image 515
mixmasteralan Avatar asked Mar 08 '10 07:03

mixmasteralan


People also ask

How do you add a Timeuuid in Cassandra?

In Cassandra Query Language now() function can be used for UTC (Universal Time) standard. Now() method is useful to insert value which is guaranteed to be unique. To insert the current time as a value then we can use timeuuid functions now() and dateof().

Which command would you use to add new columns to a table schema in Cassandra?

The ALTER TABLE command can be used to add new columns to a table and to alter the column type of an existing column.

How do I add a column to an existing Cassandra table?

You can add a column in the table by using the ALTER command. While adding column, you have to aware that the column name is not conflicting with the existing column names and that the table is not defined with compact storage option.


1 Answers

Thrift is a binary protocol; 16 bytes means 16 bytes. "1968ec4a-2a73-11df-9aca-00012e27a270" is 36 bytes. You need to get your library to give you the raw, 16 bytes form.

I don't use C++ myself, but "version 1 uuid" is the magic string you want to google for when looking for a library that can do this. http://www.google.com/search?q=C%2B%2B+version+1+uuid

like image 194
jbellis Avatar answered Sep 28 '22 06:09

jbellis