Monday 10 November 2014

Cassandra Handy commands



Some handy commands of Cassandra:

To make vertical output from cqlsh.

Use EXPAND ON;

Example :
cqlsh:loadtest> expand on;
Now printing expanded output
cqlsh:loadtest> select * from cmdtest;
@ Row 1
------+------
 id   | 1
 name | amit
(1 rows)



To execute Query from file

SOURCE

cqlsh> use loadtest;
cqlsh:loadtest> source '/tmp/query.sql'
 id | name
----+---------
  1 |    amit
  2 | testing
(2 rows)


CAPTURE :
Captures command output and appends it to a file.

To start capturing the output of a query, specify the path of the file relative to the current directory. Enclose the file name in single quotation marks

cqlsh:loadtest> capture '/tmp/a'
Now capturing query output to '/tmp/a'.
cqlsh:loadtest> select * from cmdtest;
cqlsh:loadtest> exit
cassandra@dell27:~> cat /tmp/a
 id | name
----+---------
  1 |    amit
  2 | testing
(2 rows)