Cassandra cli: Convert hex values into a human-rea

2019-03-13 10:00发布

Im starting with , and when I run list or get commands in , 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?

1条回答
Melony?
2楼-- · 2019-03-13 10:39

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.

查看更多
登录 后发表回答