Pergunta

I am trying to create a column family in Cassandra CLI Version 1.1.6, I am not sure how to specify primary key as movieid.

CREATE COLUMN FAMILY movies
WITH comparator = UTF8Type
AND key_validation_class=UTF8Type
AND column_metadata = [
{column_name: movieid, validation_class: UTF8Type}
{column_name: title, validation_class: UTF8Type}
{column_name: genres, validation_class: UTF8Type}];
Foi útil?

Solução

Creating a column family via the CLI doesn't create a schema that you have to stick to. It depends on how you insert the data, that is what defines the primary key. When you create the column family via the CLi you only have to define what kind of value the primary key will contain i.e. is it a string (UTF8Type), int (IntegerType) etc.

Also you cant actually have an alias for the KEY column (aka the primary key in your table) via the CLI. You have to use CQL for that. If you want defined schemas and structured queries rather than using wide rows you should target a newer version of cassandra (why now 1.2.x?) and use CLQ3.

A more visual representation of what I mean, your cassandra-cli statement creates this when viewed from cqlsh via the describe table command:

CREATE TABLE movies (
  KEY text PRIMARY KEY,    <------- pk 
  genres text,
  title text,
  movieid text
) WITH // and a bunch of cf options

But this doesn't mean you cant insert another column that isn't defined there, because thrift doesn't really care about the CF's schema.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top