Friday, January 04, 2013

Cassandra - learn #3 cannot parse '...' as hex bytes

I began with Cassandra again today. However, i tried to practice from a book and found error - org.apache.cassandra.db.marshal.MarshalException: cannot parse '...' as hex bytes
[default@MyKeyspace]
[default@MyKeyspace] create column family users;
e931ab3d-4e46-3e13-9c7e-002ee5b8d1d4
[default@MyKeyspace] set users['opun']['fname']='Surachart';
org.apache.cassandra.db.marshal.MarshalException: cannot parse 'fname' as hex bytes
[default@MyKeyspace]
[default@MyKeyspace] describe;
Keyspace: MyKeyspace:
  Replication Strategy: org.apache.cassandra.locator.NetworkTopologyStrategy
  Durable Writes: true
    Options: [datacenter1:1]
  Column Families:
    ColumnFamily: users
      Key Validation Class: org.apache.cassandra.db.marshal.BytesType
      Default column value validator: org.apache.cassandra.db.marshal.BytesType
      Columns sorted by: org.apache.cassandra.db.marshal.BytesType
      GC grace seconds: 864000
      Compaction min/max thresholds: 4/32
      Read repair chance: 0.1
      DC Local Read repair chance: 0.0
      Replicate on write: true
      Caching: KEYS_ONLY
      Bloom Filter FP chance: default
      Built indexes: []
      Compaction Strategy: org.apache.cassandra.db.compaction.SizeTieredCompactionStrategy
      Compression Options:
        sstable_compression: org.apache.cassandra.io.compress.SnappyCompressor
[default@MyKeyspace]
Good Luck for me, I found out idea on stackoverflow. Use "assume" command to apply client side validation with utf8.
[default@MyKeyspace] help assume;
assume <cf> comparator as <type>;
assume <cf> sub_comparator as <type>;
assume <cf> validator as <type>;
assume <cf> keys as <type>;

Assume one of the attributes (comparator, sub_comparator, validator or keys)
of the given column family match specified type. The specified type will
be used when displaying data returned from the column family.

This statement does not change the column family definition stored in
Cassandra. It only affects the cli and how it will transform values
to be sent to and interprets results from Cassandra.

If results from Cassandra do not validate according to the assumptions an
error is displayed in the cli.

Required Parameters:
- cf: Name of the column family to make the assumption about.

- type: Validator type to use when processing values.

  Supported values are:
    - ascii
    - bytes
    - counterColumn (distributed counter column)
    - int
    - integer (a generic variable-length integer type)
    - lexicalUUID
    - long
    - utf8

  It is also valid to specify the fully-qualified class name to a class that
  extends org.apache.cassandra.db.marshal.AbstractType.

Examples:
assume Standard1 comparator as lexicaluuid;
assume Standard1 keys as ascii;


[default@MyKeyspace] assume users keys as utf8;
Assumption for column family 'users' added successfully.
[default@MyKeyspace] assume users comparator as utf8;
Assumption for column family 'users' added successfully.
[default@MyKeyspace] assume users validator as utf8;
Assumption for column family 'users' added successfully.
[default@MyKeyspace] describe;
Keyspace: MyKeyspace:
  Replication Strategy: org.apache.cassandra.locator.NetworkTopologyStrategy
  Durable Writes: true
    Options: [datacenter1:1]
  Column Families:
    ColumnFamily: users
      Key Validation Class: org.apache.cassandra.db.marshal.BytesType
      Default column value validator: org.apache.cassandra.db.marshal.BytesType
      Columns sorted by: org.apache.cassandra.db.marshal.BytesType
      GC grace seconds: 864000
      Compaction min/max thresholds: 4/32
      Read repair chance: 0.1
      DC Local Read repair chance: 0.0
      Replicate on write: true
      Caching: KEYS_ONLY
      Bloom Filter FP chance: default
      Built indexes: []
      Compaction Strategy: org.apache.cassandra.db.compaction.SizeTieredCompactionStrategy
      Compression Options:
        sstable_compression: org.apache.cassandra.io.compress.SnappyCompressor
[default@MyKeyspace] set users['opun']['fname']='Surachart';
Value inserted.
Elapsed time: 83 msec(s).
[default@MyKeyspace] set users['opun']['password']='pass';
Value inserted.
Elapsed time: 2.36 msec(s).
[default@MyKeyspace] set users['opun']['lname']='Opun';
Value inserted.
Elapsed time: 2.63 msec(s).
[default@MyKeyspace] set users['opun']['email']='surachart at gmail dot com';
Value inserted.
Elapsed time: 3.58 msec(s).
[default@MyKeyspace] get  users['opun']
...     ;
=> (column=email, value=surachart at gmail dot com, timestamp=1357287771738000)
=> (column=fname, value=Surachart, timestamp=1357287712011000)
=> (column=lname, value=Opun, timestamp=1357287752774000)
=> (column=password, value=pass, timestamp=1357287730458000)
Returned 4 results.
Elapsed time: 96 msec(s).
[default@MyKeyspace] describe;
Keyspace: MyKeyspace:
  Replication Strategy: org.apache.cassandra.locator.NetworkTopologyStrategy
  Durable Writes: true
    Options: [datacenter1:1]
  Column Families:
    ColumnFamily: users
      Key Validation Class: org.apache.cassandra.db.marshal.BytesType
      Default column value validator: org.apache.cassandra.db.marshal.BytesType
      Columns sorted by: org.apache.cassandra.db.marshal.BytesType
      GC grace seconds: 864000
      Compaction min/max thresholds: 4/32
      Read repair chance: 0.1
      DC Local Read repair chance: 0.0
      Replicate on write: true
      Caching: KEYS_ONLY
      Bloom Filter FP chance: default
      Built indexes: []
      Compaction Strategy: org.apache.cassandra.db.compaction.SizeTieredCompactionStrategy
      Compression Options:
        sstable_compression: org.apache.cassandra.io.compress.SnappyCompressor
It might be old idea for lots of people, but new for me :) Cool!

2 comments:

Anonymous said...

Thank you, helped me a lot

Akash Deep said...

Go thorough this link..

http://wiki.apache.org/cassandra/CassandraCli