### CQL CREATE CUSTOM INDEX Examples Source: https://docs.datastax.com/en/cql-oss/3.1/cql/cql_reference/create_index_r Examples demonstrating how to create custom indexes in CQL. These examples show the use of the USING clause to specify a Java class and the WITH OPTIONS clause for additional configuration. ```cql CREATE CUSTOM INDEX ON users (email) USING 'path.to.the.IndexClass'; ``` ```cql CREATE CUSTOM INDEX ON users (email) USING 'path.to.the.IndexClass' WITH OPTIONS = {'storage': '/mnt/ssd/indexes/'}; ``` -------------------------------- ### CQL Keyspace Replication Map Examples Source: https://docs.datastax.com/en/cql-oss/3.1/cql/cql_reference/create_keyspace_r Provides examples of the map properties and values for defining keyspace replication strategies. It includes configurations for SimpleStrategy and NetworkTopologyStrategy. ```cql { 'class' : 'SimpleStrategy', 'replication_factor' : }; ``` ```cql { 'class' : 'NetworkTopologyStrategy'[, '' : , '' : ] . . . }; ``` -------------------------------- ### CQL CREATE KEYSPACE with SimpleStrategy Example Source: https://docs.datastax.com/en/cql-oss/3.1/cql/cql_reference/create_keyspace_r An example of creating a new keyspace named 'Excelsior' using the SimpleStrategy replication class with a replication factor of 3. This is suitable for evaluation but not production with mixed workloads. ```cql CREATE KEYSPACE Excelsior WITH REPLICATION = { 'class' : 'SimpleStrategy', 'replication_factor' : 3 }; ``` -------------------------------- ### CQL Table Definition Example Source: https://docs.datastax.com/en/cql-oss/3.1/cql/cql_reference/cql_function_r An example of a CQL table definition for a 'users' table. This is used in conjunction with the `token()` function to illustrate partition key usage. ```cql CREATE TABLE users ( userid text PRIMARY KEY, username text, ... ) ``` -------------------------------- ### CQL DESCRIBE KEYSPACE Example Source: https://docs.datastax.com/en/cql-oss/3.1/cql/cql_reference/describe_r Example of using the DESCRIBE KEYSPACE command to retrieve CQL commands for a specific keyspace. These commands can be used to recreate the keyspace and its associated tables. ```cql DESCRIBE KEYSPACE cycling; ``` -------------------------------- ### CQL DESCRIBE INDEX Example Source: https://docs.datastax.com/en/cql-oss/3.1/cql/cql_reference/describe_r Example of using the DESCRIBE INDEX command to retrieve the CQL command for a specific index. This command can be used to recreate the index. ```cql DESCRIBE INDEX team_entry; ``` -------------------------------- ### CQL DESCRIBE TABLE Example Source: https://docs.datastax.com/en/cql-oss/3.1/cql/cql_reference/describe_r Example of using the DESCRIBE TABLE command to retrieve the CQL command for a specific table. This command can be used to recreate the table structure. ```cql DESCRIBE TABLE upcoming_calendar; ``` -------------------------------- ### Example: Altering Keyspace Replication Strategy Source: https://docs.datastax.com/en/cql-oss/3.1/cql/cql_reference/alter_keyspace_r An example demonstrating how to change the replication strategy of a keyspace named 'Excalibur' to use NetworkTopologyStrategy with a replication factor of 3 in 'datacenter1'. This illustrates the practical application of the ALTER KEYSPACE command. ```cql ALTER KEYSPACE "Excalibur" WITH REPLICATION = { 'class' : 'NetworkTopologyStrategy', 'datacenter1' : 3 }; ``` -------------------------------- ### Example of Creating a Trigger - CQL Source: https://docs.datastax.com/en/cql-oss/3.1/cql/cql_reference/trigger_r Provides a concrete example of the CREATE TRIGGER statement in CQL. This example demonstrates how to specify a trigger name ('myTrigger'), the target table ('myTable'), and the fully qualified name of the Java class ('org.apache.cassandra.triggers.AuditTrigger') that contains the trigger logic. ```cql CREATE TRIGGER myTrigger ON myTable USING 'org.apache.cassandra.triggers.AuditTrigger' ``` -------------------------------- ### CQL CREATE INDEX on Table Columns Source: https://docs.datastax.com/en/cql-oss/3.1/cql/cql_reference/create_index_r Example of creating a table and then defining indexes on specific columns. This demonstrates the basic syntax for indexing regular table columns. ```cql CREATE TABLE myschema.users ( userID uuid, fname text, lname text, email text, address text, zip int, state text, PRIMARY KEY (userID) ); CREATE INDEX user_state ON myschema.users (state); CREATE INDEX ON myschema.users (zip); ``` -------------------------------- ### Creating an index on a column Source: https://docs.datastax.com/en/cql-oss/3.1/cql/cql_reference/create_index_r Example of creating a standard index on a regular column within a table. ```APIDOC ## Creating an index on a column ### Description This example demonstrates how to create a standard index on a regular column of a table. ### Method CQL Statement ### Endpoint N/A (CQL Command) ### Parameters None ### Request Example ```cql -- First, define a table CREATE TABLE myschema.users ( userID uuid, fname text, lname text, email text, address text, zip int, state text, PRIMARY KEY (userID) ); -- Then, create an index on the 'state' column CREATE INDEX user_state ON myschema.users (state); -- Create another index on the 'zip' column without a specific index name CREATE INDEX ON myschema.users (zip); ``` ### Response Success is indicated by the absence of errors during statement execution. ``` -------------------------------- ### Start cqlsh Interactive Terminal Source: https://docs.datastax.com/en/cql-oss/3.1/cql/cql_reference/cqlsh Starts the cqlsh utility, a Python-based command-line client for executing Cassandra Query Language (CQL) commands. The syntax may vary slightly between operating systems. ```shell cqlsh [options] [host [port]] ``` ```python python cqlsh [options] [host [port]] ``` -------------------------------- ### CQL DESCRIBE CLUSTER Example Source: https://docs.datastax.com/en/cql-oss/3.1/cql/cql_reference/describe_r Example of using the DESCRIBE CLUSTER command to retrieve information about the connected Apache Cassandra cluster. This output typically includes the cluster name, partitioner, and snitch, and may also show endpoint-range ownership information. ```cql DESCRIBE CLUSTER; ``` -------------------------------- ### Interactive CQL Session Example Source: https://docs.datastax.com/en/cql-oss/3.1/cql/cql_reference/cqlsh Demonstrates an interactive CQL session, showing connection details, prompt changes after selecting a keyspace, and executing a multi-line SELECT statement. ```cql cqlsh 1.2.3.4 9042 -u jdoe -p mypassword Connected to trace_consistency at 1.2.3.4:9042. [cqlsh 5.0.1 | Cassandra 2.1.0 | CQL spec 3.2 | Native protocol v3] Use HELP for help. cqlsh>USE mykeyspace; cqlsh:mykeyspace> SELECT * FROM demo_table ... WHERE id = 0; ``` -------------------------------- ### CQL DESCRIBE TYPE Example Source: https://docs.datastax.com/en/cql-oss/3.1/cql/cql_reference/describe_r Example of using the DESCRIBE TYPE command to retrieve the CQL command for a specific user-defined type. This command can be used to recreate the user-defined type. ```cql DESCRIBE TYPE basic_info; ``` -------------------------------- ### CQL Comments Syntax Source: https://docs.datastax.com/en/cql-oss/3.1/cql/cql_reference/tabProp Illustrates the syntax for single-line and multi-line comments in CQL. Single-line comments start with '--' or '//', and multi-line comments are enclosed in '/* */'. ```cql -- This is a single-line comment // This is another single-line comment /* This is a multi-line comment that spans across several lines. */ ``` -------------------------------- ### Configure Compression and Compaction for a Table in CQL Source: https://docs.datastax.com/en/cql-oss/3.1/cql/cql_reference/refSetTabProp Shows how to configure compression and compaction strategies for a table using property maps in the WITH clause. This example specifies the compressor and chunk length for compression, and the compaction strategy and threshold. ```cql CREATE TABLE DogTypes ( block_id uuid, species text, alias text, population varint, PRIMARY KEY (block_id) ) WITH compression = { 'sstable_compression' : 'DeflateCompressor', 'chunk_length_kb' : 64 } AND compaction = { 'class' : 'SizeTieredCompactionStrategy', 'min_threshold' : 6 }; ``` -------------------------------- ### Example CREATE TABLE with Properties (CQL) Source: https://docs.datastax.com/en/cql-oss/3.1/cql/cql_reference/alter_table_r This is an example of a CREATE TABLE statement that includes various properties such as bloom_filter_fp_chance, caching, comment, compaction, compression, default_time_to_live, gc_grace_seconds, and read_repair_chance. It reflects the settings that can be modified using ALTER TABLE. ```cql CREATE TABLE mykeyspace.users ( user_name text PRIMARY KEY, bio blob ) WITH bloom_filter_fp_chance = 0.01 AND caching = '{"keys":"NONE", "rows_per_partition":"25"}' 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 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.1 AND speculative_retry = '99.0PERCENTILE'; ``` -------------------------------- ### Example: Create Table with Collection Types Source: https://docs.datastax.com/en/cql-oss/3.1/cql/cql_reference/create_table_r Demonstrates how to create a 'users' table in CQL, including columns for different collection types: set, list, and map. ```cql CREATE TABLE users ( userid text PRIMARY KEY, first_name text, last_name text, emails set, top_scores list, todo map ); ``` -------------------------------- ### CQL ALTER TABLE Example: Add Column Source: https://docs.datastax.com/en/cql-oss/3.1/cql/cql_reference/alter_table_r Shows how to add a new column to an existing table using the ALTER TABLE command with the ADD instruction. This example adds a 'firstname' column of type 'text'. ```cql ALTER TABLE cycling.cyclist_races ADD firstname text; ``` -------------------------------- ### CQL SELECT with Keyspace Specification Example Source: https://docs.datastax.com/en/cql-oss/3.1/cql/cql_reference/select_r Demonstrates how to specify a keyspace along with the table name in the FROM clause of a CQL SELECT statement. This example counts rows in the 'IndexInfo' table within the 'system' keyspace. ```cql SELECT COUNT(*) FROM system."IndexInfo"; ``` -------------------------------- ### Create Keyspace with NetworkTopologyStrategy (Single Datacenter) Source: https://docs.datastax.com/en/cql-oss/3.1/cql/cql_reference/create_keyspace_r Creates a keyspace named NTSkeyspace using NetworkTopologyStrategy with one replica in 'datacenter1'. This is suitable for single-node or evaluation setups. ```cql CREATE KEYSPACE NTSkeyspace WITH REPLICATION = { 'class' : 'NetworkTopologyStrategy', 'datacenter1' : 1 }; ``` -------------------------------- ### Creating an index on a collection Source: https://docs.datastax.com/en/cql-oss/3.1/cql/cql_reference/create_index_r Example of creating an index on a collection type (set or map) in Cassandra 2.1 and later. ```APIDOC ## Creating an index on a collection ### Description This example demonstrates how to create an index on a collection column (like a set or map) in Cassandra versions 2.1 and later. ### Method CQL Statement ### Endpoint N/A (CQL Command) ### Parameters None ### Request Example ```cql -- Assume 'users' table exists. First, add a collection column. ALTER TABLE users ADD phones set; -- Create an index on the 'phones' set collection CREATE INDEX ON users (phones); -- Example for indexing map values (if 'users' table had a map like 'tags map') -- CREATE INDEX ON users (tags); -- To index map keys, use KEYS() -- CREATE INDEX ON users (KEYS(tags)); ``` ### Response Success is indicated by the absence of errors during statement execution. ``` -------------------------------- ### Creating an index on a clustering column Source: https://docs.datastax.com/en/cql-oss/3.1/cql/cql_reference/create_index_r Example of creating an index on a clustering column in a table with a composite primary key. ```APIDOC ## Creating an index on a clustering column ### Description This example shows how to create an index on a clustering column when the table has a composite primary key. ### Method CQL Statement ### Endpoint N/A (CQL Command) ### Parameters None ### Request Example ```cql -- Define a table with a composite primary key ((partition_key), clustering_key) CREATE TABLE mykeyspace.users ( userID uuid, fname text, lname text, email text, address text, zip int, state text, PRIMARY KEY ((userID, fname), state) ); -- Create an index on the clustering column 'state' CREATE INDEX ON mykeyspace.users (state); ``` ### Response Success is indicated by the absence of errors during statement execution. ``` -------------------------------- ### CQL CREATE INDEX on Clustering Column Source: https://docs.datastax.com/en/cql-oss/3.1/cql/cql_reference/create_index_r Example of creating a table with a composite primary key and then indexing a clustering column. This showcases how to index columns that are part of the table's clustering key. ```cql CREATE TABLE mykeyspace.users ( userID uuid, fname text, lname text, email text, address text, zip int, state text, PRIMARY KEY ((userID, fname), state) ); CREATE INDEX ON mykeyspace.users (state); ``` -------------------------------- ### CQL ALTER TABLE Example: Specify Keyspace Source: https://docs.datastax.com/en/cql-oss/3.1/cql/cql_reference/alter_table_r Demonstrates how to qualify a table name with its keyspace when using the ALTER TABLE command. This ensures the correct table is modified, especially in multi-keyspace environments. ```cql ALTER TABLE cycling.teams ALTER ID TYPE uuid; ``` -------------------------------- ### Grant ALL Permissions on a Keyspace - CQL Source: https://docs.datastax.com/en/cql-oss/3.1/cql/cql_reference/grant_r Example of granting all permissions on a specific keyspace to a user. This is typically used when no other user has broader ALL KEYSPACES access. ```cql GRANT ALL ON KEYSPACE keyspace_name TO user_name; ``` -------------------------------- ### CQL Blob Type and bigintAsBlob Function Example Source: https://docs.datastax.com/en/cql-oss/3.1/cql/cql_reference/blob_r Demonstrates the creation of a table with a blob column and the use of the bigintAsBlob function to insert a bigint value as a blob. It also shows how to select the data. ```cql CREATE TABLE bios ( user_name varchar PRIMARY KEY, bio blob ); INSERT INTO bios (user_name, bio) VALUES ('fred', bigintAsBlob(3)); SELECT * FROM bios; ``` -------------------------------- ### CQL CREATE INDEX on Collection Column Source: https://docs.datastax.com/en/cql-oss/3.1/cql/cql_reference/create_index_r Example of adding a collection column to a table and then creating an index on it. This illustrates how to index data within set or list collection types. ```cql ALTER TABLE users ADD phones set; CREATE INDEX ON users (phones); ``` -------------------------------- ### Configure Speculative Retry for Rapid Read Protection in Cassandra Source: https://docs.datastax.com/en/cql-oss/3.1/cql/cql_reference/tabProp This example shows how to configure the speculative retry setting for a Cassandra table. This feature helps protect against slow reads by sending additional read requests under certain conditions. ```cql ALTER TABLE users WITH speculative_retry = '10ms'; ALTER TABLE users WITH speculative_retry = '99percentile'; ``` -------------------------------- ### CQL Statement Examples Source: https://docs.datastax.com/en/cql-oss/3.1/cql/cql_reference/cql_lexicon_c Demonstrates valid CQL syntax for common operations like selecting and updating data. Statements are terminated by a semicolon and can span multiple lines. ```cql SELECT * FROM MyTable; UPDATE MyTable SET SomeColumn = 'SomeValue' WHERE columnName = B70DE1D0-9908-4AE3-BE34-5573E5B09F14; ``` -------------------------------- ### Create Table with Specific ID (CQL) Source: https://docs.datastax.com/en/cql-oss/3.1/cql/cql_reference/create_table_r This example illustrates creating a table and assigning it a specific ID using the `WITH ID` clause. This is beneficial for recreating a dropped table and ensuring data recovery through commitlog replay. ```cql CREATE TABLE users ( userid text PRIMARY KEY, emails set ) WITH ID='5a1c395e-b41f-11e5-9f22-ba0be0483c18'; ``` -------------------------------- ### Create table and copy data Source: https://docs.datastax.com/en/cql-oss/3.1/cql/cql_reference/copy_r Demonstrates creating a keyspace and table, inserting data, and then copying the data to a CSV file using the COPY TO command. ```cql CREATE KEYSPACE test WITH REPLICATION = { 'class' : 'NetworkTopologyStrategy', 'datacenter1' : 1 }; USE test; CREATE TABLE airplanes ( name text PRIMARY KEY, manufacturer ascii, year int, mach float ); INSERT INTO airplanes (name, manufacturer, year, mach) VALUES ('P38-Lightning', 'Lockheed', 1937, 0.7); COPY airplanes (name, manufacturer, year, mach) TO 'temp.csv'; ``` -------------------------------- ### Example of Dropping a Keyspace Source: https://docs.datastax.com/en/cql-oss/3.1/cql/cql_reference/drop_keyspace_r This example demonstrates how to use the DROP KEYSPACE statement to remove a specific keyspace named 'MyTwitterClone'. This action is irreversible and will delete all data within the keyspace. ```cql DROP KEYSPACE MyTwitterClone; ``` -------------------------------- ### Configure Table Caching in CQL Source: https://docs.datastax.com/en/cql-oss/3.1/cql/cql_reference/tabProp Demonstrates how to configure caching for a table using the WITH caching clause. It specifies options for 'keys' and 'rows_per_partition'. ```cql CREATE TABLE DogTypes ( block_id uuid, species text, alias text, population varint, PRIMARY KEY (species, block_id) ) WITH caching = { 'keys' : 'NONE', 'rows_per_partition' : '120' }; ``` -------------------------------- ### CQL Example: Delete Specific Columns Source: https://docs.datastax.com/en/cql-oss/3.1/cql/cql_reference/delete_r An example of deleting specific columns (firstname, lastname) from a table. This demonstrates how to list the columns to be deleted after the DELETE keyword and before the FROM clause. ```cql DELETE firstname, lastname FROM cycling.cyclist_name WHERE firstname = 'Alex'; ``` -------------------------------- ### Create Keyspace with NetworkTopologyStrategy (Multiple Datacenters) Source: https://docs.datastax.com/en/cql-oss/3.1/cql/cql_reference/create_keyspace_r Creates a keyspace named 'Excalibur' using NetworkTopologyStrategy, specifying 3 replicas for 'dc1' and 2 replicas for 'dc2'. This is for production environments with multiple data centers. ```cql CREATE KEYSPACE "Excalibur" WITH REPLICATION = {'class' : 'NetworkTopologyStrategy', 'dc1' : 3, 'dc2' : 2}; ``` -------------------------------- ### CQL UPDATE Example: Multiple Columns and Rows Source: https://docs.datastax.com/en/cql-oss/3.1/cql/cql_reference/update_r Provides examples of updating multiple columns in a single row and updating a column across several rows using the IN clause. ```cql UPDATE Movies SET col1 = val1, col2 = val2 WHERE movieID = key1; UPDATE Movies SET col3 = val3 WHERE movieID IN (key1, key2, key3); UPDATE Movies SET col4 = 22 WHERE movieID = key4; ``` ```cql UPDATE users SET state = 'TX' WHERE user_uuid IN (88b8fd18-b1ed-4e96-bf79-4280797cba80, 06a8913c-c0d6-477c-937d-6c1b69a95d43, bc108776-7cb5-477f-917d-869c12dfffa8); ``` ```cql UPDATE users SET name = 'John Smith', email = 'jsmith@cassie.com' WHERE user_uuid = 88b8fd18-b1ed-4e96-bf79-4280797cba80; ``` -------------------------------- ### Configure Table Compression in Cassandra Source: https://docs.datastax.com/en/cql-oss/3.1/cql/cql_reference/tabProp This snippet demonstrates how to configure data compression for a Cassandra table using different compressor options like LZ4, Snappy, or Deflate. It also shows how to disable compression or use a custom compression class. ```cql ALTER TABLE my_table WITH compression = { 'class': 'LZ4Compressor' }; ALTER TABLE my_table WITH compression = { 'class': 'SnappyCompressor' }; ALTER TABLE my_table WITH compression = { 'class': 'DeflateCompressor' }; ALTER TABLE my_table WITH compression = { 'class': '' }; ALTER TABLE my_table WITH compression = { 'class': 'org.apache.cassandra.io.compress.MyCustomCompressor' }; ``` -------------------------------- ### CQL Example: Delete Entire Rows Source: https://docs.datastax.com/en/cql-oss/3.1/cql/cql_reference/delete_r An example of deleting entire rows from a table. This is achieved by omitting the column names after the DELETE keyword, followed by the FROM clause and the WHERE clause to specify the rows. ```cql DELETE FROM cycling.cyclist_name WHERE firstname IN ('Alex', 'Marianne'); ``` -------------------------------- ### DESCRIBE KEYSPACES Source: https://docs.datastax.com/en/cql-oss/3.1/cql/cql_reference/describe_r Outputs a list of all keyspace names in the connected Cassandra cluster. ```APIDOC ## DESCRIBE KEYSPACES ### Description Outputs a list of all keyspace names. ### Method GET ### Endpoint N/A (This is a command-line operation, not a REST endpoint) ### Parameters None ### Request Example ```cql DESCRIBE KEYSPACES; ``` ### Response #### Success Response (200) - **keyspaces** (array) - An array of keyspace names. #### Response Example ```json { "keyspaces": [ "system", "my_app_keyspace", "another_keyspace" ] } ``` ``` -------------------------------- ### CQL CREATE USER Syntax and Examples Source: https://docs.datastax.com/en/cql-oss/3.1/cql/cql_reference/create_user_r Demonstrates the syntax for creating users in CQL, including options for setting passwords, superuser status, and conditional creation. It covers creating internal user accounts and handling existing users. ```cql CREATE USER _IF NOT EXISTS_ user_name _WITH PASSWORD 'password' NOSUPERUSER_ | _SUPERUSER _ ``` ```cql CREATE USER spillman WITH PASSWORD 'Niner27'; CREATE USER akers WITH PASSWORD 'Niner2' SUPERUSER; CREATE USER boone WITH PASSWORD 'Niner75' NOSUPERUSER; ``` ```cql CREATE USER test NOSUPERUSER; ``` ```cql CREATE USER newuser WITH PASSWORD 'password'; ``` ```cql CREATE USER IF NOT EXISTS newuser WITH PASSWORD 'password'; ``` -------------------------------- ### CQL SELECT with LIMIT Clause Example Source: https://docs.datastax.com/en/cql-oss/3.1/cql/cql_reference/select_r Illustrates the use of the LIMIT clause in CQL SELECT statements to restrict the number of rows returned by a query. Examples show limiting to 50,000 and 200,000 rows. ```cql SELECT COUNT(*) FROM big_table LIMIT 50000; SELECT COUNT(*) FROM big_table LIMIT 200000; ``` -------------------------------- ### Specify Custom Compaction Strategy in CQL Source: https://docs.datastax.com/en/cql-oss/3.1/cql/cql_reference/tabProp Shows how to define a custom compaction strategy for a table using the 'compaction' property with a full class name string. ```cql CREATE TABLE my_table ( id uuid PRIMARY KEY, data text ) WITH compaction = { 'class' : 'com.example.CustomCompactionStrategy' }; ``` -------------------------------- ### List All Permissions for a User (CQL) Source: https://docs.datastax.com/en/cql-oss/3.1/cql/cql_reference/list_permissions_r Lists all permissions granted to a specific user. This command requires the user's name and optionally a resource. The output shows the username, resource, and permission granted. ```cql LIST ALL PERMISSIONS OF akers; ``` -------------------------------- ### Check Created Keyspaces Source: https://docs.datastax.com/en/cql-oss/3.1/cql/cql_reference/create_keyspace_r Queries the system schema to list all created keyspaces, their replication strategies, and options. This helps verify keyspace creation and configuration. ```cql SELECT * FROM system.schema_keyspaces; ``` -------------------------------- ### DESCRIBE KEYSPACE Source: https://docs.datastax.com/en/cql-oss/3.1/cql/cql_reference/describe_r Outputs CQL commands to recreate the specified keyspace and its tables. ```APIDOC ## DESCRIBE KEYSPACE ### Description Outputs CQL commands for the given keyspace. These CQL commands can be used to recreate the keyspace and tables. ### Method GET ### Endpoint N/A (This is a command-line operation, not a REST endpoint) ### Parameters #### Path Parameters - **keyspace_name** (string) - Required - The name of the keyspace to describe. ### Request Example ```cql DESCRIBE KEYSPACE cycling; ``` ### Response #### Success Response (200) - **cql_commands** (string) - A string containing CQL commands to recreate the keyspace and its schema. #### Response Example ```json { "cql_commands": "CREATE KEYSPACE cycling WITH replication = {‘class’: ‘SimpleStrategy’, ‘replication_factor’: 1};\nCREATE TABLE cycling.upcoming_calendar ( \n event_id uuid PRIMARY KEY,\n description text,\n event_date date\n);" } ``` ``` -------------------------------- ### DROP TABLE Statement Source: https://docs.datastax.com/en/cql-oss/3.1/cql/cql_reference/drop_table_r This section details the DROP TABLE statement, its synopsis, description, and provides an example of its usage. ```APIDOC ## DROP TABLE ### Description Remove the named table. A DROP TABLE statement results in the immediate, irreversible removal of a table, including all data contained in the table. You can also use the alias DROP COLUMNFAMILY. ### Method DELETE ### Endpoint N/A (This is a CQL statement, not a REST API endpoint) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```cql DROP TABLE worldSeriesAttendees; ``` ### Response #### Success Response (200) N/A (CQL statements do not return HTTP responses) #### Response Example N/A ``` -------------------------------- ### Show Cassandra Version, Host, or Tracing Info (CQL) Source: https://docs.datastax.com/en/cql-oss/3.1/cql/cql_reference/show_r The SHOW command in cqlsh displays information about the current client session. It can show the Cassandra version and build number, the connected host details, or tracing information for the session. Tracing information is available for 24 hours. ```cql SHOW VERSION SHOW HOST SHOW SESSION tracing_session_id ``` ```cql cqlsh:my_ks> SHOW version [cqlsh 5.0.1 | Cassandra 2.1.0 | CQL spec 3.2 | Native protocol v3] ``` ```cql cqlsh:my_ks> SHOW host Connected to Test Cluster at 127.0.0.1:9042. ``` ```cql cqlsh:my_ks> SHOW SESSION d0321c90-508e-11e3-8c7b-73ded3cb6170 ``` ```text Tracing session: d0321c90-508e-11e3-8c7b-73ded3cb6170 activity | timestamp | source | source_elapsed -----------------------------------------------------------------------------------------------------------------------------------------+--------------+-----------+---------------- execute_cql3_query | 12:19:52,372 | 127.0.0.1 | 0 Parsing CREATE TABLE emp ( empID int, deptID int, first_name varchar, last_name varchar, PRIMARY KEY (empID, deptID) ); | 12:19:52,372 | 127.0.0.1 | 153 Request complete | 12:19:52,372 | 127.0.0.1 | 650 . . ``` -------------------------------- ### Cassandra Compaction Event: Compaction Log Source: https://docs.datastax.com/en/cql-oss/3.1/cql/cql_reference/compactSubprop This JSON log entry details a compaction event, including the start and end times. It lists the input SSTables that were compacted and the resulting output SSTable. ```json { "type": "compaction", "keyspace": "test", "table": "t", "time": 1470083660267, "start": "1470083660188", "end": "1470083660267", "input": [ { "strategyId": "1", "table": { "generation": 1372, "version": "mb", "size": 1064979, "details": { "level": 1, "min_token": "7199305267944662291", "max_token": "7323434447996777057" } } } ], "output": [ { "strategyId": "1", "table": { "generation": 1404, "version": "mb", "size": 1064306, "details": { "level": 2, "min_token": "7199305267944662291", "max_token": "7323434447996777057" } } } ] } ``` -------------------------------- ### DESCRIBE [FULL] SCHEMA Source: https://docs.datastax.com/en/cql-oss/3.1/cql/cql_reference/describe_r Outputs CQL commands for the entire schema, optionally including system keyspaces. ```APIDOC ## DESCRIBE [FULL] SCHEMA ### Description Outputs CQL commands for entire non-system keyspace and table schema. Use the FULL option to also include system keyspaces. ### Method GET ### Endpoint N/A (This is a command-line operation, not a REST endpoint) ### Parameters #### Query Parameters - **FULL** (boolean) - Optional - If true, includes system keyspaces in the schema output. ### Request Example ```cql DESCRIBE FULL SCHEMA; ``` ### Response #### Success Response (200) - **cql_commands** (string) - A string containing CQL commands for the schema. #### Response Example ```json { "cql_commands": "CREATE KEYSPACE system WITH replication = {‘class’: ‘SimpleStrategy’, ‘replication_factor’: 1};\nCREATE TABLE system.local ( ... );\nCREATE KEYSPACE my_app_keyspace WITH replication = {‘class’: ‘SimpleStrategy’, ‘replication_factor’: 1};\nCREATE TABLE my_app_keyspace.users ( ... );" } ``` ``` -------------------------------- ### CQL UPDATE Example: Counter Column Source: https://docs.datastax.com/en/cql-oss/3.1/cql/cql_reference/update_r Shows how to update a counter column by incrementing or decrementing its current value. This operation is supported by the UPDATE command. ```cql UPDATE UserActionCounts SET total = total + 2 WHERE keyalias = 523; ``` -------------------------------- ### CQL SELECT All Columns Example Source: https://docs.datastax.com/en/cql-oss/3.1/cql/cql_reference/select_r A simple CQL query demonstrating how to select all columns from a table named 'People' using the asterisk wildcard. ```cql SELECT * from People; ``` -------------------------------- ### Truncate table and import data from CSV Source: https://docs.datastax.com/en/cql-oss/3.1/cql/cql_reference/copy_r Demonstrates truncating an existing table and then importing data from a CSV file using the COPY FROM command. ```cql TRUNCATE airplanes; COPY airplanes (name, manufacturer, year, mach) FROM 'temp.csv'; ``` -------------------------------- ### CQL Boolean Literal Examples Source: https://docs.datastax.com/en/cql-oss/3.1/cql/cql_reference/valid_literal_r Shows valid representations of boolean literals in CQL. Boolean values 'true' and 'false' are case-insensitive and should not be enclosed in quotation marks. ```cql true ``` ```cql false ``` -------------------------------- ### Grant ALL Permissions on a Specific Table - CQL Source: https://docs.datastax.com/en/cql-oss/3.1/cql/cql_reference/grant_r Example of granting all possible permissions (ALL PERMISSIONS) to a user on a specific table. This provides complete access to the specified table. ```cql GRANT ALL PERMISSIONS ON ravens.plays TO boone; ``` -------------------------------- ### DESCRIBE TYPES Source: https://docs.datastax.com/en/cql-oss/3.1/cql/cql_reference/describe_r Outputs a list of all user-defined types in the current keyspace. ```APIDOC ## DESCRIBE TYPES ### Description Outputs list of all user-defined types in the current keyspace. ### Method GET ### Endpoint N/A (This is a command-line operation, not a REST endpoint) ### Parameters None ### Request Example ```cql DESCRIBE TYPES; ``` ### Response #### Success Response (200) - **types** (array) - An array of user-defined type names. #### Response Example ```json { "types": [ "address", "contact_info" ] } ``` ``` -------------------------------- ### CQL CREATE KEYSPACE Synopsis Source: https://docs.datastax.com/en/cql-oss/3.1/cql/cql_reference/create_keyspace_r The synopsis for the CREATE KEYSPACE statement in CQL. It outlines the basic structure for defining a new keyspace, including optional clauses and the REPLICATION map. ```cql CREATE KEYSPACE | SCHEMA _IF NOT EXISTS_ keyspace_name WITH REPLICATION = map _AND DURABLE_WRITES = __ true _|_ false_ ``` -------------------------------- ### CQL COUNT Aggregate Function Example Source: https://docs.datastax.com/en/cql-oss/3.1/cql/cql_reference/select_r Demonstrates how to use the COUNT(*) aggregate function in CQL to retrieve the total number of rows in the 'users' table. ```cql SELECT COUNT(*) FROM users; ``` -------------------------------- ### ALTER TABLE - Changing Column Type Source: https://docs.datastax.com/en/cql-oss/3.1/cql/cql_reference/alter_table_r Demonstrates how to change the data type of an existing column using the ALTER TABLE command. It highlights compatibility requirements and provides examples. ```APIDOC ## ALTER TABLE - Changing Column Type ### Description Change the datatype of a column. The original datatype must be compatible with the new type. Unsupported changes include altering the type of a clustering column or a column with an index. ### Method ALTER TABLE ... ALTER ... TYPE ### Endpoint `ALTER TABLE _keyspace_name._table_name ALTER column_name TYPE new_cql_type;` ### Parameters - **column_name** (string) - Required - The name of the column to modify. - **new_cql_type** (string) - Required - The new CQL data type for the column. ### Request Example ```cql -- Change 'bio' column from ascii to text ALTER TABLE users ALTER bio TYPE text; -- Change 'bio' column from text to blob ALTER TABLE users ALTER bio TYPE blob; ``` ### Response This operation returns no results. Errors may occur if the new data type is incompatible with existing data. ``` -------------------------------- ### List All Permissions for All Users (CQL) Source: https://docs.datastax.com/en/cql-oss/3.1/cql/cql_reference/list_permissions_r Lists all permissions granted to all users across all keyspaces and tables. This command can be used without specifying a user or resource. Superusers can view all users' permissions. ```cql LIST ALL PERMISSIONS; ``` -------------------------------- ### Grant SELECT Permission on All Keyspaces - CQL Source: https://docs.datastax.com/en/cql-oss/3.1/cql/cql_reference/grant_r Example of granting SELECT permission to a user on all tables across all keyspaces. This allows the specified user to read data from any table. ```cql GRANT SELECT ON ALL KEYSPACES TO spillman; ``` -------------------------------- ### DESCRIBE TABLES Source: https://docs.datastax.com/en/cql-oss/3.1/cql/cql_reference/describe_r Outputs all tables in the current keyspace, or in all keyspaces if there is no current keyspace. ```APIDOC ## DESCRIBE TABLES ### Description Outputs all tables in the current keyspace, or in all keyspaces if there is not current keyspace. ### Method GET ### Endpoint N/A (This is a command-line operation, not a REST endpoint) ### Parameters None ### Request Example ```cql DESCRIBE TABLES; ``` ### Response #### Success Response (200) - **tables** (array) - An array of table names. #### Response Example ```json { "tables": [ "users", "products", "orders" ] } ``` ``` -------------------------------- ### CQL DESCRIBE Command Synopsis Source: https://docs.datastax.com/en/cql-oss/3.1/cql/cql_reference/describe_r The synopsis for the DESCRIBE command in CQL, outlining the various objects that can be described within an Apache Cassandra cluster. This includes cluster-wide information, keyspaces, tables, types, and indexes. ```cql DESCRIBE _FULL_ CLUSTER | SCHEMA | KEYSPACES | KEYSPACE keyspace_name | TABLES | TABLE table_name | TYPES | TYPE user_defined_type | INDEX | INDEX index_name ``` -------------------------------- ### Get Datacenter Status Source: https://docs.datastax.com/en/cql-oss/3.1/cql/cql_reference/create_keyspace_r Uses the 'nodetool status' command to display the status of nodes in the Cassandra cluster, including their datacenter and rack information. This is useful for determining default datacenter names. ```bash $ nodetool status ``` -------------------------------- ### View Table Contents with cqlsh Source: https://docs.datastax.com/en/cql-oss/3.1/cql/cql_reference/copy_r Displays the contents of the 'songs' table in the 'music' keyspace. This is a preliminary step to verify data before copying. ```cql cqlsh> SELECT * FROM music.songs; ```