Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Prettifying results of cqlsh commands in Linux terminal

Is there any way to prettify the results of cql commands in the Linux terminal while using the cqlsh utility (cql version of Mongo .pretty())? It becomes quite difficult to read the results when the output is displayed normally, especially when there are nested documents and arrays

like image 657
booleanhunter Avatar asked Mar 09 '15 19:03

booleanhunter


People also ask

Which command displays the details of current Cqlsh session?

SHOW − Displays the details of current cqlsh session such as Cassandra version, host, or data type assumptions. SOURCE − Executes a file that contains CQL statements. TRACING − Enables or disables request tracing.

What is Cqlsh commands?

cqlsh is a command-line interface for interacting with Cassandra using CQL (the Cassandra Query Language). It is shipped with every Cassandra package, and can be found in the bin/ directory alongside the cassandra executable.


2 Answers

Perhaps you are interested in the EXPAND command?

Usage: EXPAND ON;

From the documentation over at Datastax:

This command lists the contents of each row of a table vertically, providing a more convenient way to read long rows of data than the default horizontal format. You scroll down to see more of the row instead of scrolling to the right. Each column name appears on a separate line in column one and the values appear in column two.

Source: https://docs.datastax.com/en/dse/5.1/cql/cql/cql_reference/cqlsh_commands/cqlshExpand.html

like image 166
arielkirkwood Avatar answered Sep 28 '22 11:09

arielkirkwood


cqlsh is a python script that uses the datastax python-driver to make queries to cassandra. You can modify the script to meet your needs (see: Why does cqlsh right-align strings? for an example), or you can write a program using the python-driver or another library to do what you need.

Since mongo is document-oriented, it makes sense that pretty-printing is an available option. However cassandra is more columnar / row-oriented so you don't typically look at result sets like documents, instead you look at them more like rows, although I do see the utility in a 'pretty-print' like function.

like image 33
Andy Tolbert Avatar answered Sep 28 '22 09:09

Andy Tolbert