Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does cutting and pasting from the Cassandra CLI tutorial not work?

Tags:

cassandra

Blindly following http://wiki.apache.org/cassandra/CassandraCli, and can someone please explain this?

aaron-mac:apache-cassandra-1.0.0 aaron$ bin/cassandra-cli -host localhost -port 9160
Connected to: "Test Cluster" on localhost/9160
Welcome to the Cassandra CLI.

Type 'help;' or '?' for help.
Type 'quit;' or 'exit;' to quit.

[default@unknown] use Keyspace1;
Authenticated to keyspace: Keyspace1

[default@Keyspace1] create column family User with comparator = UTF8Type; 
5ef4bad0-fb2a-11e0-0000-242d50cf1ffd
Waiting for schema agreement...
... schemas agree across the cluster
[default@Keyspace1] set User['jsmith']['first'] = 'John'; 
org.apache.cassandra.db.marshal.MarshalException: cannot parse 'jsmith' as hex bytes
[default@Keyspace1] 
like image 675
Aaron Watters Avatar asked Oct 20 '11 14:10

Aaron Watters


3 Answers

Before you run any set command in Cassandra CLI, it is always advisable to do the following :

assume <column_family> keys as utf8;
assume <column_family> comparator as utf8;
assume <column_family> validator as utf8;

This will ensure that everything you set and list will be understood

P.S : This is only for newcomers to Cassandra

like image 108
Karthik S Avatar answered Nov 08 '22 21:11

Karthik S


That's for an older version of Cassandra. Keys are now treated as hex bytes by default, so you need:

set User[utf8('jsmith')]['first'] = 'John';

or do:

assume User keys as utf8;
set User['jsmith']['first'] = 'John';

Or, as the note in the doc says:

Note: As of Cassandra 0.8, we need to declare a key_validation_class for the column family:

update column family User with key_validation_class=UTF8Type;
like image 4
Theodore Hong Avatar answered Nov 08 '22 19:11

Theodore Hong


set User['jsmith'][utf8('first')] = utf8('John');

If you're unsure about the set command you can type help set; and it'll show the full documentation.

like image 1
Sebastian Salamanca Avatar answered Nov 08 '22 19:11

Sebastian Salamanca