Deep dive into Cassandra Shell Commands

Last updated on May 30 2022
Lalit Kolgaonkar

Table of Contents

Deep dive into Cassandra Shell Commands

Cassandra – Shell Commands

Cassandra provides documented shell commands in addition to CQL commands. Given below are the Cassandra documented shell commands.

Help

The HELP command displays a synopsis and a brief description of all cqlsh commands. Given below is the usage of help command.

cqlsh> help

 

Documented shell commands:

===========================

CAPTURE COPY DESCRIBE EXPAND PAGING SOURCE

CONSISTENCY DESC EXIT HELP SHOW TRACING.

 

CQL help topics:

================

ALTER           CREATE_TABLE_OPTIONS       SELECT

ALTER_ADD       CREATE_TABLE_TYPES         SELECT_COLUMNFAMILY

ALTER_ALTER     CREATE_USER                SELECT_EXPR

ALTER_DROP      DELETE                     SELECT_LIMIT

ALTER_RENAME    DELETE_COLUMNS             SELECT_TABLE

Capture

This command captures the output of a command and adds it to a file. For example, take a look at the following code that captures the output to a file named Outputfile.

cqlsh> CAPTURE ‘/home/hadoop/CassandraProgs/Outputfile’

When we type any command in the terminal, the output will be captured by the file given. Given below is the command used and the snapshot of the output file.

cqlsh:tecklearn> select * from emp;

a 3
Capture

You can turn capturing off using the following command.

cqlsh:tecklearn> capture off;

Consistency

This command shows the current consistency level, or sets a new consistency level.

cqlsh:tecklearn> CONSISTENCY

Current consistency level is 1.

Copy

This command copies data to and from Cassandra to a file. Given below is an example to copy the table named emp to the file myfile.

cqlsh:tecklearn> COPY emp (emp_id, emp_city, emp_name, emp_phone,emp_sal) TO ‘myfile’;

4 rows exported in 0.034 seconds.

If you open and verify the file given, you can find the copied data as shown below.

b 2
Copy

Describe

This command describes the current cluster of Cassandra and its objects. The variants of this command are explained below.

Describe cluster − This command provides information about the cluster.

cqlsh:tecklearn> describe cluster;

 

Cluster: Test Cluster

Partitioner: Murmur3Partitioner

 

Range ownership:

-658380912249644557 [127.0.0.1]

-2833890865268921414 [127.0.0.1]

-6792159006375935836 [127.0.0.1]

Describe Keyspaces − This command lists all the keyspaces in a cluster. Given below is the usage of this command.

cqlsh:tecklearn> describe keyspaces;

 

system_traces system tp tecklearn

Describe tables − This command lists all the tables in a keyspace. Given below is the usage of this command.

cqlsh:tecklearn> describe tables;

emp

Describe table − This command provides the description of a table. Given below is the usage of this command.

cqlsh:tecklearn> describe table emp;

 

CREATE TABLE tecklearn.emp (

emp_id int PRIMARY KEY,

emp_city text,

emp_name text,

emp_phone varint,

emp_sal varint

) WITH bloom_filter_fp_chance = 0.01

AND caching = ‘{“keys”:”ALL”, “rows_per_partition”:”NONE”}’

AND comment = ”

AND compaction = {‘min_threshold’: ‘4’, ‘class’:

‘org.apache.cassandra.db.compaction.SizeTieredCompactionStrategy’,

‘max_threshold’: ’32’}

 

AND compression = {‘sstable_compression’:

‘org.apache.cassandra.io.compress.LZ4Compressor’}

 

AND dclocal_read_repair_chance = 0.1

AND default_time_to_live = 0

AND gc_grace_seconds = 864000

AND max_index_interval = 2048

AND memtable_flush_period_in_ms = 0

AND min_index_interval = 128

AND read_repair_chance = 0.0

AND speculative_retry = ‘99.0PERCENTILE’;

CREATE INDEX emp_emp_sal_idx ON tecklearn.emp (emp_sal);

Describe Type

This command is used to describe a user-defined data type. Given below is the usage of this command.

cqlsh:tecklearn> describe type card_details;

 

CREATE TYPE tecklearn.card_details (

num int,

pin int,

name text,

cvv int,

phone set<int>,

mail text

);

Describe Types

This command lists all the user-defined data types. Given below is the usage of this command. Assume there are two user-defined data types: card and card_details.

cqlsh:tecklearn> DESCRIBE TYPES;

 

card_details card

Expand

This command is used to expand the output. Before using this command, you have to turn the expand command on. Given below is the usage of this command.

cqlsh:tecklearn> expand on;

cqlsh:tecklearn> select * from emp;

 

@ Row 1

———–+————

emp_id | 1

emp_city | Hyderabad

emp_name | ram

emp_phone | 9848022338

emp_sal | 50000

 

@ Row 2

———–+————

emp_id | 2

emp_city | Delhi

emp_name | robin

emp_phone | 9848022339

emp_sal | 50000

 

@ Row 3

———–+————

emp_id | 4

emp_city | Pune

emp_name | rajeev

emp_phone | 9848022331

emp_sal | 30000

 

@ Row 4

———–+————

emp_id | 3

emp_city | Chennai

emp_name | rahman

emp_phone | 9848022330

emp_sal | 50000

(4 rows)

Note − You can turn the expand option off using the following command.

cqlsh:tecklearn> expand off;

Disabled Expanded output.

Exit

This command is used to terminate the cql shell.

Show

This command displays the details of current cqlsh session such as Cassandra version, host, or data type assumptions. Given below is the usage of this command.

cqlsh:tecklearn> show host;

Connected to Test Cluster at 127.0.0.1:9042.

 

cqlsh:tecklearn> show version;

[cqlsh 5.0.1 | Cassandra 2.1.2 | CQL spec 3.2.0 | Native protocol v3]

Source

Using this command, you can execute the commands in a file. Suppose our input file is as follows −

c 2
Source

Then you can execute the file containing the commands as shown below.

cqlsh:tecklearn> source ‘/home/hadoop/CassandraProgs/inputfile’;

 

emp_id |  emp_city | emp_name |  emp_phone | emp_sal

——–+———–+———-+————+———

1 | Hyderabad |   ram    | 9848022338 | 50000

2 | Delhi     |   robin  | 9848022339 | 50000

3 | Pune      |   rajeev | 9848022331 | 30000

4 | Chennai   |   rahman | 9848022330 | 50000

(4 rows)

 

So, this brings us to the end of blog. This Tecklearn ‘Deep dive into Cassandra Shell Commands’ helps you with commonly asked questions if you are looking out for a job in Cassandra and No-SQL Database Domain.

If you wish to learn HBase and build a career in Cassandra or No-SQL Database domain, then check out our interactive, Apache Cassandra Training, that comes with 24*7 support to guide you throughout your learning period. Please find the link for course details:

https://www.tecklearn.com/course/apache-cassandra-training/

Apache Cassandra Training

About the Course

Take your career to the next level as a certified Apache Cassandra developer by acquiring all the skills through our hands-on training sessions. Tecklearn’s Apache Cassandra Certification Training is designed by professionals as per the industry requirements and demands. This Cassandra Certification Training helps you to master the concepts of Apache Cassandra including Cassandra Architecture, its features, Cassandra Data Model, and its Administration. Our Cassandra certification training course lets you master the high availability NoSQL distributed database.

Why Should you take Apache Cassandra Training?

  • The average salary of a Software Engineer with Apache Cassandra skill is $120,500 per year. – Payscale.com
  • Cassandra is in use at Constant Contact, CERN, Comcast, eBay, GitHub, GoDaddy, Hulu, Instagram, Intuit, Netflix, Reddit, The Weather Channel, and over 1500 more companies that have large, active data sets.
  • Apache Cassandra is one of the most widely used NoSQL database. It offers features such as Fault Tolerance, Scalability, Flexible Data Storage and its efficient writes, which makes it the perfect database for various purposes.

What you will Learn in this Course?

Introduction to Big Data, and Cassandra

  • What is Big Data
  • Limitations of RDBMS
  • NoSQL and it’s Characteristics
  • CAP Theorem
  • Basic concepts of Cassandra
  • Features of Cassandra

Cassandra Data model, Installation and setup

  • Installation of Cassandra
  • Key concepts and deployment of non-relational database, column-oriented database, Data Model – column, column family

Cassandra Architecture

  • Explain the Architecture of Cassandra
  • Different Layers of Cassandra Architecture
  • Partitioning and Snitches
  • Explain Vnodes and How Read and Write Path works
  • Understand Compaction, Anti-Entropy and Tombstone
  • Describe Repairs in Cassandra

Deep Dive into Cassandra Database

  • Describe Different Data Types Used in Cassandra
  • Explain Collection Types
  • Describe What are CRUD Operations
  • Implement Insert, Select, Update and D        elete of various elements
  • Implement Various Functions Used in Cassandra
  • Describe Importance of Roles and Indexing

Backup & Restore and Performance Tuning

  • Learn backup and restore functionality and its importance
  • Create a snapshot using Nodetool utility
  • Restore a snapshot
  • Understand how to choose the right balance of the following resources: memory, CPU, disks, number of nodes, and network.
  • Understand all the logs created by Cassandra
  • Explain the purpose of different log files
  • Configure the log files
  • Learn about Performance Tuning
  • Integration with Spark and Kafka

Advance Modelling

  • Rules of Cassandra data modelling
  • Modelling data around queries
  • Creating table for data queries

Deploying the IDE for Cassandra applications

  • Learning key drivers
  • Deploying the IDE for Cassandra applications and cluster connection
  • Data query implementation

Cassandra Administration

  • Understanding Node Tool Utility
  • Cluster management using Command Line Interface
  • Management and Monitoring using DataStax Ops Center

Cassandra API and Summarization

  • Cassandra client connectivity
  • Connection pool internals
  • Cassandra API
  • Features and concepts of Hector client
  • Thrift, JAVA code and Summarization

Got a question for us? Please mention it in the comments section and we will get back to you.

0 responses on "Deep dive into Cassandra Shell Commands"

Leave a Message

Your email address will not be published. Required fields are marked *