| by Arround The Web | No comments

Cassandra Code Comments

“When interacting with Cassandra databases, you often use the Cassandra Query language. Whether you are creating a CQL script or just executing commands in the terminal, it can be beneficial to include comments in your code. This helps you document your code for later use or sharing with other devs.

This short tutorial will cover the syntax for adding commands in your CQL scripts and CQL Shell.”

Cassandra Single Line Comments

The first type of comment you can use is single-line comments. These types of comments only span to the end of the line.

They are very useful for adding meta-comments to your code.

To create a single comment in CQL, you can use two dashes (- -).

An example is as shown:

drop keyspace if exists zero_day; -- ensure no name collisions

 
In this case, the text after the — symbol until the end of the line is commented out. This means that it will not be treated as a valid CQL command.

Another method you can use to create single-line comments is two forward slash characters (//).

Example:

cassandra@cqlsh> expand on; // test

 
This commenting technique is supported in CQL Shell. Like the two-dashed method, it comments out the content until the end of the line.

Cassandra Block Comments

The second and most common type of comment is block comments. These types of comments can span multiple lines.

The multi-line/block comment syntax is as shown:

/* start here
Line_2
Line_3
Line_N
close */

 
In this case, we start with a forward slash and an asterisk character (/*). The comment then continues until it encounters an asterisk and a forward slash (*/).

It is good to remember that a comment is ignored even if it contains valid CQL commands. These make comments very useful for disabling sections of your code.

Example:

/*
create type cve_reports (
cve_number text,
report_date date,
affected_vendor text,
severity float,
);
*/

 

Terminating

This post discussed how we could create and use comments in CQL scripts and CQL Shell.

Thanks for reading & Happy coding!!

Share Button

Source: linuxhint.com

Leave a Reply