0
votes

I am trying to have a column family that I can have a key for one CQL to get a row based on a key and another CQL to where I have a list of keys using the "IN" keyword and have an ORDER BY clause. The data I am getting is from the Column value not the Column Name. The issue I am having is trying to setup the column family to achieve this. I have this cli command to create the column family but when I go do an insert I get a odd exception about the Primary key. Below is the cli and the error when doing the insert of column values after the column family was created.

The cli command used to create the column family:

create column family video_item_details 
with key_validation_class = 'CompositeType(IntegerType,UTF8Type)'
and comparator = 'UTF8Type'
and column_metadata = [
{column_name : key, validation_class: IntegerType, index_type: KEYS}
{column_name : name, validation_class : 'UTF8Type', index_type: KEYS}
{column_name : description, validation_class :'UTF8Type'}
{column_name : url, validation_class : 'UTF8Type'}
{column_name : play_time, validation_class : 'UTF8Type'}
{column_name : type, validation_class : 'UTF8Type'}
]
with caching='ALL';

the error during insert is:

Error while inserting com.datastax.driver.core.exceptions.InvalidQueryException: Missing mandatory PRIMARY KEY part key2

The insert statement that was being attempted to be executed was:

INSERT INTO video.video_item_details(key, name, description, url, play_time, type) values
(1,'Gettysburg','Gettysburg Movie Trailer','test','2:53','Streaming')

Thanks for any advice on how to get Cassandra to do this type of query.

Best Regards, -Tony

2

2 Answers

3
votes

The DataStax Java driver which you seem to be using supports only CQL3 and to me it looks like you have defined the table using the Thrift API. Combining the 2 will lead you into issues like this one.

I've posted a set of links on this other SO question that covers the differences between the 2 interfaces.

0
votes

That message means you're missing the "key2" column (the second part of your CompositeType).

But like Alex told you, the right way to do this is to create the table from CQL [i.e., with cqlsh] as well instead of trying to mangle CompositeTypes manually. Anyone on "the Cassandra team" would tell you the same thing. Source: I am Apache Cassandra project chair and DataStax Cassandra team lead.