Mapping Cassandra Super Columns

5.7k views Asked by At

I guess everybody that played with Cassandra already read this article.

I trying to create my schema on CassandraCli, but I am having a lot of problems, can someone guide me to the right way? I am trying to create a similar structure like the Comments column family from the article.

In CassandraCli terminal I type:

create column family posts with column_type = ‘Super’ and comparator = ‘AsciiType’ and subcomparator = TimeUUIDType;

It works fine, there is no doc telling me that if I add a column_metadata attribute those will be for the super columns cause my column family is of type super, i can’t find if it is true so:

create column family posts with column_type = ‘Super’ and comparator = ‘AsciiType’ and subcomparator = ‘TimeUUIDType’ and column_metadata = [{column_name:'body'}];

I am trying to create the same as the comment column family of the article, but when i try to populate

set posts['post1'][timeuuid()][body] = ‘Hello I am Goku!’;

i got:

Invalid UUID string: body

I guess because i chose the subcomparator be of type timeuuid and the body is a string, it should be a timeuuid, so HOW my columns inside the super column which is the type timeuuid could holds columns with string type names as the comments of the article are created?

Thanks

4

There are 4 answers

0
gustavoboby On

set posts[1][timeuuid()][utf8('body')] = 'Hello I am Goku!';

The correct answer shall be that.

:p

0
yfeldblum On

Did you try quoting 'body'?

set posts['post1'][timeuuid()]['body'] = ‘Hello I am Goku!’;
0
Tyler Hobbs On

I think you switched what comparator_type and subcomparator_type apply to. In super column families, comparator_type applies to the super column names, and subcombparator_type applies to the subcolumn names.

Switch the comparator types and your first example should work.

0
aletapool On

I tried:

set posts[1][timeuuid()]['body'] = 'Hello I am Goku!';

it worked...