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:
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:
Run the following capture command:
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:
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:
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.
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.