Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cassandra cli: Convert hex values into a human-readable format

Im starting with cassandra, and when I run list or get commands in cassandra-cli, I get results like this:

[default@usersdatabase] list users;
Using default limit of 100
-------------------
RowKey: boby
=> (column=6e616d65, value=426f62, timestamp=1294780856414000)
-------------------
RowKey: edzuksm
=> (column=656d61696c, value=6d617268656c697340696e626f782e6c76, timestamp=1294780533705000)
=> (column=6e616d65, value=45647561726473, timestamp=1294780488155000)
=> (column=7375726e616d65, value=4d617268656c6973, timestamp=1294780515429000)

2 Rows Returned.

I can't read it, I see only values like '6e616d65'.

How can I display the values in a human-readable format?

like image 426
Edmhs Avatar asked Jan 11 '11 21:01

Edmhs


1 Answers

By default, column names and column values have no type in Cassandra, they are only byte arrays. If you set a comparator class (column name type) or validation class (column value type), the CLI will pick up on this and show you the data types in a sensible format instead of a hex version of the byte array.

If you don't want this actual data typing, you can tell the CLI to assume that column names or values are a certain data type by using the assume command. Keys never have a data type, so assume has to be used there if you want to work with some data types.

Here's the help info on assume for reference:

[default@Keyspace1] help assume;    
assume <column_family> comparator as <type>;
assume <column_family> sub_comparator as <type>;
assume <column_family> validator as <type>;
assume <column_family> keys as <type>;

Assume one of the attributes (comparator, sub_comparator, validator or keys)
of the given column family to match specified type. Available types: bytes, integer,
long, lexicaluuid, timeuuid, utf8, ascii.
example:
assume Users comparator as lexicaluuid;

EDIT: As of Cassandra 0.8, you can specify a validation class for keys, and the CLI automatically makes use of this info.

like image 78
Tyler Hobbs Avatar answered Oct 16 '22 18:10

Tyler Hobbs