Cassandra cli: why my columns are not readable?

Working on cassandra store for Apache Sirona (I’ll speak surely of it in another post) I used cassandra-cli to check my persisted data and browse my Cassandra keyspace easily.

However doing a simple ‘list’ (select *) the result looked like the expected one but was not that readable. Even if test data values were not that important the row keys were something crucial in my modelling and tests so I needed to read it (even if my unit tests were green it is always better to validate it twice ;).

When you wrote few cassandra code you know Serializer is something very important and you quickly understand the unreadable values/keys are in fact bytes. Googling a bit you quickly realize the command you are looking for is ‘assume’. Thanks to it you can set the encoding type and if that’s something “standard” (utf8 in my case) cassandra-cli can unserialize it.

So basically in my case I started from this serialized result:

RowKey: 73657373696f6e2d6475726174696f6e732d3e6e732d3e73657373696f6e2d6475726174696f6e732d2f2d3e7562756e7475
=> (name=key, value=73657373696f6e2d6475726174696f6e732d2f, timestamp=1384413692465001)
=> (name=m2, value=7ff8000000000000, timestamp=1384413692466005)
=> (name=max, value=7ff8000000000000, timestamp=1384413692466002)
=> (name=maxConcurrency, value=00000000, timestamp=1384413692465002)
=> (name=mean, value=7ff8000000000000, timestamp=1384413692466006)
=> (name=min, value=7ff8000000000000, timestamp=1384413692466003)
=> (name=n, value=0000000000000000, timestamp=1384413692466001)
=> (name=role, value=73657373696f6e2d6475726174696f6e73, timestamp=1384413692465000)
=> (name=sum, value=0000000000000000, timestamp=1384413692466004)
=> (name=variance, value=7ff8000000000000, timestamp=1384413692466000

Then i “assumed” the row key was an utf8 string:

[default@sirona] assume counters_values keys as utf8;

And got a redable key:

RowKey: jdbc->ns->jdbc:sirona:hsqldb:mem:db?delegateDriver=org.hsqldb.jdbcDriver->node1
=> (name=key, value=6a6462633a7369726f6e613a6873716c64623a6d656d3a64623f64656c65676174654472697665723d6f72672e6873716c64622e6a646263447269766572, timestamp=1384413693666001)
=> (name=m2, value=7ff8000000000000, timestamp=1384413693666008)
=> (name=max, value=7ff8000000000000, timestamp=1384413693666005)
=> (name=maxConcurrency, value=00000001, timestamp=1384413693666002)
=> (name=mean, value=7ff8000000000000, timestamp=1384413693666009)
=> (name=min, value=7ff8000000000000, timestamp=1384413693666006)
=> (name=n, value=0000000000000000, timestamp=1384413693666004)
=> (name=role, value=6a646263, timestamp=1384413693666000)
=> (name=sum, value=0000000000000000, timestamp=1384413693666007)
=> (name=variance, value=7ff8000000000000, timestamp=1384413693666003)

If you want to decode values you just set the right serializer as comparator and validator:

[default@sirona] assume counters_values validator as long;
Assumption for column family 'counters_values' added successfully.
[default@sirona] assume counters_values comparator as long;
Assumption for column family 'counters_values' added successfully.

Then simply ‘GET’ you data (don’t forget to serialize keys/column names with the right encoder, utf8() in my case):

[default@sirona] GET counters_values[utf8('jdbc->ns->jdbc:sirona:hsqldb:mem:db?delegateDriver=org.hsqldb.jdbcDriver->node1')][utf8('variance')];
=> (name=8530224966148186981, value=9221120237041090560, timestamp=1384413693666003)
Elapsed time: 4.12 msec(s).

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s