Chapter 4 covers the basics of Cassandra Query Language (CQL), the primary language used for interacting with Cassandra databases. This chapter explains how to create keyspaces and tables, perform CRUD operations, and understand the different data types in Cassandra. It also delves into partition keys and clustering columns for efficient data distribution and retrieval.
Introduction to CQL
What does CQL stand for in the context of Cassandra? a) Cassandra Query Language b) Cassandra Queue Language c) Column Query Language d) Cassandra Query Loader
Which of the following is true about CQL? a) It uses SQL-like syntax but operates on a NoSQL database b) It is used for querying relational databases c) It uses JSON for data manipulation d) It is similar to Python
What is the primary purpose of CQL in Cassandra? a) Data visualization b) To execute map-reduce jobs c) To interact with Cassandra databases d) To configure server settings
Which of the following is NOT a valid CQL command? a) SELECT b) CREATE c) DROP d) MERGE
In CQL, which statement is used to insert data into a table? a) ADD INTO b) INSERT INTO c) PUT DATA d) LOAD INTO
Creating Keyspaces and Tables
What is a keyspace in Cassandra? a) A container for data storage b) A namespace for tables and data c) A database within a relational database system d) A type of data compression
Which CQL command is used to create a new keyspace? a) CREATE DATABASE b) CREATE SCHEMA c) CREATE KEYSPACE d) CREATE TABLESPACE
What is the default replication strategy used when creating a keyspace in Cassandra? a) NetworkTopologyStrategy b) SimpleStrategy c) RackAwareStrategy d) DCLStrategy
To create a table in CQL, which command is used? a) CREATE TABLE b) NEW TABLE c) CREATE DATA d) DEFINE TABLE
When defining a table in CQL, which is used to uniquely identify rows? a) Primary Key b) Unique Key c) Cluster Key d) Partition Key
CRUD Operations
Which CQL command is used to retrieve data from a table? a) SELECT b) GET c) SHOW d) FETCH
What does the CQL command INSERT INTO do? a) Updates existing records b) Deletes data c) Adds new rows to a table d) Modifies table structure
Which CQL command is used to modify existing data? a) CHANGE b) UPDATE c) ALTER d) MODIFY
In CQL, which command is used to delete data from a table? a) REMOVE b) DELETE c) DROP d) CLEAR
The CQL command TRUNCATE is used for: a) Deleting all data from a table b) Dropping the table c) Removing a single record d) Updating data
Data Types in Cassandra
Which of the following is a valid CQL data type? a) STRING b) BOOLEAN c) INT d) All of the above
What is the data type used to store variable-length strings in CQL? a) VARCHAR b) TEXT c) CHAR d) STRING
Which data type is used to store dates and times in CQL? a) TIMESTAMP b) DATETIME c) DATE d) TIME
Which data type in CQL is used to store a collection of elements of the same type? a) SET b) LIST c) MAP d) TUPLE
What is the CQL data type for storing a unique identifier? a) UUID b) GUID c) ID d) UNIQUE
Understanding Partition Keys and Clustering Columns
What is the purpose of the partition key in Cassandra? a) To group rows within the same table b) To distribute rows across nodes c) To enforce uniqueness of data d) To define relationships between tables
Which CQL clause is used to define the partition key? a) PRIMARY KEY b) PARTITION KEY c) CLUSTERING d) INDEX
In Cassandra, what is a clustering column used for? a) Identifying partitions b) Sorting rows within a partition c) Defining data types d) Storing large objects
What is the maximum number of clustering columns allowed in a table in Cassandra? a) 1 b) 2 c) 5 d) Unlimited
The order of clustering columns affects: a) Data storage in the file system b) The query performance for sorting and filtering c) Data replication across nodes d) The security level
Advanced CQL Concepts
When creating a table, the WITH clause in CQL is used for: a) Specifying the primary key b) Defining the table’s read/write consistency c) Defining table-level settings such as compaction or caching d) Adding new columns
Which CQL feature is used for controlling read and write consistency levels? a) CONSISTENCY b) REPLICATION c) CLUSTERING d) CAPACITY
What is the purpose of the IF NOT EXISTS clause in CQL? a) To check if a record exists before inserting b) To conditionally create a keyspace or table c) To check table schema compatibility d) To automatically drop a table if it exists
The ALLOW FILTERING clause in CQL is used to: a) Enable filtering on non-primary key columns b) Disable filtering in queries c) Restrict access to certain data types d) Perform data validation
Which of the following is true about CQL in Cassandra? a) CQL can only query single-node databases b) CQL queries are similar to SQL but adapted for Cassandra’s NoSQL model c) CQL is primarily used for data visualization d) CQL only supports key-value pairs
Answers Table
QNo
Answer
1
a) Cassandra Query Language
2
a) It uses SQL-like syntax but operates on a NoSQL database
3
c) To interact with Cassandra databases
4
d) MERGE
5
b) INSERT INTO
6
b) A namespace for tables and data
7
c) CREATE KEYSPACE
8
b) SimpleStrategy
9
a) CREATE TABLE
10
a) Primary Key
11
a) SELECT
12
c) Adds new rows to a table
13
b) UPDATE
14
b) DELETE
15
a) Deleting all data from a table
16
d) All of the above
17
a) VARCHAR
18
a) TIMESTAMP
19
b) LIST
20
a) UUID
21
b) To distribute rows across nodes
22
b) PARTITION KEY
23
b) Sorting rows within a partition
24
d) Unlimited
25
b) The query performance for sorting and filtering
26
c) Defining table-level settings such as compaction or caching
27
a) CONSISTENCY
28
b) To conditionally create a keyspace or table
29
a) Enable filtering on non-primary key columns
30
b) CQL queries are similar to SQL but adapted for Cassandra’s NoSQL model