### Creating Multiple SAI Indexes for Quickstart Example Source: https://github.com/apache/cassandra/blob/trunk/doc/modules/cassandra/pages/reference/cql-commands/create-custom-index.adoc This snippet creates several SAI indexes on the 'cycling.cyclist_semi_pro' table, as used in the SAI quickstart guide. It demonstrates indexing different columns like 'name', 'countryid', and 'race_times' (as entries). ```cql CREATE CUSTOM INDEX IF NOT EXISTS cyclistNameIdx ON cycling.cyclist_semi_pro (name) USING 'StorageAttachedIndex'; CREATE CUSTOM INDEX IF NOT EXISTS cyclistCountryIdx ON cycling.cyclist_semi_pro (countryid) USING 'StorageAttachedIndex'; CREATE CUSTOM INDEX IF NOT EXISTS cyclistRaceTimesIdx ON cycling.cyclist_semi_pro (ENTRIES(race_times)) USING 'StorageAttachedIndex'; ``` -------------------------------- ### Start Cassandra Service (RPM Install) Source: https://github.com/apache/cassandra/blob/trunk/doc/modules/cassandra/pages/installing/installing.adoc Starts the Cassandra service after installation via RPM. A new Linux user 'cassandra' is created and the service runs as this user. ```shell sudo service cassandra start ``` -------------------------------- ### Cassandra Cluster Startup Log Example Source: https://github.com/apache/cassandra/blob/trunk/doc/modules/cassandra/pages/reference/java17.adoc This log output indicates a single-node Cassandra cluster has successfully started and joined the ring. ```console INFO [main] 2019-07-31 21:18:19,687 InboundConnectionInitiator.java:130 - Listening on address: (127.0.0.1:7000), nic: lo, encryption: enabled (openssl) ... ... INFO [main] 2019-07-31 21:18:19,850 StorageService.java:512 - Unable to gossip with any peers but continuing anyway since node is in its own seed list INFO [main] 2019-07-31 21:18:19,864 StorageService.java:695 - Loading persisted ring state INFO [main] 2019-07-31 21:18:19,865 StorageService.java:814 - Starting up server gossip INFO [main] 2019-07-31 21:18:20,088 BufferPool.java:216 - Global buffer pool is enabled, when pool is exhausted (max is 251.000MiB) it will allocate on heap INFO [main] 2019-07-31 21:18:20,110 StorageService.java:875 - This node will not auto bootstrap because it is configured to be a seed node. ... ... INFO [main] 2019-07-31 21:18:20,809 StorageService.java:1507 - JOINING: Finish joining ring INFO [main] 2019-07-31 21:18:20,921 StorageService.java:2508 - Node 127.0.0.1:7000 state jump to NORMAL ``` -------------------------------- ### Execute Command Output Example Source: https://github.com/apache/cassandra/blob/trunk/doc/modules/cassandra/pages/managing/operating/async-profiler.adoc Example output from executing the 'meminfo' command. ```text Call trace storage: 10244 KB Flight recording: 0 KB Dictionaries: 68 KB Code cache: 11934 KB ------------------------------ Total: 22246 KB ``` -------------------------------- ### Install Audit Trigger Source: https://github.com/apache/cassandra/blob/trunk/examples/triggers/README.adoc Navigate to the trigger examples directory and run the ant install command to build and copy the trigger to the Cassandra configuration. ```bash cd /examples/triggers ant install ``` -------------------------------- ### List Results Output Example Source: https://github.com/apache/cassandra/blob/trunk/doc/modules/cassandra/pages/managing/operating/async-profiler.adoc Example output showing available profiling result files. ```text memory-allocation-5m.html cpu.html ``` -------------------------------- ### Install Custom Constraints Source: https://github.com/apache/cassandra/blob/trunk/examples/constraints/README.adoc Builds and installs the custom constraints JAR. This command should be run from the `examples/constraints` directory. ```bash cd /examples/constraints ant install ``` -------------------------------- ### CREATE USER statement example Source: https://github.com/apache/cassandra/blob/trunk/doc/modules/cassandra/pages/developing/cql/security.adoc Example of creating a new user. ```cql include::cassandra:example$CQL/create_user.cql[] ``` -------------------------------- ### Run Security Example Tests Source: https://github.com/apache/cassandra/blob/trunk/examples/ssl-factory/README.adoc Runs tests for the security examples within the ssl-factory module. Navigate to the example directory and execute 'ant test'. ```bash cd /examples/ssl-factory ant test ``` -------------------------------- ### Generatetokens Tool Execution Example Source: https://github.com/apache/cassandra/blob/trunk/doc/modules/cassandra/pages/tooling/generate-tokens.adoc Demonstrates the execution of the `generatetokens` tool with specific arguments for node count, vnodes, replication factor, and rack distribution. This command is run before the Cassandra node is first started. ```console tools/bin/generatetokens -n 9 -t 4 --rf 3 --racks 3,3,3 ``` -------------------------------- ### Duration Input Examples Source: https://github.com/apache/cassandra/blob/trunk/doc/modules/cassandra/pages/developing/cql/types.adoc Provides examples of how to input duration values using a quantity-unit format. ```cql INSERT INTO durations (id, d) VALUES (1, 12h30m); ``` -------------------------------- ### List all ROLES statement example Source: https://github.com/apache/cassandra/blob/trunk/doc/modules/cassandra/pages/developing/cql/security.adoc Example of listing all known roles in the system. ```cql include::cassandra:example$CQL/list_roles.cql[] ``` -------------------------------- ### Install Cassandra with APT Source: https://github.com/apache/cassandra/blob/trunk/doc/modules/cassandra/pages/installing/installing.adoc Installs Cassandra on a Debian-based system using the APT package manager. ```shell sudo apt-get install cassandra ``` -------------------------------- ### Create Role Example Source: https://github.com/apache/cassandra/blob/trunk/doc/modules/cassandra/pages/developing/cql/security.adoc An example of creating a database role using CQL. ```cql include::cassandra:example$CQL/create_role.cql[] ``` -------------------------------- ### Status Output Example Source: https://github.com/apache/cassandra/blob/trunk/doc/modules/cassandra/pages/managing/operating/async-profiler.adoc Example output indicating that profiling is currently running. ```text Profiling is running for 7 seconds ``` -------------------------------- ### Start Advanced Profiling Source: https://github.com/apache/cassandra/blob/trunk/doc/modules/cassandra/pages/managing/operating/async-profiler.adoc Starts profiling memory allocations for 5 minutes and saves the output to a specified HTML file. ```bash $ nodetool profile start -e alloc -d 5m -o memory-allocation-5m.html ``` -------------------------------- ### Basic SELECT Statement Example Source: https://github.com/apache/cassandra/blob/trunk/doc/modules/cassandra/pages/developing/cql/dml.adoc A simple example demonstrating how to query data from a table using the SELECT statement. ```cql include::cassandra:example$CQL/select_statement.cql[] ``` -------------------------------- ### Create Table Statement Example Source: https://github.com/apache/cassandra/blob/trunk/doc/modules/cassandra/pages/developing/cql/ddl.adoc An example demonstrating the creation of a table in CQL, including column definitions and primary key specification. ```cql CREATE TABLE "My Table" (id uuid PRIMARY KEY, name text, age int); ``` -------------------------------- ### Start Cassandra with Docker Network Source: https://github.com/apache/cassandra/blob/trunk/doc/modules/cassandra/pages/getting-started/cassandra-quickstart.adoc Starts a Cassandra container and creates a Docker network for it. This allows for port access without exposing them directly on the host. ```bash docker network create cassandra docker run --name some-cassandra -d --network cassandra -p 9042:9042 cassandra:latest ``` -------------------------------- ### Cassandra Stress Full Example YAML Source: https://github.com/apache/cassandra/blob/trunk/doc/modules/cassandra/pages/tooling/cassandra-stress.adoc Includes a full example YAML configuration for Cassandra stress. This is a placeholder for a more detailed configuration file. ```yaml include::cassandra:example$YAML/stress-example.yaml[] ``` -------------------------------- ### Create Keyspace Sample Source: https://github.com/apache/cassandra/blob/trunk/doc/modules/cassandra/pages/developing/cql/cql_singlefile.adoc Demonstrates creating a new keyspace with different replication strategies. ```sql CREATE KEYSPACE Excelsior WITH replication = {'class': 'SimpleStrategy', 'replication_factor' : 3}; CREATE KEYSPACE Excalibur WITH replication = {'class': 'NetworkTopologyStrategy', 'DC1' : 1, 'DC2' : 3} AND durable_writes = false; ``` -------------------------------- ### Create New SAI Index Source: https://github.com/apache/cassandra/blob/trunk/doc/modules/cassandra/pages/developing/cql/indexing/sai/_sai-alter.adoc Use this command to create a new SAI index, for example, for a quick start setup. ```cql CREATE CUSTOM INDEX "cyclist_name_idx" ON "cyclist_table" (name) USING 'StorageAttachedIndex' WITH OPTIONS = { 'normalization' : 'best_case', 'case_sensitive' : 'false' }; CREATE CUSTOM INDEX "cyclist_team_idx" ON "cyclist_table" (team) USING 'StorageAttachedIndex' WITH OPTIONS = { 'normalization' : 'best_case', 'case_sensitive' : 'false' }; CREATE CUSTOM INDEX "cyclist_country_idx" ON "cyclist_table" (country) USING 'StorageAttachedIndex' WITH OPTIONS = { 'normalization' : 'best_case', 'case_sensitive' : 'false' }; ``` -------------------------------- ### Install Java 17 on RedHat Linux Source: https://github.com/apache/cassandra/blob/trunk/doc/modules/cassandra/pages/reference/java17.adoc Use this command to install OpenJDK 17 on RedHat-based systems. This is required for building Cassandra with Java 17. ```console $ yum install java-17-openjdk ``` -------------------------------- ### Creating a Simple Table Source: https://github.com/apache/cassandra/blob/trunk/doc/modules/cassandra/pages/developing/cql/functions.adoc Example of creating a basic table with a text partition key, used to illustrate the token function. ```sql include::cassandra:example$CQL/create_table_simple.cql[] ``` -------------------------------- ### Start Cassandra from Tarball Source: https://github.com/apache/cassandra/blob/trunk/doc/modules/cassandra/pages/installing/installing.adoc Starts the Cassandra service when installed from a tarball. This command runs Cassandra as the authenticated Linux user. ```shell bin/cassandra -f ``` -------------------------------- ### Example Startup Check Configuration Source: https://github.com/apache/cassandra/blob/trunk/examples/startup-checks/README.adoc Configure custom startup checks in cassandra.yaml. The 'my_check' entry demonstrates how to pass options to your custom check. ```yaml startup_checks: my_check: key: value ``` -------------------------------- ### Build Startup Check JAR Source: https://github.com/apache/cassandra/blob/trunk/examples/startup-checks/README.adoc Build the custom startup check JAR and install it into the Cassandra environment. ```bash $ cd /examples/startup-checks $ ant install ``` -------------------------------- ### Create Keyspace and Use Demo Keyspace Source: https://github.com/apache/cassandra/blob/trunk/doc/SASI.md This snippet demonstrates how to create a new keyspace with simple replication and then switch to using it. This is a prerequisite for the following examples. ```cql cqlsh> CREATE KEYSPACE demo WITH replication = { ... 'class': 'SimpleStrategy', ... 'replication_factor': '1' ... }; cqlsh> USE demo; ``` -------------------------------- ### Query a FROZEN map index Source: https://github.com/apache/cassandra/blob/trunk/doc/modules/cassandra/pages/developing/cql/indexing/2i/_2i-create-on-collection.adoc Query a FULL index on a frozen map to find rows matching specific criteria within the map's content. This example finds cyclists with a specific number of race wins, Grand Tour starts, and Classic starts. ```cql SELECT cyclist_id, name, race_stats FROM race_starts WHERE race_stats['Pro wins'] = 39 AND race_stats['Grand Tour starts'] = 7 AND race_stats['Classic starts'] = 14; ``` -------------------------------- ### Create Tables in catalogkeyspace Source: https://github.com/apache/cassandra/blob/trunk/doc/modules/cassandra/pages/managing/operating/backups.adoc Creates two tables, `journal` and `magazine`, within the `catalogkeyspace` keyspace using CQL. These tables are part of the example setup for backups. ```cql CREATE TABLE catalogkeyspace.journal (journal_id int PRIMARY KEY, title text, editor text); CREATE TABLE catalogkeyspace.magazine (magazine_id int PRIMARY KEY, title text, publisher text); ``` -------------------------------- ### Create Keyspace and Table with CQL Source: https://github.com/apache/cassandra/blob/trunk/doc/modules/cassandra/pages/managing/operating/fqllogging.adoc Demonstrates the creation of a keyspace and a table within it using CQL, followed by inserting data. ```cql cqlsh> CREATE KEYSPACE querylogkeyspace ... WITH replication = {'class': 'SimpleStrategy', 'replication_factor' : 1}; cqlsh> USE querylogkeyspace; cqlsh:querylogkeyspace> CREATE TABLE t ( id int, k int, v text, PRIMARY KEY (id) ); cqlsh:querylogkeyspace> INSERT INTO t (id, k, v) VALUES (0, 0, 'val0'); cqlsh:querylogkeyspace> INSERT INTO t (id, k, v) VALUES (0, 1, 'val1'); ``` -------------------------------- ### Example Unit Test Structure Source: https://github.com/apache/cassandra/blob/trunk/TESTING.md A basic JUnit test case demonstrating the recommended structure: setup, precondition check, action under test, and postcondition check. This structure enhances readability. ```java import org.junit.Test; import static org.junit.Assert.*; public class ExampleTest { @Test public void increment() throws Exception { // setup code int x = 1; // check preconditions assertEquals(1, x); // perform the state changing action under test x++; // check post conditions assertEquals(2, x); } } ``` -------------------------------- ### Generatetokens Example Command Source: https://github.com/apache/cassandra/blob/trunk/doc/modules/cassandra/pages/tooling/generate-tokens.adoc An example of how to run the `generatetokens` command with specific parameters for node count, vnodes, replication factor, and rack distribution. This helps in understanding practical application of the command. ```console generatetokens -n 30 -t 8 --rf 3 --racks 10,10,10 ``` -------------------------------- ### Drop Trigger Example Source: https://github.com/apache/cassandra/blob/trunk/doc/modules/cassandra/pages/developing/cql/triggers.adoc An example of dropping a trigger in CQL. ```cql DROP TRIGGER my_trigger; ``` -------------------------------- ### Configuring Cassandra Credentials File Source: https://github.com/apache/cassandra/blob/trunk/doc/modules/cassandra/pages/managing/operating/password_validation.adoc This example shows how to configure the ~/.cassandra/credentials file for authentication with a username and password. ```ini [PlainTextAuthProvider] username = cassandra password = R7tb33?.mcAX ``` -------------------------------- ### Create Trigger Example Source: https://github.com/apache/cassandra/blob/trunk/doc/modules/cassandra/pages/developing/cql/triggers.adoc An example of creating a trigger in CQL. ```cql CREATE TRIGGER my_trigger ON my_table USING com.example.MyTrigger; ``` -------------------------------- ### Revoke Permission Example Source: https://github.com/apache/cassandra/blob/trunk/doc/modules/cassandra/pages/developing/cql/security.adoc Example of revoking a permission from a specific role. ```cql REVOKE SELECT ON keyspace1.table1 FROM alice; ``` -------------------------------- ### Create Keyspace Example in CQL3 Source: https://github.com/apache/cassandra/blob/trunk/NEWS.txt Demonstrates the syntax for creating a keyspace in CQL3, specifying the replication strategy and factor. Consistency level cannot be set here and must be handled at the protocol level. ```sql CREATE KEYSPACE ks WITH replication = { 'class' : 'SimpleStrategy', 'replication_factor' : 2 }; ``` -------------------------------- ### Configure Keyspace with SimpleStrategy Source: https://github.com/apache/cassandra/blob/trunk/doc/modules/cassandra/pages/managing/operating/transientreplication.adoc Example of creating a keyspace with a replication factor of 4 total replicas, where 1 is transient, using SimpleStrategy. ```cql CREATE KEYSPACE CassandraKeyspaceSimple WITH replication = {'class': 'SimpleStrategy', 'replication_factor' : 4/1}; ``` -------------------------------- ### Create Function Example Source: https://github.com/apache/cassandra/blob/trunk/doc/modules/cassandra/pages/developing/cql/functions.adoc An example of creating a user-defined function in CQL. ```sql include::cassandra:example$CQL/create_function.cql[] ``` -------------------------------- ### Create Table with Compaction Options Source: https://github.com/apache/cassandra/blob/trunk/doc/modules/cassandra/pages/developing/cql/indexing/sai/operations/configuring.adoc This example demonstrates how to set compaction options, specifically `sstable_size_in_mb`, when creating a table. Adjusting this value can impact performance for tables with SAI indexes. ```cql CREATE TABLE "my_table" ( pk int PRIMARY KEY, col1 text, col2 int ) WITH compaction = { 'class': 'LeveledCompactionStrategy', 'sstable_size_in_mb': 320 }; ``` -------------------------------- ### Snapshot Command Output Source: https://github.com/apache/cassandra/blob/trunk/doc/modules/cassandra/pages/managing/operating/backups.adoc Example output after taking a snapshot of all tables in a keyspace. ```none Snapshot directory: /var/lib/cassandra/data/catalogkeyspace/snapshots/1678886400000 ``` -------------------------------- ### Alter User Example Source: https://github.com/apache/cassandra/blob/trunk/doc/modules/cassandra/pages/developing/cql/security.adoc Example of altering a user's password in CQL. ```cql ALTER USER "test" WITH PASSWORD = 'new_password'; ``` -------------------------------- ### Table Creation and Data Insertion for Aggregate Example Source: https://github.com/apache/cassandra/blob/trunk/doc/modules/cassandra/pages/developing/cql/cql_singlefile.adoc Sets up a sample table 'atable' and inserts data to demonstrate the usage of the user-defined 'average' aggregate function. ```sql CREATE TABLE atable ( pk int PRIMARY KEY, val int); INSERT INTO atable (pk, val) VALUES (1,1); INSERT INTO atable (pk, val) VALUES (2,2); INSERT INTO atable (pk, val) VALUES (3,3); INSERT INTO atable (pk, val) VALUES (4,4); ``` -------------------------------- ### Specify browser for help Source: https://github.com/apache/cassandra/blob/trunk/doc/modules/cassandra/pages/managing/tools/cqlsh.adoc Use the --browser option to specify the browser for displaying CQL help. ```bash cqlsh --browser "/usr/bin/google-chrome-stable %s" ``` -------------------------------- ### Start Basic Profiling Source: https://github.com/apache/cassandra/blob/trunk/doc/modules/cassandra/pages/managing/operating/async-profiler.adoc Initiates a profiling session for the default duration of 60 seconds. ```bash $ nodetool profile start ``` -------------------------------- ### Revoke ROLE statement example Source: https://github.com/apache/cassandra/blob/trunk/doc/modules/cassandra/pages/developing/cql/security.adoc Example of revoking the 'report_writer' role from 'alice'. ```cql include::cassandra:example$CQL/revoke_role.cql[] ``` -------------------------------- ### Grant ROLE statement example Source: https://github.com/apache/cassandra/blob/trunk/doc/modules/cassandra/pages/developing/cql/security.adoc Example of granting the 'report_writer' role to 'alice'. ```cql include::cassandra:example$CQL/grant_role.cql[] ``` -------------------------------- ### Example Schema and Index Hint Query Source: https://github.com/apache/cassandra/blob/trunk/src/java/org/apache/cassandra/db/filter/IndexHints.md Demonstrates a Cassandra schema with multiple indexes and a SELECT query using index hints to specify which indexes to include and exclude. ```cassandra CREATE TABLE users ( username text PRIMARY KEY, birth_year int, country text, phone text ); CREATE INDEX birth_year_idx ON users (birth_year) USING 'sai'; CREATE INDEX country_idx ON users (country) USING 'sai'; CREATE INDEX phone_idx ON users (phone) USING 'sai'; SELECT * FROM users WHERE birth_year = 1981 AND country = 'FR' WITH included_indexes = {birth_year_idx} AND excluded_indexes = {country_idx, phone_idx}; ``` -------------------------------- ### Alter Role Example Source: https://github.com/apache/cassandra/blob/trunk/doc/modules/cassandra/pages/developing/cql/security.adoc An example of altering an existing database role using CQL. ```cql include::cassandra:example$CQL/alter_role.cql[] ``` -------------------------------- ### CREATE TABLE LIKE Sample Source: https://github.com/apache/cassandra/blob/trunk/doc/modules/cassandra/pages/developing/cql/cql_singlefile.adoc A sample CQL statement demonstrating how to create a new table based on an existing one. ```sql CREATE TABLE my_new_table LIKE my_old_table WITH compaction = { 'class' : 'TimeWindowCompactionStrategy', 'compaction_window_unit' : 'DAYS', 'compaction_window_size' : 1 }; ``` -------------------------------- ### Example CREATE MATERIALIZED VIEW Statement Source: https://github.com/apache/cassandra/blob/trunk/doc/modules/cassandra/pages/developing/cql/mvs.adoc An example of how to create a materialized view using CQL. ```cql include::cassandra:example$CQL/create_mv_statement.cql[] ``` -------------------------------- ### Create Secondary Index Example Source: https://github.com/apache/cassandra/blob/trunk/doc/modules/cassandra/pages/developing/cql/indexes.adoc Example of creating a secondary index on a column in a Cassandra table. ```cql CREATE INDEX ON cycling.cyclists (lastname); ``` -------------------------------- ### Example Generatetokens Command and Output Source: https://github.com/apache/cassandra/blob/trunk/doc/modules/cassandra/assets/images/generatetokens.rst Demonstrates the usage of the generatetokens command with specific parameters for nodes, tokens, replication factor, and rack distribution. The output shows the generated tokens for each node and rack. ```bash $ tools/bin/generatetokens -n 9 -t 4 --rf 3 --racks 3,3,3 Generating tokens for 9 nodes with 4 vnodes each for replication factor 3 and partitioner Murmur3Partitioner Node 0 rack 0: [-6270077235120413733, -1459727275878514299, 2887564907718879562, 5778609289102954400] Node 1 rack 1: [-8780789453057732897, -3279530982831298765, 1242905755717369197, 8125606440590916903] Node 2 rack 2: [-7240625170832344686, -4453155190605073029, 74749827226930055, 4615117940688406403] Node 3 rack 0: [-5361616212862743381, -2369629129354906532, 2065235331718124379, 6952107864846935651] Node 4 rack 1: [-8010707311945038792, -692488724325792122, 3751341424203642982, 7538857152718926277] Node 5 rack 2: [-7625666241388691739, -3866343086718185897, 5196863614895680401, 8895780530621367810] Node 6 rack 0: [-5815846723991578557, -1076108000102153211, 1654070543717746788, 8510693485606142356] Node 7 rack 1: [-2824580056093102649, 658827791472149626, 3319453165961261272, 6365358576974945025] Node 8 rack 2: [-4159749138661629463, -1914678202616710416, 4905990777792043402, 6658733220910940338] ``` -------------------------------- ### Get Scroll Position Source: https://github.com/apache/cassandra/blob/trunk/tools/stress/resources/org/apache/cassandra/stress/graph/graph.html Gets or sets the horizontal or vertical scroll position of an element or window. ```javascript m.each({scrollLeft:"pageXOffset",scrollTop:"pageYOffset"},function(a,b){var c=/Y/.test(b);m.fn[a]=function(d){return V(this,function(a,d,e){var f=dd(a);return void 0===e?f?b in f?f[b]:f.document.documentElement[d]:a[d]:void(f?f.scrollTo(c?m(f).scrollLeft():e,c?e:m(f).scrollTop()):a[d]=e)},a,d,arguments.length,null)}}) ``` -------------------------------- ### Enabling FQL with nodetool Source: https://github.com/apache/cassandra/blob/trunk/doc/modules/cassandra/pages/managing/operating/fqllogging.adoc Example command to enable Full Query Logging on a Cassandra node. The --path option is mandatory if log_dir is not set in cassandra.yaml. ```bash nodetool enablefullquerylog --path /var/log/cassandra/fullquerylog ``` -------------------------------- ### Install Cassandra with YUM Source: https://github.com/apache/cassandra/blob/trunk/doc/modules/cassandra/pages/installing/installing.adoc Installs Cassandra on an RPM-based system using the YUM package manager. ```shell sudo yum install cassandra ``` -------------------------------- ### Create SAI Indexes for cycling.cyclist_semi_pro Table Source: https://github.com/apache/cassandra/blob/trunk/doc/modules/cassandra/pages/developing/cql/create-custom-index.adoc This example demonstrates creating multiple SAI indexes on the 'cycling.cyclist_semi_pro' table, including indexes on regular columns and map entries. It showcases the use of the 'sai' keyword and various indexing strategies. ```cql CREATE CUSTOM INDEX cyclist_name_idx ON cycling.cyclist_semi_pro (cyclist_name) USING 'sai'; CREATE CUSTOM INDEX cyclist_age_idx ON cycling.cyclist_semi_pro (cyclist_age) USING 'sai'; CREATE CUSTOM INDEX cyclist_country_idx ON cycling.cyclist_semi_pro (country) USING 'sai'; CREATE CUSTOM INDEX cyclist_race_name_idx ON cycling.cyclist_semi_pro (race_name) USING 'sai'; CREATE CUSTOM INDEX cyclist_race_results_idx ON cycling.cyclist_semi_pro (race_results) USING 'sai'; CREATE CUSTOM INDEX cyclist_race_results_entries_idx ON cycling.cyclist_semi_pro (ENTRIES(race_results)) USING 'sai'; CREATE CUSTOM INDEX cyclist_race_results_keys_idx ON cycling.cyclist_semi_pro (KEYS(race_results)) USING 'sai'; CREATE CUSTOM INDEX cyclist_race_results_values_idx ON cycling.cyclist_semi_pro (VALUES(race_results)) USING 'sai'; CREATE CUSTOM INDEX cyclist_team_name_idx ON cycling.cyclist_semi_pro (team_name) USING 'sai'; CREATE CUSTOM INDEX cyclist_team_name_lower_idx ON cycling.cyclist_semi_pro (LOWER(team_name)) USING 'sai'; CREATE CUSTOM INDEX cyclist_team_name_ascii_idx ON cycling.cyclist_semi_pro (TRANSLATE(team_name, 'i', 'I')) USING 'sai' WITH OPTIONS = { 'ascii': 'true' }; CREATE CUSTOM INDEX cyclist_team_name_normalized_idx ON cycling.cyclist_semi_pro (team_name) USING 'sai' WITH OPTIONS = { 'normalize': 'true' }; CREATE CUSTOM INDEX cyclist_team_name_case_sensitive_idx ON cycling.cyclist_semi_pro (team_name) USING 'sai' WITH OPTIONS = { 'case_sensitive': 'true' }; ``` -------------------------------- ### Example: Setting log_dir for FQL Source: https://github.com/apache/cassandra/blob/trunk/doc/modules/cassandra/pages/managing/operating/fqllogging.adoc Specify an existing directory for FQL logs. This directory will have its contents recursively deleted as needed. Do not use symbolic links within this directory. ```plaintext log_dir: /tmp/cassandrafullquerylog ``` -------------------------------- ### Grant SELECT Permission Example Source: https://github.com/apache/cassandra/blob/trunk/doc/modules/cassandra/pages/developing/cql/security.adoc Example of granting SELECT permission to a role on all tables across all keyspaces. ```cql include::cassandra:example$CQL/grant_perm.cql[] ``` -------------------------------- ### Example DROP AGGREGATE Statement Source: https://github.com/apache/cassandra/blob/trunk/doc/modules/cassandra/pages/developing/cql/functions.adoc An example of how to drop a user-defined aggregate function in CQL, specifying its signature. ```sql DROP AGGREGATE IF EXISTS my_aggregate (int, text) ``` -------------------------------- ### Create Keyspace with Auto-Expanding and Datacenter Override Source: https://github.com/apache/cassandra/blob/trunk/doc/modules/cassandra/pages/developing/cql/ddl.adoc Demonstrates creating a keyspace with auto-expanding enabled and overriding replication settings for a specific datacenter. ```cql CREATE KEYSPACE my_keyspace WITH replication = {'class': 'NetworkTopologyStrategy', 'replication_factor': 3, 'datacenter1': 3, 'datacenter2': 3} AND auto_expand = true; ``` -------------------------------- ### Example User-Defined Aggregate Source: https://github.com/apache/cassandra/blob/trunk/doc/modules/cassandra/pages/developing/cql/functions.adoc A complete example demonstrating the creation and usage of a user-defined aggregate function in CQL. ```sql CREATE OR REPLACE FUNCTION sum_state(state int, val int) RETURNS int LANGUAGE java AS $$ if (val == null) { return state; } if (state == null) { return val; } return state + val; ;$$; CREATE OR REPLACE FUNCTION sum_final(state int) RETURNS int LANGUAGE java AS $$ return state; ;$$; CREATE OR REPLACE AGGREGATE sum(int) SFUNC sum_state STYPE int FINALFUNC sum_final // INITCOND 0 // Optional: default is null ; CREATE TABLE IF NOT EXISTS test (id int PRIMARY KEY, val int); INSERT INTO test (id, val) VALUES (1, 10); INSERT INTO test (id, val) VALUES (2, 20); INSERT INTO test (id, val) VALUES (3, 30); SELECT sum(val) FROM test; DROP AGGREGATE sum(int); DROP FUNCTION sum_final(int); DROP FUNCTION sum_state(int, int); ``` -------------------------------- ### Example cassandra-topologies.properties File Source: https://github.com/apache/cassandra/blob/trunk/doc/modules/cassandra/pages/managing/configuration/cass_topo_file.adoc This snippet shows an example of the cassandra-topologies.properties file, defining three datacenters (DC1, DC2, DC3) with multiple racks (RAC1, RAC2) and a default configuration for unknown nodes. Ensure this file is identical on all cluster nodes. ```properties # datacenter One 175.56.12.105=DC1:RAC1 175.50.13.200=DC1:RAC1 175.54.35.197=DC1:RAC1 120.53.24.101=DC1:RAC2 120.55.16.200=DC1:RAC2 120.57.102.103=DC1:RAC2 # datacenter Two 110.56.12.120=DC2:RAC1 110.50.13.201=DC2:RAC1 110.54.35.184=DC2:RAC1 50.33.23.120=DC2:RAC2 50.45.14.220=DC2:RAC2 50.17.10.203=DC2:RAC2 # datacenter Three 172.106.12.120=DC3:RAC1 172.106.12.121=DC3:RAC1 172.106.12.122=DC3:RAC1 # default for unknown nodes default =DC3:RAC1 ``` -------------------------------- ### Drop Function Example Source: https://github.com/apache/cassandra/blob/trunk/doc/modules/cassandra/pages/developing/cql/functions.adoc An example of dropping a user-defined function in CQL, specifying argument types if overloaded. ```sql include::cassandra:example$CQL/drop_function.cql[] ``` -------------------------------- ### INSERT Statement Example Source: https://github.com/apache/cassandra/blob/trunk/doc/modules/cassandra/pages/developing/cql/dml.adoc An example of how to insert data for a row into a Cassandra table using the INSERT statement. ```cql INSERT INTO users (id, name, email) VALUES (1, 'John Doe', 'john.doe@example.com'); ```