Apache Cassandra

CQLSH CAPTURE Command

In this post, we will learn how to use the capture command when working in the Cassandra Shell.

This command allows you to capture the results of a given query and append them to a file in an exponential format. It is one of the useful commands that can help you speed up your work in the Cassandra shell.

Let us discuss what this command does and how to use it.

Command Syntax

The following shows the command syntax:

CAPTURE [‘filename’ | OFF]

The capture command allows you to start the capture of your queries to the specified filename.

Remember that the command does not support absolute file paths when specifying the filename value.

NOTE: When capture mode is ON, CQLSH will not display any output except error messages.

Show Capture Status

To check whether capture mode is enabled, log in to your Cassandra cluster and run the following capture command:

$ cqlsh -u cassandra -p cassandra

Run the following capture command:

cassandra@cqlsh> capture
Currently not capturing query output.

In this case, we can see that capture mode is not enabled.

Cassandra Enable Capture to a Given File

The following enables capture mode and writes the result to cqlcapture.out as shown in the command below:

cassandra@cqlsh> capture ‘~/cqlcapture.out’
Now capturing query output to ‘/root/cqlcapture.out’.

Once enabled, we can execute standard CQL queries whose output will be saved to the specified filename.

We can run a few commands, as shown below:

cassandra@cqlsh> expand on;
Now Expanded output is enabled
cassandra@cqlsh> use zero_day;
cassandra@cqlsh:zero_day> select * from records;
cassandra@cqlsh:zero_day>

Note that the commands do not display the results but instead write them to the specified file.

$ cat ~/cqlcapture.out

The contents of the file are shown below:

To end the capture mode, run the command: CAPTURE OFF.

Conclusion

This tutorial covers how to capture query results to a given file using the CQLSH CAPTURE command. The examples highlighted the syntax command and showed the CAPTURE status.

About the author

John Otieno

My name is John and am a fellow geek like you. I am passionate about all things computers from Hardware, Operating systems to Programming. My dream is to share my knowledge with the world and help out fellow geeks. Follow my content by subscribing to LinuxHint mailing list