liveBook · Manning

Cassandra Query Language

As explained in Spring in Action, Sixth Edition

CQL is Cassandra Query Language, the language for defining, querying, and modifying Cassandra data and schemas.

Cassandra Query Language (CQL) defines, queries, and modifies Cassandra data and schemas. Its command-line shell, cqlsh, provides a practical way to prepare a keyspace and inspect persisted rows. section 4.1.1 section 4.1.3

A small Cassandra application workflow uses CQL to:

  • Create a keyspace that groups Cassandra tables, using replication settings and durable writes. section 4.1.1
  • Query table rows through cqlsh, including simple columns and collections containing user-defined values. section 4.1.3
  • Prepare the keyspace that Spring Data Cassandra uses through application configuration. section 4.1.1

Creating and inspecting Taco Cloud data

At the cqlsh prompt, create the tacocloud keyspace with SimpleStrategy, one replica, and durable writes. Then query the tacos table with `select id, name, createdAt, ingredients from tacos;`. The ingredients value appears as a collection of user-defined ingredient objects. section 4.1.1 section 4.1.3

cqlsh> create keyspace tacocloud
   ... with replication={'class':'SimpleStrategy', 'replication_factor':1}
   ... and durable_writes=true;

View the complete cqlsh command for creating the tacocloud keyspace. section 4.1.1

cqlsh:tacocloud> select id, name, createdAt, ingredients from tacos;
 
 id       | name      | createdat | ingredients
----------+-----------+-----------+----------------------------------------
 827390...| Carnivore | 2018-04...| [{name: 'Flour Tortilla', type: 'WRAP'},
                                     {name: 'Carnitas', type: 'PROTEIN'},
                                     {name: 'Sour Cream', type: 'SAUCE'},
                                     {name: 'Salsa', type: 'SAUCE'},
                                     {name: 'Cheddar', type: 'CHEESE'}]
 
(1 rows)

View a complete CQL query and its returned taco row with embedded ingredients. section 4.1.3

How Spring in Action, Sixth Edition covers it

How deep it goes
Defines keyspace creation and table queries with working commands, but defers broader CQL syntax and replication details.
Examples
Uses the tacocloud keyspace and a tacos query returning embedded ingredient user-defined types.
What it assumes
Assumes a running Cassandra node and introduces keyspaces, replication settings, cqlsh, and Spring Cassandra configuration.
What you can do after
Operate/configure Cassandra by creating a keyspace and querying persisted rows with cqlsh.
How it connects
Connects CQL with Cassandra, keyspaces, tables, cqlsh, user-defined types, and Spring Data Cassandra.

Also explained in

Compare how 2 books explain Cassandra Query Language →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Spring in Action, Sixth Edition. The section links point to the parts of the book it draws on.