Reading rows and columns

CLI commands to retrieve data.

Use the CLI GET command within to retrieve a particular row from a table. Use the LIST command to return a batch of rows and their associated columns (default limit of rows returned is 100).

Cassandra stores all data internally as hex byte arrays by default. If you do not specify a default row key validation class, column comparator and column validation class when you define the table, Cassandra CLI will expect input data for row keys, column names, and column values to be in hex format (and data will be returned in hex format).

To pass and return data in human-readable format, you can pass a value through an encoding function. Available encodings are:

  • ascii
  • bytes
  • integer (a generic variable-length integer type)
  • lexicalUUID
  • long
  • utf8

You can also use the ASSUME command to specify the encoding in which table data should be returned for the entire client session.

Procedure

  1. Get the first 100 rows (and all associated columns) from the users table.
    [default@demo] LIST users;
  2. Return a particular row key and column in UTF8 format.
    [default@demo] GET users[utf8('bobbyjo')][utf8('full_name')];
                    
  3. Return row keys, column names, and column values in ASCII-encoded format.
    [default@demo] ASSUME users KEYS AS ascii;
    [default@demo] ASSUME users COMPARATOR AS ascii;
    [default@demo] ASSUME users VALIDATOR AS ascii;