PolarSPARC |
Cassandra Quick Notes :: Part - 1
Bhaskar S | *UPDATED*11/24/2023 |
Overview
Cassandra is a proven open-source NoSQL database with the following capabilities:
Distributed
Decentralized
Highly Scalable
Fault Tolerant
Column Oriented
Installation and Setup
We will assume that the installation will be on a Ubuntu 22.04 LTS based Linux desktop. Also, assuming the logged in user is polarsparc with the home directory located at /home/polarsparc.
Ensure Docker is installed and setup. Else, refer to this article for further instructions Introduction to Docker.
We will setup a directory structure by executing the following commands from the users home directory:
$ mkdir -p cassandra/data
$ mkdir -p cassandra/logs
$ mkdir -p cassandra/etc/cassandra
We will refer to the directory /home/polarsparc/cassandra using the environment variable called CASSANDRA_HOME set as follows:
$ export CASSANDRA_HOME=/home/polarsparc/cassandra
To run a single node Apache Cassandra cluster, we need to download few configuration files to the directory $CASSANDRA_HOME/etc/cassandra by executing the following commands:
$ cd $CASSANDRA_HOME/etc/cassandra
$ wget https://github.com/apache/cassandra/raw/trunk/conf/cassandra-env.sh
$ wget https://github.com/apache/cassandra/raw/trunk/conf/cassandra.yaml
$ wget https://github.com/apache/cassandra/raw/trunk/conf/jvm-server.options
$ wget https://github.com/apache/cassandra/raw/trunk/conf/jvm17-server.options
$ wget https://github.com/apache/cassandra/raw/trunk/conf/logback.xml
$ cd $CASSANDRA_HOME
Edit the file $CASSANDRA_HOME/etc/cassandra/cassandra-env.sh to uncomment and replace the following line:
# JVM_OPTS="$JVM_OPTS -Djava.rmi.server.hostname=<public name>"
with the line:
JVM_OPTS="$JVM_OPTS -Djava.rmi.server.hostname=127.0.0.1"
For our exploration, we will be downloading and using the official docker image cassandra for Apache Cassandra.
To pull and download the docker image for cassandra, execute the following command:
$ docker pull cassandra:5.0
The following should be the typical output:
5.0: Pulling from library/cassandra 7a2c55901189: Pull complete 875b30e249cd: Pull complete cabab1ce7888: Pull complete a993c8646506: Pull complete f9c0e45100d9: Pull complete 2614e7ad90d5: Pull complete 3d7a82bb0214: Pull complete 2f49febc123d: Pull complete 37fb126206c6: Pull complete 3accb547e8fc: Pull complete Digest: sha256:41aedccbe44efc557044df7c7b56d1fbb17c750c501df81f08b13a48c6826ce2 Status: Downloaded newer image for cassandra:5.0 docker.io/library/cassandra:5.0
To create a docker network for cassandra, execute the following command:
$ docker network create cassandra-db-net
The following would be the typical output:
be0f828bc6843dd9270c991dab06ee18935c20477003a7bf6fb96076fa984f7f
To start a single node Apache Cassandra cluster, execute the following command:
$ docker run --rm --name cas-node-1 --hostname cas-node-1 --network cassandra-db-net -p 7199:7199 -p 9042:9042 -u $(id -u $USER):$(id -g $USER) -v $CASSANDRA_HOME/data:/var/lib/cassandra/data -v $CASSANDRA_HOME/etc/cassandra:/etc/cassandra -v $CASSANDRA_HOME/logs:/opt/cassandra/logs cassandra:5.0
The following would be the typical trimmed output:
INFO [main] 2023-11-23 17:43:32,926 YamlConfigurationLoader.java:101 - Configuration location: file:/etc/cassandra/cassandra.yaml ... [ SNIP ] ... INFO [main] 2023-11-23 17:43:33,444 CassandraDaemon.java:601 - Hostname: cas-node-1:7000:7001 INFO [main] 2023-11-23 17:43:33,445 CassandraDaemon.java:608 - JVM vendor/version: OpenJDK 64-Bit Server VM/17.0.9 ... [ SNIP ] ... INFO [main] 2023-11-23 17:43:33,889 Keyspace.java:366 - Creating replication strategy system params KeyspaceParams{durable_writes=true, replication=ReplicationParams{class=org.apache.cassandra.locator.LocalStrategy}} INFO [main] 2023-11-23 17:43:33,908 ColumnFamilyStore.java:495 - Initializing system.IndexInfo INFO [main] 2023-11-23 17:43:34,430 ColumnFamilyStore.java:495 - Initializing system.batches INFO [main] 2023-11-23 17:43:34,433 ColumnFamilyStore.java:495 - Initializing system.paxos INFO [main] 2023-11-23 17:43:34,437 SecondaryIndexManager.java:225 - Index [PaxosUncommittedIndex] registered and writable. INFO [SecondaryIndexManagement:1] 2023-11-23 17:43:34,440 SecondaryIndexManager.java:1824 - Index [PaxosUncommittedIndex] became queryable after successful build. INFO [main] 2023-11-23 17:43:34,442 ColumnFamilyStore.java:495 - Initializing system.paxos_repair_history INFO [main] 2023-11-23 17:43:34,445 ColumnFamilyStore.java:495 - Initializing system.local INFO [main] 2023-11-23 17:43:34,448 ColumnFamilyStore.java:495 - Initializing system.peers_v2 INFO [main] 2023-11-23 17:43:34,450 ColumnFamilyStore.java:495 - Initializing system.peers INFO [main] 2023-11-23 17:43:34,453 ColumnFamilyStore.java:495 - Initializing system.peer_events_v2 INFO [main] 2023-11-23 17:43:34,456 ColumnFamilyStore.java:495 - Initializing system.peer_events INFO [main] 2023-11-23 17:43:34,460 ColumnFamilyStore.java:495 - Initializing system.compaction_history INFO [main] 2023-11-23 17:43:34,464 ColumnFamilyStore.java:495 - Initializing system.sstable_activity INFO [main] 2023-11-23 17:43:34,467 ColumnFamilyStore.java:495 - Initializing system.sstable_activity_v2 INFO [main] 2023-11-23 17:43:34,471 ColumnFamilyStore.java:495 - Initializing system.size_estimates INFO [main] 2023-11-23 17:43:34,475 ColumnFamilyStore.java:495 - Initializing system.table_estimates INFO [main] 2023-11-23 17:43:34,479 ColumnFamilyStore.java:495 - Initializing system.available_ranges_v2 INFO [main] 2023-11-23 17:43:34,482 ColumnFamilyStore.java:495 - Initializing system.available_ranges INFO [main] 2023-11-23 17:43:34,486 ColumnFamilyStore.java:495 - Initializing system.transferred_ranges_v2 INFO [main] 2023-11-23 17:43:34,489 ColumnFamilyStore.java:495 - Initializing system.transferred_ranges INFO [main] 2023-11-23 17:43:34,493 ColumnFamilyStore.java:495 - Initializing system.view_builds_in_progress INFO [main] 2023-11-23 17:43:34,498 ColumnFamilyStore.java:495 - Initializing system.built_views INFO [main] 2023-11-23 17:43:34,501 ColumnFamilyStore.java:495 - Initializing system.prepared_statements INFO [main] 2023-11-23 17:43:34,505 ColumnFamilyStore.java:495 - Initializing system.repairs INFO [main] 2023-11-23 17:43:34,508 ColumnFamilyStore.java:495 - Initializing system.top_partitions INFO [main] 2023-11-23 17:43:34,525 QueryProcessor.java:127 - Initialized prepared statement caches with 62 MiB INFO [main] 2023-11-23 17:43:34,567 Keyspace.java:366 - Creating replication strategy system_schema params KeyspaceParams{durable_writes=true, replication=ReplicationParams{class=org.apache.cassandra.locator.LocalStrategy}} INFO [main] 2023-11-23 17:43:34,569 ColumnFamilyStore.java:495 - Initializing system_schema.keyspaces INFO [main] 2023-11-23 17:43:34,574 ColumnFamilyStore.java:495 - Initializing system_schema.tables INFO [main] 2023-11-23 17:43:34,578 ColumnFamilyStore.java:495 - Initializing system_schema.columns INFO [main] 2023-11-23 17:43:34,581 ColumnFamilyStore.java:495 - Initializing system_schema.column_masks INFO [main] 2023-11-23 17:43:34,585 ColumnFamilyStore.java:495 - Initializing system_schema.triggers INFO [main] 2023-11-23 17:43:34,588 ColumnFamilyStore.java:495 - Initializing system_schema.dropped_columns INFO [main] 2023-11-23 17:43:34,591 ColumnFamilyStore.java:495 - Initializing system_schema.views INFO [main] 2023-11-23 17:43:34,595 ColumnFamilyStore.java:495 - Initializing system_schema.types INFO [main] 2023-11-23 17:43:34,598 ColumnFamilyStore.java:495 - Initializing system_schema.functions INFO [main] 2023-11-23 17:43:34,601 ColumnFamilyStore.java:495 - Initializing system_schema.aggregates INFO [main] 2023-11-23 17:43:34,604 ColumnFamilyStore.java:495 - Initializing system_schema.indexes ... [ SNIP ] ... INFO [main] 2023-11-23 17:44:21,938 Keyspace.java:366 - Creating replication strategy system_auth params KeyspaceParams{durable_writes=true, replication=ReplicationParams{class=org.apache.cassandra.locator.SimpleStrategy, replication_factor=1}} INFO [main] 2023-11-23 17:44:21,940 ColumnFamilyStore.java:495 - Initializing system_auth.roles INFO [main] 2023-11-23 17:44:21,942 ColumnFamilyStore.java:495 - Initializing system_auth.role_members INFO [main] 2023-11-23 17:44:21,945 ColumnFamilyStore.java:495 - Initializing system_auth.role_permissions INFO [main] 2023-11-23 17:44:21,947 ColumnFamilyStore.java:495 - Initializing system_auth.resource_role_permissons_index INFO [main] 2023-11-23 17:44:21,950 ColumnFamilyStore.java:495 - Initializing system_auth.network_permissions INFO [main] 2023-11-23 17:44:21,952 ColumnFamilyStore.java:495 - Initializing system_auth.cidr_permissions INFO [main] 2023-11-23 17:44:21,955 ColumnFamilyStore.java:495 - Initializing system_auth.cidr_groups INFO [main] 2023-11-23 17:44:21,957 ColumnFamilyStore.java:495 - Initializing system_auth.identity_to_role INFO [main] 2023-11-23 17:44:21,960 StorageService.java:1961 - JOINING: Finish joining ring ... [ SNIP ] ... INFO [main] 2023-11-23 17:44:30,110 PipelineConfigurator.java:131 - Starting listening for CQL clients on /0.0.0.0:9042 (unencrypted)... INFO [main] 2023-11-23 17:44:30,113 CassandraDaemon.java:743 - Startup complete ... [ SNIP ] ...
At this point a single node Apache Cassandra cluster should be ready for use.
Concepts - Level I
This section will cover some basic concepts of Cassandra:
A Column (or a Cell) is the most basic unit of data in Cassandra. It has a name and an associated value
A Row is a container of ordered Columns. Each Row has an associated unique Primary Key (or Row Key)
A Table (or a Column Family) is a container of ordered Rows
A Keyspace is a container of Tables. Think of it as analogous to a Schema from the relational database world
CQL (or Cassandra Query Language) is SQL like interface for working with Cassandra
CQL uses SQL like statements (create, alter, drop) to either define, change, or delete Tables in Cassandra
CQL uses SQL like statements (insert, update, select, delete) to either create, change, or delete Rows in Cassandra Tables
Cassandra is different from any Relational database in the sense that there is no concept of table joins and hence CQL does not have JOINs unlike SQL
CQL supports the following data types for Column values:
boolean :: true or false
int :: 32-bit integer
bigint :: 64-bit integer
varint :: Arbitrary precision integer
float :: 4-byte float
double :: 8-byte float
decimal :: Arbitrary precision decimal
blob :: Bytes in Hexadecimal. This is the default type
ascii :: ASCII encoded string
varchar :: UTF8 encoded string
text :: UTF8 encoded string
timestamp :: 8-byte date plus time as seconds since epoch
uuid :: 4-byte uuid
Hands-on with Cassandra - I
The best way to explore Cassandra is to use the Cassandra CQL command-line interface called cqlsh.
To work with CQL, execute the following command:
$ docker run -it --rm --name cassandra-client --network cassandra-db-net cassandra:5.0 cqlsh cas-node-1
The following will be the output:
WARNING: cqlsh was built against 5.0-alpha2, but this server is 5.0. All features may not work! Connected to Cassandra Cluster at cas-node-1:9042 [cqlsh 6.2.0 | Cassandra 5.0-alpha2 | CQL spec 3.4.7 | Native protocol v5] Use HELP for help. cqlsh>
On success, CQL will change the command prompt to "cqlsh>".
To exit CQL, input the following command at the "cqlsh>" prompt:
cqlsh> exit;
To get help at any time in CQL, input the following command at the "cqlsh> " prompt:
cqlsh> help
The following will be the output:
Documented shell commands: =========================== CAPTURE CLS COPY DESCRIBE EXPAND HISTORY PAGING SHOW TRACING CLEAR CONSISTENCY DESC EXIT HELP LOGIN SERIAL SOURCE UNICODE CQL help topics: ================ AGGREGATES CREATE_KEYSPACE DROP_TRIGGER TEXT ALTER_KEYSPACE CREATE_MATERIALIZED_VIEW DROP_TYPE TIME ALTER_MATERIALIZED_VIEW CREATE_ROLE DROP_USER TIMESTAMP ALTER_TABLE CREATE_TABLE FUNCTIONS TRUNCATE ALTER_TYPE CREATE_TRIGGER GRANT TYPES ALTER_USER CREATE_TYPE INSERT UPDATE APPLY CREATE_USER INSERT_JSON USE ASCII DATE INT UUID BATCH DELETE JSON BEGIN DROP_AGGREGATE KEYWORDS BLOB DROP_COLUMNFAMILY LIST_PERMISSIONS BOOLEAN DROP_FUNCTION LIST_ROLES COUNTER DROP_INDEX LIST_USERS CREATE_AGGREGATE DROP_KEYSPACE PERMISSIONS CREATE_COLUMNFAMILY DROP_MATERIALIZED_VIEW REVOKE CREATE_FUNCTION DROP_ROLE SELECT CREATE_INDEX DROP_TABLE SELECT_JSON
To create a Keyspace called mytestks, input the following command at the "cqlsh>" prompt:
cqlsh> CREATE KEYSPACE IF NOT EXISTS mytestks WITH replication = {'class': 'SimpleStrategy', 'replication_factor': 1};
There will be no output.
Once a Keyspace is created, one needs to select the Keyspace for use. To use the Keyspace called mytestks, input the following command at the "cqlsh>" prompt:
cqlsh> USE mytestks;
There will be no output and the input prompt would change to "cqlsh:mytestks>".
To create a Table called book_catalog, input the following command at the "cqlsh:mytestks>" prompt:
cqlsh:mytestks> CREATE TABLE IF NOT EXISTS book_catalog (isbn text, title text, year int, price float, PRIMARY KEY (isbn));
There will be no output.
To insert a row into the table book_catalog, input the following command at the " cqlsh:mytestks>" prompt:
cqlsh:mytestks> INSERT INTO book_catalog (isbn) VALUES ('ISBN-111');
There will be no output.
With the INSERT statement, the first column name in parenthesis after the column family name has to be the row key (primary key) column. In our example, the primary key is the column isbn.
To select all the rows from the table book_catalog, input the following command at the "cqlsh:mytestks>" prompt:
SELECT * FROM book_catalog;
The following will be the output:
isbn | price | title | year ---------+-------+-------+------ ISBN-111 | null | null | null (1 rows)
Let us try to update the values of the columns price, title, and year for the row in book_catalog whose primary key has a value of ISBN-111. To do that, input the following command at the "cqlsh:mytestks>" prompt:
cqlsh:mytestks> UPDATE book_catalog SET price = 2.99, title = 'Cassandra Quick Notes', year = 2023 WHERE isbn = 'ISBN-111';
There will be no output.
Let us insert 2 more rows into the table book_catalog by inputting the following commands at the "cqlsh:mytestks>" prompt:
cqlsh:mytestks> INSERT INTO book_catalog (isbn, title, year, price) VALUES ('ISBN-222', 'Cassandra Guide', 2021, 4.99);
cqlsh:mytestks> INSERT INTO book_catalog (isbn, title, year, price) VALUES ('ISBN-333', 'Cassandra For Developers', 2019, 3.99);
There will be no output.
To select all the rows from the table book_catalog, input the following command at the "cqlsh:mytestks>" prompt:
cqlsh:mytestks> SELECT * FROM book_catalog;
The following will be the output:
isbn | price | title | year ----------+-------+--------------------------+------ ISBN-333 | 3.99 | Cassandra For Developers | 2019 ISBN-111 | 2.99 | Cassandra Quick Notes | 2023 ISBN-222 | 4.99 | Cassandra Guide | 2021 (3 rows)
By default, the select of all the rows from a table returns upto 10000 rows. To limit the number of rows returned, use the LIMIT clause. To SELECT all the rows from the table book_catalog with a limit of 1 row, input the following command at the "cqlsh:mytestks> " prompt:
cqlsh:mytestks> SELECT * FROM book_catalog LIMIT 1;
The following will be the output:
isbn | price | title | year ----------+-------+--------------------------+------ ISBN-333 | 3.99 | Cassandra For Developers | 2019 (1 rows)
To select just the columns title and price for all the rows from the table book_catalog, input the following command at the "cqlsh:mytestks>" prompt:
cqlsh:mytestks> SELECT title, price FROM book_catalog;
The following will be the output:
title | price --------------------------+------- Cassandra For Developers | 3.99 Cassandra Quick Notes | 2.99 Cassandra Guide | 4.99 (3 rows)
To add a new column called publisher of type text to the table book_catalog, input the following command at the "cqlsh:mytestks>" prompt:
cqlsh:mytestks> ALTER TABLE book_catalog ADD publisher text;
There will be no output.
To check if the column publisher has been added to the table book_catalog, input the following command at the "cqlsh:mytestks>" prompt:
cqlsh:mytestks> DESCRIBE TABLE book_catalog;
The following will be the output:
CREATE TABLE mytestks.book_catalog ( isbn text PRIMARY KEY, price float, publisher text, title text, year int ) WITH additional_write_policy = '99p' AND allow_auto_snapshot = true AND bloom_filter_fp_chance = 0.01 AND caching = {'keys': 'ALL', 'rows_per_partition': 'NONE'} AND cdc = false AND comment = '' AND compaction = {'class': 'org.apache.cassandra.db.compaction.SizeTieredCompactionStrategy', 'max_threshold': '32', 'min_threshold': '4'} AND compression = {'chunk_length_in_kb': '16', 'class': 'org.apache.cassandra.io.compress.LZ4Compressor'} AND memtable = 'default' AND crc_check_chance = 1.0 AND default_time_to_live = 0 AND extensions = {} AND gc_grace_seconds = 864000 AND incremental_backups = true AND max_index_interval = 2048 AND memtable_flush_period_in_ms = 0 AND min_index_interval = 128 AND read_repair = 'BLOCKING' AND speculative_retry = '99p';
Now let us SELECT all the rows to check the value of the column publisher that was added to the table book_catalog. To do that, input the following command at the "cqlsh:mytestks> " prompt:
cqlsh:mytestks> SELECT * FROM book_catalog;
The following will be the output:
isbn | price | publisher | title | year ----------+-------+------------+--------------------------+------ ISBN-333 | 3.99 | null | Cassandra For Developers | 2019 ISBN-111 | 2.99 | Polarsparc | Cassandra Quick Notes | 2023 ISBN-222 | 4.99 | null | Cassandra Guide | 2021 (3 rows)
As we can see, the output shows null value for each row of the column publisher.
Let us try to update the value of the column publisher for all the rows in the table book_catalog. To do that, input the following command at the "cqlsh:mytestks>" prompt:
cqlsh:mytestks> UPDATE book_catalog SET publisher = 'Polarsparc';
The following will be the output:
SyntaxException: line 1:48 mismatched input ';' expecting K_WHERE
In Cassandra, one has to update a column value for each row specifying the primary key. This makes sense as Cassandra is a column-oriented distributed database and not all rows need to have all the columns unlike Relational databases.
To update the value of the column publisher for the row with isbn = 'ISBN-111' in the table book_catalog, input the following command at the "cqlsh:mytestks>" prompt:
cqlsh:mytestks> UPDATE book_catalog SET publisher = 'Polarsparc' WHERE isbn = 'ISBN-111';
There will be no output.
Let us now try to SELECT all the rows from the table book_catalog. To do that, input the following command at the "cqlsh:mytestks>" prompt:
cqlsh:mytestks> SELECT * FROM book_catalog;
The following will be the output:
isbn | price | publisher | title | year ----------+-------+------------+--------------------------+------ ISBN-333 | 3.99 | null | Cassandra For Developers | 2019 ISBN-111 | 2.99 | Polarsparc | Cassandra Quick Notes | 2023 ISBN-222 | 4.99 | null | Cassandra Guide | 2021 (3 rows)
Let us now try to SELECT all the rows with the condition year = 2021 from the table book_catalog. To do that, input the following command at the "cqlsh:mytestks>" prompt:
cqlsh:mytestks> SELECT * FROM book_catalog WHERE year = 2021;
The following will be the output:
InvalidRequest: Error from server: code=2200 [Invalid query] message="Cannot execute this query as it might involve data filtering and thus may have unpredictable performance. If you want to execute this query despite the performance unpredictability, use ALLOW FILTERING"
The error indicates that we have not created an index on the column year.
To create a seconadry index on the column year called year_idx for the table book_catalog, input the following command at the "cqlsh:mytestks> " prompt:
cqlsh:mytestks> CREATE INDEX year_idx ON book_catalog (year);
There will be no output.
Now let us re-execute the SELECT of all the rows with the condition year = 2021 from the table book_catalog. To do that, input the following command at the "cqlsh:mytestks> " prompt:
cqlsh:mytestks> SELECT * FROM book_catalog WHERE year = 2021;
The following will be the output:
isbn | price | publisher | title | year ----------+-------+-----------+-----------------+------ ISBN-222 | 4.99 | null | Cassandra Guide | 2021 (1 rows)
To drop the column publisher from the table book_catalog, input the following command at the "cqlsh:mytestks>" prompt:
cqlsh:mytestks> ALTER TABLE book_catalog DROP publisher;
There will be no output.
To drop the secondary index called year_idx on the column year from the table book_catalog, input the following command at the "cqlsh:mytestks> " prompt:
cqlsh:mytestks> DROP INDEX year_idx;
There will be no output.
To INSERT a new row into the table book_catalog with values for the columns isbn and year that will be alive for only 30 seconds, input the following command at the "cqlsh:mytestks>" prompt:
cqlsh:mytestks> INSERT INTO book_catalog (isbn, year) VALUES ('ISBN-555', 2022) USING TTL 30;
There will be no output.
Now let us SELECT all the rows from the table book_catalog. To do that, input the following command at the "cqlsh:mytestks>" prompt:
cqlsh:mytestks> SELECT * FROM book_catalog;
The following will be the output:
isbn | price | title | year ----------+-------+--------------------------+------ ISBN-333 | 3.99 | Cassandra For Developers | 2019 ISBN-111 | 2.99 | Cassandra Quick Notes | 2023 ISBN-555 | null | null | 2022 ISBN-222 | 4.99 | Cassandra Guide | 2021 (4 rows)
Wait for about 30 seconds and re-execute the above SELECT command from the table book_catalog. To do that, input the following command at the "cqlsh:mytestks>" prompt:
cqlsh:mytestks> SELECT * FROM book_catalog;
The following will be the output:
isbn | price | title | year ----------+-------+--------------------------+------ ISBN-333 | 3.99 | Cassandra For Developers | 2019 ISBN-111 | 2.99 | Cassandra Quick Notes | 2023 ISBN-222 | 4.99 | Cassandra Guide | 2021 (3 rows)
To delete one or more columns from the table book_catalog, input the following command at the "cqlsh:mytestks>" prompt:
cqlsh:mytestks> DELETE price, year FROM book_catalog WHERE isbn = 'ISBN-333';
There will be no output.
Now let us SELECT all the rows from the table book_catalog. To do that, input the following command at the "cqlsh:mytestks>" prompt:
cqlsh:mytestks> SELECT * FROM book_catalog;
The following will be the output:
isbn | price | title | year ----------+-------+--------------------------+------ ISBN-333 | null | Cassandra For Developers | null ISBN-111 | 2.99 | Cassandra Quick Notes | 2023 ISBN-222 | 4.99 | Cassandra Guide | 2021 (3 rows)
To delete the entire row for the primary key isbn with a value of "ISBN-333" from the table book_catalog, input the following command at the "cqlsh:mytestks> " prompt:
cqlsh:mytestks> DELETE FROM book_catalog WHERE isbn = 'ISBN-333';
There will be no output.
Now let us SELECT all the rows from the table book_catalog. To do that, input the following command at the "cqlsh:mytestks>" prompt:
cqlsh:mytestks> SELECT * FROM book_catalog;
The following will be the output:
isbn | price | title | year ----------+-------+--------------------------+------ ISBN-111 | 2.99 | Cassandra Quick Notes | 2023 ISBN-222 | 4.99 | Cassandra Guide | 2021 (2 rows)
To drop the entire table book_catalog, input the following command at the " cqlsh:mytestks>" prompt:
cqlsh:mytestks> DROP TABLE book_catalog;
There will be no output.
Now let us SELECT all the rows from the table book_catalog. To do that, input the following command at the "cqlsh:mytestks>" prompt:
cqlsh:mytestks> SELECT * FROM book_catalog;
The following will be the output:
InvalidRequest: Error from server: code=2200 [Invalid query] message="table book_catalog does not exist"
To drop the entire keyspace mytestks, input the following command at the " cqlsh:mytestks>" prompt:
cqlsh:mytestks> DROP KEYSPACE mytestks;
There will be no output.
Now let us try to gather information about the keyspace mytestks. To do that, input the following command at the "cqlsh:mytestks>" prompt:
cqlsh:mytestks> DESCRIBE mytestks;
The following will be the output:
'mytestks' not found in keyspaces
To exit the CQL command-line interface, input the following command at the " cqlsh:mytestks>" prompt:
cqlsh:mytestks> exit;
There will be no output.
This concludes the hands-on demonstration for this part in setting and using a single-node Apache Cassandra !!!
References