From 709ae29fd8947dfe4479dc73930e786d226b8a48 Mon Sep 17 00:00:00 2001 From: Lorina Poland Date: Thu, 9 Nov 2023 12:18:41 -0800 Subject: [PATCH] Docs: Fix vsearch missing files Remove Accord from What's New. Add missing reference files for create/drop table and partials. Add missing examples. patch by Lorina Poland; reviewed by Mick Semb Wever for CASSANDRA-18604 --- .../cassandra/examples/CQL/comments-table.cql | 104 ++++ .../examples/CQL/country_flag-table.cql | 84 +++ .../examples/CQL/cyclist_base-table.cql | 84 +++ .../examples/CQL/cyclist_category-table.cql | 118 +++++ .../examples/CQL/cyclist_emails-table.cql | 35 ++ .../examples/CQL/cyclist_expenses-table.cql | 216 ++++++++ .../examples/CQL/cyclist_id-table.cql | 77 +++ .../examples/CQL/cyclist_name-table.cql | 486 ++++++++++++++++++ .../examples/CQL/cyclist_races-table.cql | 62 +++ .../examples/CQL/popular_count-table.cql | 42 ++ .../examples/CQL/race_times-table.cql | 43 ++ .../examples/CQL/race_winners-table.cql | 73 +++ .../CQL/rank_by_year_and_name-table.cql | 136 +++++ .../examples/CQLSH/comments-desc_table.cqlsh | 1 + .../RESULTS/comments-desc_table.result | 21 + ...er_batch_food_from_cyclist_expenses.result | 7 + ...er_batch_paid_from_cyclist_expenses.result | 7 + ..._after_update_from_cyclist_expenses.result | 5 + .../select_initial_from_country_flag.result | 8 + ...elect_initial_from_cyclist_expenses.result | 5 + .../cassandra/examples/RESULTS/true.result | 3 + doc/modules/cassandra/nav.adoc | 10 +- doc/modules/cassandra/pages/new/index.adoc | 2 - .../reference/cql-commands/create-index.adoc | 9 +- .../cql-commands/create-table-examples.adoc | 98 ++++ .../reference/cql-commands/create-table.adoc | 95 ++++ .../reference/cql-commands/drop-table.adoc | 52 ++ .../_query-vector-data-cycling.adoc | 8 +- .../pages/vector-search/overview.adoc | 6 +- .../vector-search-working-with.adoc | 13 + .../cassandra/partials/cluster-order.adoc | 14 + .../partials/compact-subproperties.adoc | 262 ++++++++++ .../partials/compaction-strategies.adoc | 9 + .../partials/compress-subproperties.adoc | 69 +++ .../partials/primary-key-column.adoc | 29 ++ .../partials/single-partition-batch-note.adoc | 10 + .../partials/table-column-definitions.adoc | 29 ++ .../cassandra/partials/table-properties.adoc | 146 ++++++ 38 files changed, 2463 insertions(+), 15 deletions(-) create mode 100644 doc/modules/cassandra/examples/CQL/comments-table.cql create mode 100644 doc/modules/cassandra/examples/CQL/country_flag-table.cql create mode 100644 doc/modules/cassandra/examples/CQL/cyclist_base-table.cql create mode 100644 doc/modules/cassandra/examples/CQL/cyclist_category-table.cql create mode 100644 doc/modules/cassandra/examples/CQL/cyclist_emails-table.cql create mode 100644 doc/modules/cassandra/examples/CQL/cyclist_expenses-table.cql create mode 100644 doc/modules/cassandra/examples/CQL/cyclist_id-table.cql create mode 100644 doc/modules/cassandra/examples/CQL/cyclist_name-table.cql create mode 100644 doc/modules/cassandra/examples/CQL/cyclist_races-table.cql create mode 100644 doc/modules/cassandra/examples/CQL/popular_count-table.cql create mode 100644 doc/modules/cassandra/examples/CQL/race_times-table.cql create mode 100644 doc/modules/cassandra/examples/CQL/race_winners-table.cql create mode 100644 doc/modules/cassandra/examples/CQL/rank_by_year_and_name-table.cql create mode 100644 doc/modules/cassandra/examples/CQLSH/comments-desc_table.cqlsh create mode 100644 doc/modules/cassandra/examples/RESULTS/comments-desc_table.result create mode 100644 doc/modules/cassandra/examples/RESULTS/select_after_batch_food_from_cyclist_expenses.result create mode 100644 doc/modules/cassandra/examples/RESULTS/select_after_batch_paid_from_cyclist_expenses.result create mode 100644 doc/modules/cassandra/examples/RESULTS/select_after_update_from_cyclist_expenses.result create mode 100644 doc/modules/cassandra/examples/RESULTS/select_initial_from_country_flag.result create mode 100644 doc/modules/cassandra/examples/RESULTS/select_initial_from_cyclist_expenses.result create mode 100644 doc/modules/cassandra/examples/RESULTS/true.result create mode 100644 doc/modules/cassandra/pages/reference/cql-commands/create-table-examples.adoc create mode 100644 doc/modules/cassandra/pages/reference/cql-commands/create-table.adoc create mode 100644 doc/modules/cassandra/pages/reference/cql-commands/drop-table.adoc create mode 100644 doc/modules/cassandra/pages/vector-search/vector-search-working-with.adoc create mode 100644 doc/modules/cassandra/partials/cluster-order.adoc create mode 100644 doc/modules/cassandra/partials/compact-subproperties.adoc create mode 100644 doc/modules/cassandra/partials/compaction-strategies.adoc create mode 100644 doc/modules/cassandra/partials/compress-subproperties.adoc create mode 100644 doc/modules/cassandra/partials/primary-key-column.adoc create mode 100644 doc/modules/cassandra/partials/single-partition-batch-note.adoc create mode 100644 doc/modules/cassandra/partials/table-column-definitions.adoc create mode 100644 doc/modules/cassandra/partials/table-properties.adoc diff --git a/doc/modules/cassandra/examples/CQL/comments-table.cql b/doc/modules/cassandra/examples/CQL/comments-table.cql new file mode 100644 index 0000000000..7ce38f5218 --- /dev/null +++ b/doc/modules/cassandra/examples/CQL/comments-table.cql @@ -0,0 +1,104 @@ +SOURCE 'keyspace-create-simple.cql'; +SOURCE 'keyspace-use.cql'; + +// tag::drop[] +DROP TABLE IF EXISTS cycling.comments; +// end::drop[] + +/* Support fast retrieval of first record on each partition + and show upserts of timestamp type fields */ + +// tag::comments-table[] +CREATE TABLE IF NOT EXISTS cycling.comments ( + record_id timeuuid, + id uuid, + commenter text, + comment text, + created_at timestamp, + PRIMARY KEY (id, created_at) +) +WITH CLUSTERING ORDER BY (created_at DESC); +// end::comments-table[] + +DROP INDEX IF EXISTS cycling.fn_sparse; + +// tag::fn_sparse[] +CREATE CUSTOM INDEX IF NOT EXISTS fn_sparse +ON cycling.comments (created_at) +USING 'org.apache.cassandra.index.sasi.SASIIndex' +WITH OPTIONS = { 'mode': 'SPARSE' }; +// end::fn_sparse[] + +// tag::insertall[] +INSERT INTO cycling.comments (record_id, id, created_at, comment, commenter) VALUES (now(), e7ae5cf3-d358-4d99-b900-85902fda9bb0, '2017-02-14 12:43:20-0800', 'Raining too hard should have postponed', 'Alex'); +INSERT INTO cycling.comments (record_id, id, created_at, comment, commenter) VALUES (now(), e7ae5cf3-d358-4d99-b900-85902fda9bb0, '2017-02-14 12:43:20.234-0800', 'Raining too hard should have postponed', 'Alex'); +INSERT INTO cycling.comments (record_id, id, created_at, comment, commenter) VALUES (now(), e7ae5cf3-d358-4d99-b900-85902fda9bb0, '2017-03-21 13:11:09.999-0800', 'Second rest stop was out of water', 'Alex'); +INSERT INTO cycling.comments (record_id, id, created_at, comment, commenter) VALUES (now(), e7ae5cf3-d358-4d99-b900-85902fda9bb0, '2017-04-01 06:33:02.16-0800', 'LATE RIDERS SHOULD NOT DELAY THE START', 'Alex'); +INSERT INTO cycling.comments (record_id, id, created_at, comment, commenter) VALUES (now(), c7fceba0-c141-4207-9494-a29f9809de6f, totimestamp(now()), 'The gift certificate for winning was the best', 'Amy'); +INSERT INTO cycling.comments (record_id, id, created_at, comment, commenter) VALUES (now(), c7fceba0-c141-4207-9494-a29f9809de6f, '2017-02-17 12:43:20.234+0400', 'Glad you ran the race in the rain', 'Amy'); +INSERT INTO cycling.comments (record_id, id, created_at, comment, commenter) VALUES (now(), c7fceba0-c141-4207-9494-a29f9809de6f, '2017-03-22 5:16:59.001+0400', 'Great snacks at all reststops', 'Amy'); +INSERT INTO cycling.comments (record_id, id, created_at, comment, commenter) VALUES (now(), c7fceba0-c141-4207-9494-a29f9809de6f, '2017-04-01 17:43:08.030+0400', 'Last climb was a killer', 'Amy'); +INSERT INTO cycling.comments (record_id, id, created_at, comment, commenter) VALUES (now(), 8566eb59-07df-43b1-a21b-666a3c08c08a, totimestamp(now()), 'Fastest womens time ever way to go amy!', 'Maryanne'); +INSERT INTO cycling.comments (record_id, id, created_at, comment, commenter) VALUES (now(), 8566eb59-07df-43b1-a21b-666a3c08c08a, '2017-02-13 11:20:17.020-0600', 'Great race on a crappy day', 'Maryanne'); +INSERT INTO cycling.comments (record_id, id, created_at, comment, commenter) VALUES (now(), 8566eb59-07df-43b1-a21b-666a3c08c08a, '2017-03-20 15:45:10.101-0600', 'Saggers really rocked it', 'Maryanne'); +INSERT INTO cycling.comments (record_id, id, created_at, comment, commenter) VALUES (now(), 8566eb59-07df-43b1-a21b-666a3c08c08a, '2017-04-14 05:16:52.009-0600', 'Not bad for a flatlander', 'Maryanne'); +INSERT INTO cycling.comments (record_id, id, created_at, comment, commenter) VALUES (now(), fb372533-eb95-4bb4-8685-6ef61e994caa, totimestamp(now()), 'Great course', 'Michael'); +INSERT INTO cycling.comments (record_id, id, created_at, comment, commenter) VALUES (now(), fb372533-eb95-4bb4-8685-6ef61e994caa, '2017-02-15 18:22:11-0800', 'Some entries complain a lot', 'Michael'); +INSERT INTO cycling.comments (record_id, id, created_at, comment, commenter) VALUES (now(), fb372533-eb95-4bb4-8685-6ef61e994caa, '2017-03-16 19:43:01.030-0800', 'Getting read for the race', 'Michael'); +INSERT INTO cycling.comments (record_id, id, created_at, comment, commenter) VALUES (now(), fb372533-eb95-4bb4-8685-6ef61e994caa, '2017-03-22 1:19:44.060-0800', 'Awesome race glad you held it anyway', 'Michael'); +INSERT INTO cycling.comments (record_id, id, created_at, comment, commenter) VALUES (now(), fb372533-eb95-4bb4-8685-6ef61e994caa, '2017-04-07 11:21:14.001-0800', 'Thanks for waiting for me!', 'Michael'); +INSERT INTO cycling.comments (record_id, id, created_at, comment, commenter) VALUES (now(), 9011d3be-d35c-4a8d-83f7-a3c543789ee7, totimestamp(now()), 'Can''t wait for the next race', 'Katarzyna'); +INSERT INTO cycling.comments (record_id, id, created_at, comment, commenter) VALUES (now(), 9011d3be-d35c-4a8d-83f7-a3c543789ee7, '2017-01-01 11:20:17.020-0600', 'Gearing up for the seaon', 'Katarzyna'); +INSERT INTO cycling.comments (record_id, id, created_at, comment, commenter) VALUES (now(), 5b6962dd-3f90-4c93-8f61-eabfa4a803e2, totimestamp(now()), 'Thanks for all your hard work', 'Marianne'); +INSERT INTO cycling.comments (record_id, id, created_at, comment, commenter) VALUES (now(), 220844bf-4860-49d6-9a4b-6b5d3a79cbfb, totimestamp(now()), 'A for effort!', 'Paolo'); +INSERT INTO cycling.comments (record_id, id, created_at, comment, commenter) VALUES (now(), c4b65263-fe58-4846-83e8-f0e1c13d518f, totimestamp(now()), 'Closing ceremony was a little lame', 'Rossella'); +INSERT INTO cycling.comments (record_id, id, created_at, comment, commenter) VALUES (now(), 38ab64b6-26cc-4de9-ab28-c257cf011659, totimestamp(now()), 'Next time guys!', 'Marcia'); +INSERT INTO cycling.comments (record_id, id, created_at, comment, commenter) VALUES (now(), 38ab64b6-26cc-4de9-ab28-c257cf011659, '2017-02-11 22:09:56+0800', 'First race was amazing, can''t wait for more', 'Marcia'); +INSERT INTO cycling.comments (record_id, id, created_at, comment, commenter) VALUES (now(), 6ab09bec-e68e-48d9-a5f8-97e6fb4c9b47, totimestamp(now()), 'So many great races thanks y''all', 'Steven'); +INSERT INTO cycling.comments (record_id, id, created_at, comment, commenter) VALUES (now(), 6ab09bec-e68e-48d9-a5f8-97e6fb4c9b47, '2017-02-02 09:49:00.02+0800', 'Best of luck everybody I can''t make it', 'Steven'); +INSERT INTO cycling.comments (record_id, id, created_at, comment, commenter) VALUES (now(), 6ab09bec-e68e-48d9-a5f8-97e6fb4c9b47, '2017-04-05 12:01:00.003', 'Bike damaged in transit bummer', 'Steven'); +INSERT INTO cycling.comments (record_id, id, created_at, comment, commenter) VALUES (now(), e7cd5752-bc0d-4157-a80f-7523add8dbcd, totimestamp(now()), 'Go team, you rocked it', 'Anna'); +INSERT INTO cycling.comments (record_id, id, created_at, comment, commenter) VALUES (now(), 6d5f1663-89c0-45fc-8cfd-60a373b01622, totimestamp(now()), 'Next year the tour of california!', 'Melissa'); +INSERT INTO cycling.comments (record_id, id, created_at, comment, commenter) VALUES (now(), 95addc4c-459e-4ed7-b4b5-472f19a67995, totimestamp(now()), 'Next year for sure!', 'Vera'); +INSERT INTO cycling.comments (record_id, id, created_at, comment, commenter) VALUES (now(), 95addc4c-459e-4ed7-b4b5-472f19a67995, '2017-02-13 11:40:16.123-0600', 'I can do without the rain@@@@', 'Vera'); +// end::insertall[] + +CAPTURE 'select_from_comments.results'; +// tag::select[] +SELECT * +FROM cycling.comments +WHERE created_at < '2017-02-13 11:40:16.123'; +// end::select[] +CAPTURE OFF; + +// tag::alt[] +ALTER TABLE cycling.comments +WITH compression = { + 'sstable_compression' : 'DeflateCompressor', + 'chunk_length_kb' : 64 +}; +// end::alt[] + +// tag::cache[] +ALTER TABLE cycling.comments +WITH caching = { + 'keys' : 'NONE', + 'rows_per_partition' : 10 +}; +// end::cache[] + +// tag::nocompact[] +ALTER TABLE cycling.comments +WITH COMPACTION = { + 'class' : 'SizeTieredCompactionStrategy', + 'enabled' : 'false' +}; +// end::nocompact[] + +// tag::compaction[] +ALTER TABLE cycling.comments +WITH COMPACTION = { + 'class' : 'SizeTieredCompactionStrategy', + 'enabled' : 'true' +}; +// end::compaction[] \ No newline at end of file diff --git a/doc/modules/cassandra/examples/CQL/country_flag-table.cql b/doc/modules/cassandra/examples/CQL/country_flag-table.cql new file mode 100644 index 0000000000..7cf6f7c4c5 --- /dev/null +++ b/doc/modules/cassandra/examples/CQL/country_flag-table.cql @@ -0,0 +1,84 @@ +// CREATE TABLE WITH STATIC COLUMN, example uses an integer to identify flag, but it could be a blob +SOURCE 'keyspace-create-simple.cql'; +SOURCE 'keyspace-use.cql'; + +DROP TABLE IF EXISTS cycling.country_flag; + +// tag::staticColumn[] +CREATE TABLE IF NOT EXISTS cycling.country_flag ( + country text, + cyclist_name text, + flag int STATIC, + PRIMARY KEY (country, cyclist_name) +); +// end::staticColumn[] + +// tag::insert[] +INSERT INTO cycling.country_flag ( + country, cyclist_name, flag +) VALUES ( + 'Belgium', 'Jacques', 1 +); + +INSERT INTO cycling.country_flag ( + country, cyclist_name +) VALUES ( + 'Belgium', 'Andre' +); + +INSERT INTO cycling.country_flag ( + country, cyclist_name, flag +) VALUES ( + 'France', 'Andre', 2 +); + +INSERT INTO cycling.country_flag ( + country, cyclist_name, flag +) VALUES ( + 'France', 'George', 3 +); +// end::insert[] + +CAPTURE 'select_initial_from_country_flag.results'; +// Query to view inserted data +// tag::select[] +SELECT * +FROM cycling.country_flag; +// end::select[] +CAPTURE OFF; + +// Truncate data without dropping the table +// tag::truncate[] +TRUNCATE cycling.country_flag; +// end::truncate[] + +// Query again to view data truncated from table +// tag::emptytable[] +SELECT * +FROM cycling.country_flag; +// end::emptytable[] + +// Insert data again +INSERT INTO cycling.country_flag ( + country, cyclist_name, flag +) VALUES ( + 'Belgium', 'Jacques', 1 +); + +INSERT INTO cycling.country_flag ( + country, cyclist_name +) VALUES ( + 'Belgium', 'Andre' +); + +INSERT INTO cycling.country_flag ( + country, cyclist_name, flag +) VALUES ( + 'France', 'Andre', 2 +); + +INSERT INTO cycling.country_flag ( + country, cyclist_name, flag +) VALUES ( + 'France', 'George', 3 +); \ No newline at end of file diff --git a/doc/modules/cassandra/examples/CQL/cyclist_base-table.cql b/doc/modules/cassandra/examples/CQL/cyclist_base-table.cql new file mode 100644 index 0000000000..8978d722d7 --- /dev/null +++ b/doc/modules/cassandra/examples/CQL/cyclist_base-table.cql @@ -0,0 +1,84 @@ +SOURCE 'keyspace-create-simple.cql'; +SOURCE 'keyspace-use.cql'; + +DROP TABLE IF EXISTS cycling.cyclist_base; + +// tag::cyclist_base[] +CREATE TABLE IF NOT EXISTS cycling.cyclist_base ( + cid UUID PRIMARY KEY, + name text, + age int, + birthday date, + country text +); +// end::cyclist_base[] + +// tag::data[] +INSERT INTO cycling.cyclist_base ( + cid,name,age,birthday,country +) VALUES ( + e7ae5cf3-d358-4d99-b900-85902fda9bb0,'Alex FRAME', 22, '1993-06-18', 'New Zealand' +); + +INSERT INTO cycling.cyclist_base ( + cid,name,age,birthday,country +) VALUES ( + 220844bf-4860-49d6-9a4b-6b5d3a79cbfb,'Paolo TIRALONGO', 38, '1977-07-08', 'Italy' +); + +INSERT INTO cycling.cyclist_base ( + cid,name,age,birthday,country +) VALUES ( + 6ab09bec-e68e-48d9-a5f8-97e6fb4c9b47,'Steven KRUIKSWIJK', 28, '1987-06-07', 'Netherlands' +); + +INSERT INTO cycling.cyclist_base ( + cid,name,age,birthday,country +) VALUES ( + ffdfa2a7-5fc6-49a7-bfdc-3fcdcfdd7156,'Pascal EENKHOORN', 18, '1997-02-08', 'Netherlands' +); + +INSERT INTO cycling.cyclist_base ( + cid,name,age,birthday,country +) VALUES ( + 18f471bf-f631-4bc4-a9a2-d6f6cf5ea503,'Bram WELTEN', 18, '1997-03-29', 'Netherlands' +); + +INSERT INTO cycling.cyclist_base ( + cid,name,age,birthday,country +) VALUES ( + 15a116fc-b833-4da6-ab9a-4a7775752836,'Adrien COSTA', 18, '1997-08-19', 'United States' +); + +INSERT INTO cycling.cyclist_base ( + cid,name,age,birthday,country +) VALUES ( + 862cc51f-00a1-4d5a-976b-a359cab7300e,'Joakim BUKDAL', 20, '1994-09-04', 'Denmark' +); + +INSERT INTO cycling.cyclist_base ( + cid,name,age,birthday,country +) VALUES ( + c9c9c484-5e4a-4542-8203-8d047a01b8a8,'Cristian EGIDIO', 27, '1987-09-04', 'Brazil' +); +// end::data[] + +CAPTURE 'select_all_from_cyclist_base.results'; +SELECT * +FROM cycling.cyclist_base; +CAPTURE OFF; + +// tag::alt[] +ALTER TABLE cycling.cyclist_base +WITH comment = 'basic cyclist information'; +// end::alt[] + +// tag::specr[] +ALTER TABLE cycling.cyclist_base +WITH speculative_retry = '95percentile'; +// end::specr[] + +// tag::milli[] +ALTER TABLE cycling.cyclist_base +WITH speculative_retry = '10ms'; +// end::milli[] \ No newline at end of file diff --git a/doc/modules/cassandra/examples/CQL/cyclist_category-table.cql b/doc/modules/cassandra/examples/CQL/cyclist_category-table.cql new file mode 100644 index 0000000000..6b0c8566d7 --- /dev/null +++ b/doc/modules/cassandra/examples/CQL/cyclist_category-table.cql @@ -0,0 +1,118 @@ +// Find cyclists that fit a particular category + +SOURCE 'keyspace-create-simple.cql'; +SOURCE 'keyspace-use.cql'; + +// CREATE TABLE CLUSTERING ORDER, PRIMARY KEY: PARTITION KEY + 1 CLUSTERING COLUMN, SIMPLE WHERE QUERY + +DROP TABLE IF EXISTS cycling.cyclist_category; + +// tag::use_and_cpartitionkey[] +USE cycling; +CREATE TABLE IF NOT EXISTS cyclist_category ( + category text, + points int, + id UUID, + lastname text, + PRIMARY KEY (category, points) +) +WITH CLUSTERING ORDER BY (points DESC); +// end::use_and_cpartitionkey[] + +DROP TABLE IF EXISTS cycling.cyclist_category; + +// tag::cpartitionkey[] +CREATE TABLE IF NOT EXISTS cycling.cyclist_category ( + category text, + points int, + id UUID, + lastname text, + PRIMARY KEY (category, points) +) +WITH CLUSTERING ORDER BY (points DESC); +// end::cpartitionkey[] + +INSERT INTO cycling.cyclist_category (category, points, id, lastname) VALUES ('GC',1269,220844bf-4860-49d6-9a4b-6b5d3a79cbfb,'TIRALONGO'); +INSERT INTO cycling.cyclist_category (category, points, id, lastname) VALUES ('One-day-races',367,220844bf-4860-49d6-9a4b-6b5d3a79cbfb,'TIRALONGO'); +INSERT INTO cycling.cyclist_category (category, points, id, lastname) VALUES ('Time-trial',182,220844bf-4860-49d6-9a4b-6b5d3a79cbfb,'TIRALONGO'); +INSERT INTO cycling.cyclist_category (category, points, id, lastname) VALUES ('Sprint',0,220844bf-4860-49d6-9a4b-6b5d3a79cbfb,'TIRALONGO'); +INSERT INTO cycling.cyclist_category (category, points, id, lastname) VALUES ('GC',1324,6ab09bec-e68e-48d9-a5f8-97e6fb4c9b47,'KRUIJSWIJK'); +INSERT INTO cycling.cyclist_category (category, points, id, lastname) VALUES ('One-day-races',198,6ab09bec-e68e-48d9-a5f8-97e6fb4c9b47,'KRUIJSWIJK'); +INSERT INTO cycling.cyclist_category (category, points, id, lastname) VALUES ('Sprint',39,6ab09bec-e68e-48d9-a5f8-97e6fb4c9b47,'KRUIJSWIJK'); +INSERT INTO cycling.cyclist_category (category, points, id, lastname) VALUES ('Time-trial',3,6ab09bec-e68e-48d9-a5f8-97e6fb4c9b47,'KRUIJSWIJK'); + +// tag::rows[] +RESTRICT ROWS ON cycling.cyclist_category USING category; +// end::rows[] + +CAPTURE 'select_all_from_cyclist_category_order_by_descending_points.results'; +// tag::select_compound_primary_key[] +SELECT * +FROM cycling.cyclist_category +WHERE category = 'Time-trial' +ORDER BY points DESC; +// end::select_compound_primary_key[] +CAPTURE OFF; + +// Add JSON rows + +// tag::insert_SUTHERLAND[] +INSERT INTO cycling.cyclist_category JSON '{ + "category" : "GC", + "points" : 780, + "id" : "829aa84a-4bba-411f-a4fb-38167a987cda", + "lastname" : "SUTHERLAND" +}'; +// end::insert_SUTHERLAND[] + +// tag::clear_lastname[] +INSERT INTO cycling.cyclist_category JSON '{ + "category" : "Sprint", + "points" : 780, + "id" : "829aa84a-4bba-411f-a4fb-38167a987cda" +}'; +// end::clear_lastname[] + +// tag::unset[] +INSERT INTO cycling.cyclist_category JSON '{ + "category" : "Sprint", + "points" : 780, + "id" : "829aa84a-4bba-411f-a4fb-38167a987cda" +}' +DEFAULT UNSET; +// end::unset[] + +// tag::set_points[] +INSERT INTO cycling.cyclist_category JSON '{ + "category" : "Sprint", + "points" : 700, + "id" : "829aa84a-4bba-411f-a4fb-38167a987cda" +}'; +// end::set_points[] + +CAPTURE 'select_all_from_cyclist_category.results'; +// tag::select_all_rows[] +SELECT * +FROM cycling.cyclist_category; +// end::select_all_rows[] +CAPTURE OFF; + +// tag::copy[] +COPY cycling.cyclist_category +FROM 'cyclist_category.csv' +WITH DELIMITER = '|' + AND HEADER = TRUE; +// end::copy[] + +// Truncate table +TRUNCATE TABLE cycling.cyclist_category; + +// Re-insert data +INSERT INTO cycling.cyclist_category (category, points, id, lastname) VALUES ('GC',1269,220844bf-4860-49d6-9a4b-6b5d3a79cbfb,'TIRALONGO'); +INSERT INTO cycling.cyclist_category (category, points, id, lastname) VALUES ('One-day-races',367,220844bf-4860-49d6-9a4b-6b5d3a79cbfb,'TIRALONGO'); +INSERT INTO cycling.cyclist_category (category, points, id, lastname) VALUES ('Time-trial',182,220844bf-4860-49d6-9a4b-6b5d3a79cbfb,'TIRALONGO'); +INSERT INTO cycling.cyclist_category (category, points, id, lastname) VALUES ('Sprint',0,220844bf-4860-49d6-9a4b-6b5d3a79cbfb,'TIRALONGO'); +INSERT INTO cycling.cyclist_category (category, points, id, lastname) VALUES ('GC',1324,6ab09bec-e68e-48d9-a5f8-97e6fb4c9b47,'KRUIJSWIJK'); +INSERT INTO cycling.cyclist_category (category, points, id, lastname) VALUES ('One-day-races',198,6ab09bec-e68e-48d9-a5f8-97e6fb4c9b47,'KRUIJSWIJK'); +INSERT INTO cycling.cyclist_category (category, points, id, lastname) VALUES ('Sprint',39,6ab09bec-e68e-48d9-a5f8-97e6fb4c9b47,'KRUIJSWIJK'); +INSERT INTO cycling.cyclist_category (category, points, id, lastname) VALUES ('Time-trial',3,6ab09bec-e68e-48d9-a5f8-97e6fb4c9b47,'KRUIJSWIJK'); diff --git a/doc/modules/cassandra/examples/CQL/cyclist_emails-table.cql b/doc/modules/cassandra/examples/CQL/cyclist_emails-table.cql new file mode 100644 index 0000000000..61d12e0194 --- /dev/null +++ b/doc/modules/cassandra/examples/CQL/cyclist_emails-table.cql @@ -0,0 +1,35 @@ +SOURCE 'keyspace-create-simple.cql'; +SOURCE 'keyspace-use.cql'; + +DROP TABLE IF EXISTS cycling.cyclist_emails; + +// Create a table with a known table id +// tag::ID[] +CREATE TABLE IF NOT EXISTS cycling.cyclist_emails ( + userid text PRIMARY KEY, + id UUID, + emails set +) +WITH ID = '1bb7516e-b140-11e8-96f8-529269fb1459'; +// end::ID[] + +// Drop table +DROP TABLE IF EXISTS cycling.cyclist_emails; + +// Create table again with a known table id +// tag::recreateID[] +CREATE TABLE IF NOT EXISTS cycling.cyclist_emails ( + userid text PRIMARY KEY, + id UUID, + emails set +) +WITH ID = '1bb7516e-b140-11e8-96f8-529269fb1459'; +// end::recreateID[] + +// Retrieve the table id +// tag::select_id_from_system_schema[] +SELECT id +FROM system_schema.tables +WHERE keyspace_name = 'cycling' + AND table_name = 'cyclist_emails'; +// end::select_id_from_system_schema[] diff --git a/doc/modules/cassandra/examples/CQL/cyclist_expenses-table.cql b/doc/modules/cassandra/examples/CQL/cyclist_expenses-table.cql new file mode 100644 index 0000000000..c36bf346b9 --- /dev/null +++ b/doc/modules/cassandra/examples/CQL/cyclist_expenses-table.cql @@ -0,0 +1,216 @@ +SOURCE 'keyspace-create-simple.cql'; +SOURCE 'keyspace-use.cql'; + +DROP TABLE IF EXISTS cycling.cyclist_expenses; + +// tag::create_table[] +CREATE TABLE IF NOT EXISTS cycling.cyclist_expenses ( + cyclist_name text, + balance float STATIC, + expense_id int, + amount float, + description text, + paid boolean, + PRIMARY KEY (cyclist_name, expense_id) +); +// end::create_table[] + +// tag::batch_Vera[] +BEGIN BATCH + + INSERT INTO cycling.cyclist_expenses ( + cyclist_name, balance + ) VALUES ( + 'Vera ADRIAN', 0 + ) IF NOT EXISTS; + + INSERT INTO cycling.cyclist_expenses ( + cyclist_name, expense_id, amount, description, paid + ) VALUES ( + 'Vera ADRIAN', 1, 7.95, 'Breakfast', false + ); + +APPLY BATCH; +// end::batch_Vera[] + +CAPTURE 'select_initial_from_cyclist_expenses.results'; +// tag::select_initial[] +SELECT * +FROM cycling.cyclist_expenses; +// end::select_initial[] +CAPTURE OFF; + +// tag::update_Vera[] +UPDATE cycling.cyclist_expenses +SET balance = -7.95 +WHERE cyclist_name = 'Vera ADRIAN' +IF balance = 0; +// end::update_Vera[] + +CAPTURE 'select_after_update_from_cyclist_expenses.results'; +SELECT * +FROM cycling.cyclist_expenses; +CAPTURE OFF; + +// tag::batch_food[] +BEGIN BATCH + + INSERT INTO cycling.cyclist_expenses ( + cyclist_name, expense_id, amount, description, paid + ) VALUES ( + 'Vera ADRIAN', 2, 13.44, 'Lunch', true + ); + + INSERT INTO cycling.cyclist_expenses ( + cyclist_name, expense_id, amount, description, paid + ) VALUES ( + 'Vera ADRIAN', 3, 25.00, 'Dinner', false + ); + + UPDATE cycling.cyclist_expenses + SET balance = -32.95 + WHERE cyclist_name = 'Vera ADRIAN' + IF balance = -7.95; + +APPLY BATCH; +// end::batch_food[] + +CAPTURE 'select_after_batch_food_from_cyclist_expenses.results'; +SELECT * +FROM cycling.cyclist_expenses; +CAPTURE OFF; + +// tag::batch_paid[] +BEGIN BATCH + + UPDATE cycling.cyclist_expenses + SET balance = 0 + WHERE cyclist_name = 'Vera ADRIAN' + IF balance = -32.95; + + UPDATE cycling.cyclist_expenses + SET paid = true + WHERE cyclist_name = 'Vera ADRIAN' + AND expense_id = 1 IF paid = false; + + UPDATE cycling.cyclist_expenses + SET paid = true + WHERE cyclist_name = 'Vera ADRIAN' + AND expense_id = 3 + IF paid = false; + +APPLY BATCH; +// end::batch_paid[] + +CAPTURE 'select_after_batch_paid_from_cyclist_expenses.results'; +SELECT * +FROM cycling.cyclist_expenses; +CAPTURE OFF; + +// tag::batch_multiple_partitions[] +BEGIN BATCH + + INSERT INTO cycling.cyclist_expenses ( + cyclist_name, expense_id, amount, description, paid + ) VALUES ( + 'John SMITH', 3, 15.00, 'Lunch', false + ); + + INSERT INTO cycling.cyclist_name ( + id, lastname, firstname + ) VALUES ( + 6ab09bec-e68e-48d9-a5f8-97e6fb4c9b12, 'SMITH', 'John' + ); + +APPLY BATCH; +// end::batch_multiple_partitions[] + +DELETE FROM cycling.cyclist_name +WHERE id = 6ab09bec-e68e-48d9-a5f8-97e6fb4c9b12; + +TRUNCATE TABLE cycling.cyclist_expenses; + +// tag::batch[] +BEGIN BATCH USING TIMESTAMP 1481124356754405 + + INSERT INTO cycling.cyclist_expenses ( + cyclist_name, expense_id, amount, description, paid + ) VALUES ( + 'Vera ADRIAN', 2, 13.44, 'Lunch', true + ); + + INSERT INTO cycling.cyclist_expenses ( + cyclist_name, expense_id, amount, description, paid + ) VALUES ( + 'Vera ADRIAN', 3, 25.00, 'Dinner', true + ); + +APPLY BATCH; +// end::batch[] + +// tag::con[] +BEGIN BATCH + + INSERT INTO cycling.cyclist_expenses ( + cyclist_name, expense_id + ) VALUES ( + 'Joe WALLS', 1 + ) + IF NOT EXISTS; + + INSERT INTO cycling.cyclist_expenses ( + cyclist_name, expense_id, amount, description, paid + ) VALUES ( + 'Joe WALLS', 1, 8, 'burrito', false + ); + +APPLY BATCH; +// end::con[] + +insert into cycling.cyclist_expenses (cyclist_name,expense_id,amount,description) values ('Anna VAN DER BREGGEN',1,50,'dinner'); +insert into cycling.cyclist_expenses (cyclist_name,expense_id,amount,description) values ('Anna VAN DER BREGGEN',2,50,'lunch'); +insert into cycling.cyclist_expenses (cyclist_name,expense_id,amount,description) values ('Michael MATTHEWS',3,25,'lunch'); +insert into cycling.cyclist_expenses (cyclist_name,expense_id,amount,description) values ('Michael MATTHEWS',4,25,'lunch'); +insert into cycling.cyclist_expenses (cyclist_name,expense_id,amount,description) values ('Alex FRAME',5,40,'lunch'); +insert into cycling.cyclist_expenses (cyclist_name,expense_id,amount,description) values ('Alex FRAME',6,40,'dinner'); +insert into cycling.cyclist_expenses (cyclist_name,expense_id,amount,description) values ('Steven KRUIKSWIJK',7,20,'lunch'); +insert into cycling.cyclist_expenses (cyclist_name,expense_id,amount,description) values ('Steven KRUIKSWIJK',8,39,'dinner'); +insert into cycling.cyclist_expenses (cyclist_name,expense_id,amount,description) values ('Marianne VOS',9,20,'lunch'); +insert into cycling.cyclist_expenses (cyclist_name,expense_id,amount,description) values ('Marianne VOS',10,20,'dinner'); +insert into cycling.cyclist_expenses (cyclist_name,expense_id,amount,description) values ('Paolo TIRALONGO',11,10,'dinner'); +insert into cycling.cyclist_expenses (cyclist_name,expense_id,amount,description) values ('Paolo TIRALONGO',12,10,'dinner'); +insert into cycling.cyclist_expenses (cyclist_name,expense_id,amount,description) values ('Anna VAN DER BREGGEN',13,50,'dinner'); +insert into cycling.cyclist_expenses (cyclist_name,expense_id,amount,description) values ('Anna VAN DER BREGGEN',14,25,'lunch'); +insert into cycling.cyclist_expenses (cyclist_name,expense_id,amount,description) values ('Anna VAN DER BREGGEN',15,35,'dinner'); +insert into cycling.cyclist_expenses (cyclist_name,expense_id,amount,description) values ('Anna VAN DER BREGGEN',16,20,'lunch'); +insert into cycling.cyclist_expenses (cyclist_name,expense_id,amount,description) values ('Anna VAN DER BREGGEN',17,70,'dinner'); +insert into cycling.cyclist_expenses (cyclist_name,expense_id,amount,description) values ('Anna VAN DER BREGGEN',18,10,'lunch'); +insert into cycling.cyclist_expenses (cyclist_name,expense_id,amount,description) values ('Anna VAN DER BREGGEN',19,50,'dinner'); +insert into cycling.cyclist_expenses (cyclist_name,expense_id,amount,description) values ('Anna VAN DER BREGGEN',20,25,'lunch'); +insert into cycling.cyclist_expenses (cyclist_name,expense_id,amount,description) values ('Anna VAN DER BREGGEN',21,35,'dinner'); +insert into cycling.cyclist_expenses (cyclist_name,expense_id,amount,description) values ('Anna VAN DER BREGGEN',22,20,'lunch'); +insert into cycling.cyclist_expenses (cyclist_name,expense_id,amount,description) values ('Anna VAN DER BREGGEN',23,70,'dinner'); +insert into cycling.cyclist_expenses (cyclist_name,expense_id,amount,description) values ('Paolo TIRALONGO',24,10,'lunch'); +insert into cycling.cyclist_expenses (cyclist_name,expense_id,amount,description) values ('Paolo TIRALONGO',25,11,'dinner'); +insert into cycling.cyclist_expenses (cyclist_name,expense_id,amount,description) values ('Paolo TIRALONGO',26,12,'lunch'); +insert into cycling.cyclist_expenses (cyclist_name,expense_id,amount,description) values ('Paolo TIRALONGO',27,13,'lunch'); +insert into cycling.cyclist_expenses (cyclist_name,expense_id,amount,description) values ('Paolo TIRALONGO',28,14,'lunch'); +insert into cycling.cyclist_expenses (cyclist_name,expense_id,amount,description) values ('Paolo TIRALONGO',29,15,'dinner'); +insert into cycling.cyclist_expenses (cyclist_name,expense_id,amount,description) values ('Paolo TIRALONGO',30,16,'lunch'); +insert into cycling.cyclist_expenses (cyclist_name,expense_id,amount,description) values ('Paolo TIRALONGO',31,17,'dinner'); +insert into cycling.cyclist_expenses (cyclist_name,expense_id,amount,description) values ('Paolo TIRALONGO',32,18,'breakfast'); +insert into cycling.cyclist_expenses (cyclist_name,expense_id,amount,description) values ('Steven KRUIKSWIJK',33,3,'coffee'); +insert into cycling.cyclist_expenses (cyclist_name,expense_id,amount,description) values ('Steven KRUIKSWIJK',34,3,'coffee'); +insert into cycling.cyclist_expenses (cyclist_name,expense_id,amount,description) values ('Steven KRUIKSWIJK',35,3,'coffee'); +insert into cycling.cyclist_expenses (cyclist_name,expense_id,amount,description) values ('Steven KRUIKSWIJK',36,3,'coffee'); +insert into cycling.cyclist_expenses (cyclist_name,expense_id,amount,description) values ('Steven KRUIKSWIJK',37,3,'coffee'); +insert into cycling.cyclist_expenses (cyclist_name,expense_id,amount,description) values ('Steven KRUIKSWIJK',38,3,'coffee'); +insert into cycling.cyclist_expenses (cyclist_name,expense_id,amount,description) values ('Steven KRUIKSWIJK',39,3,'coffee'); +insert into cycling.cyclist_expenses (cyclist_name,expense_id,amount,description) values ('Michael MATTHEWS',40,25,'lunch'); +insert into cycling.cyclist_expenses (cyclist_name,expense_id,amount,description) values ('Michael MATTHEWS',41,25,'lunch'); +insert into cycling.cyclist_expenses (cyclist_name,expense_id,amount,description) values ('Michael MATTHEWS',42,25,'lunch'); +insert into cycling.cyclist_expenses (cyclist_name,expense_id,amount,description) values ('Michael MATTHEWS',43,25,'lunch'); +insert into cycling.cyclist_expenses (cyclist_name,expense_id,amount,description) values ('Michael MATTHEWS',44,25,'lunch'); +insert into cycling.cyclist_expenses (cyclist_name,expense_id,amount,description) values ('Michael MATTHEWS',45,25,'lunch'); +insert into cycling.cyclist_expenses (cyclist_name,expense_id,amount,description) values ('Michael MATTHEWS',46,25,'lunch'); +insert into cycling.cyclist_expenses (cyclist_name,expense_id,amount,description) values ('Michael MATTHEWS',47,25,'lunch'); diff --git a/doc/modules/cassandra/examples/CQL/cyclist_id-table.cql b/doc/modules/cassandra/examples/CQL/cyclist_id-table.cql new file mode 100644 index 0000000000..ca1b17745c --- /dev/null +++ b/doc/modules/cassandra/examples/CQL/cyclist_id-table.cql @@ -0,0 +1,77 @@ +SOURCE 'keyspace-create-simple.cql'; +SOURCE 'keyspace-use.cql'; + +DROP TABLE IF EXISTS cycling.cyclist_id; + +// Find a cyclist's id given lastname and firstname +// Another CREATE TABLE using COMPOSITE PARTITION KEY +// INDEX ALSO GOOD FOR THIS TABLE + +// tag::comp_pk[] +CREATE TABLE IF NOT EXISTS cycling.cyclist_id ( + lastname text, + firstname text, + age int, + id UUID, + PRIMARY KEY ((lastname, firstname), age) +); +// end::comp_pk[] + +// tag::altercdc[] +ALTER TABLE cycling.cyclist_id +WITH CDC = false; +// end::altercdc[] + +INSERT INTO cycling.cyclist_id ( + lastname, firstname, age, id +) VALUES ( + 'EENKHOORN', 'Pascal', 18, ffdfa2a7-5fc6-49a7-bfdc-3fcdcfdd7156 +); + +INSERT INTO cycling.cyclist_id ( + lastname, firstname, age, id +) VALUES ( + 'WELTEN', 'Bram', 18, 18f471bf-f631-4bc4-a9a2-d6f6cf5ea503 +); + +INSERT INTO cycling.cyclist_id ( + lastname, firstname, age, id +) VALUES ( + 'COSTA', 'Adrien', 17, 15a116fc-b833-4da6-ab9a-4a7775752836 +); + +// tag::resetid[] +UPDATE cycling.cyclist_id +SET id = UUID() +WHERE lastname = 'WELTEN' + AND firstname = 'Bram' + AND age = 18 +IF EXISTS; +// end::resetid[] + +// tag::ifid[] +UPDATE cycling.cyclist_id +SET id = UUID() +WHERE lastname = 'WELTEN' + AND firstname = 'Bram' + AND age = 18 +IF id = 18f471bf-f631-4bc4-a9a2-d6f6cf5ea503; +// end::ifid[] + +// tag::ifnull[] +UPDATE cycling.cyclist_id +SET id = UUID() +WHERE lastname = 'Smith' + AND firstname = 'Joe' + AND age = 22 +IF id = NULL; +// end::ifnull[] + +// tag::select_with_in_and_equals[] +SELECT * +FROM cycling.cyclist_id +WHERE lastname = 'EENKHOORN' + AND firstname = 'Pascal' + AND age IN (17, 18); +// end::select_with_in_and_equals[] + diff --git a/doc/modules/cassandra/examples/CQL/cyclist_name-table.cql b/doc/modules/cassandra/examples/CQL/cyclist_name-table.cql new file mode 100644 index 0000000000..30b7b65f73 --- /dev/null +++ b/doc/modules/cassandra/examples/CQL/cyclist_name-table.cql @@ -0,0 +1,486 @@ +SOURCE 'keyspace-create-simple.cql'; +SOURCE 'keyspace-use.cql'; + +// tag::droptble[] +DROP TABLE IF EXISTS cycling.cyclist_name; +// end::droptble[] + +// tag::pk_at_start[] +USE cycling; +CREATE TABLE cyclist_name ( + id UUID PRIMARY KEY, + lastname text, + firstname text +); +// end::pk_at_start[] + +DROP TABLE IF EXISTS cycling.cyclist_name; + +// tag::pk_at_end[] +USE cycling; +CREATE TABLE cycling.cyclist_name ( + id UUID, + lastname text, + firstname text, + PRIMARY KEY (id) +); +// end::pk_at_end[] + +DROP TABLE IF EXISTS cycling.cyclist_name; + +// tag::keyspace_included[] +CREATE TABLE cycling.cyclist_name ( + id UUID PRIMARY KEY, + lastname text, + firstname text +); +// end::keyspace_included[] + +DROP TABLE IF EXISTS cycling.cyclist_name; + +// Create a table with a simple partition key +// tag::simple[] +CREATE TABLE IF NOT EXISTS cycling.cyclist_name ( + id UUID PRIMARY KEY, + lastname text, + firstname text +); +// end::simple[] + +// tag::uuid[] +INSERT INTO cycling.cyclist_name ( + id +) VALUES ( + uuid() +); +// end::uuid[] + +// tag::batch[] +BEGIN BATCH + + INSERT INTO cycling.cyclist_name ( + id, lastname, firstname + ) VALUES ( + 6d5f1663-89c0-45fc-8cfd-60a373b01622,'HOSKINS', 'Melissa' + ); + + INSERT INTO cycling.cyclist_name ( + id, lastname, firstname + ) VALUES ( + 38ab64b6-26cc-4de9-ab28-c257cf011659,'FERNANDES', 'Marcia' + ); + + INSERT INTO cycling.cyclist_name ( + id, lastname, firstname + ) VALUES ( + 9011d3be-d35c-4a8d-83f7-a3c543789ee7,'NIEWIADOMA', 'Katarzyna' + ); + + INSERT INTO cycling.cyclist_name ( + id, lastname, firstname + ) VALUES ( + 95addc4c-459e-4ed7-b4b5-472f19a67995,'ADRIAN', 'Vera' + ); + +APPLY BATCH; +// end::batch[] + +TRUNCATE cycling.cyclist_name; + +// Insert data with TTL and timestamp +// tag::insertstampttl[] +INSERT INTO cycling.cyclist_name ( + id, lastname, firstname +) VALUES ( + 6ab09bec-e68e-48d9-a5f8-97e6fb4c9b47, 'KRUIKSWIJK', 'Steven' +) +USING TTL 86400 +AND TIMESTAMP 123456789; +// end::insertstampttl[] + +// tag::insertifnotexists[] +INSERT INTO cycling.cyclist_name ( + id, lastname, firstname +) VALUES ( + c4b65263-fe58-4846-83e8-f0e1c13d518f, 'RATTO', 'Rissella' +) +IF NOT EXISTS; +// end::insertifnotexists[] + + +DROP INDEX IF EXISTS fn_prefix; + +// tag::fn_prefix[] +CREATE CUSTOM INDEX IF NOT EXISTS fn_prefix +ON cycling.cyclist_name (firstname) +USING 'org.apache.cassandra.index.sasi.SASIIndex'; +// end::fn_prefix[] + +TRUNCATE cycling.cyclist_name; + +// Insert 6 rows of cyclists +INSERT INTO cycling.cyclist_name (id, lastname, firstname) VALUES (5b6962dd-3f90-4c93-8f61-eabfa4a803e2, 'VOS','Marianne'); +INSERT INTO cycling.cyclist_name (id, lastname, firstname) VALUES (e7cd5752-bc0d-4157-a80f-7523add8dbcd, 'VAN DER BREGGEN','Anna'); +INSERT INTO cycling.cyclist_name (id, lastname, firstname) VALUES (e7ae5cf3-d358-4d99-b900-85902fda9bb0, 'FRAME','Alex'); +INSERT INTO cycling.cyclist_name (id, lastname, firstname) VALUES (220844bf-4860-49d6-9a4b-6b5d3a79cbfb, 'TIRALONGO','Paolo'); +INSERT INTO cycling.cyclist_name (id, lastname, firstname) VALUES (6ab09bec-e68e-48d9-a5f8-97e6fb4c9b47, 'KRUIKSWIJK','Steven'); +INSERT INTO cycling.cyclist_name (id, lastname, firstname) VALUES (fb372533-eb95-4bb4-8685-6ef61e994caa, 'MATTHEWS', 'Michael'); + +// View output +CAPTURE 'select_all_from_cycling_initial.results'; +// tag::select_initial[] +SELECT * +FROM cycling.cyclist_name; +// end::select_initial[] +CAPTURE OFF; + +CAPTURE 'select_marianne_from_cyclist_name.results'; +// tag::select_Marianne[] +SELECT * +FROM cycling.cyclist_name +WHERE firstname = 'Marianne'; +// end::select_Marianne[] +CAPTURE OFF; + +CAPTURE 'select_like_M_from_cyclist_name.results'; +// tag::select_like_M_start[] +SELECT * +FROM cycling.cyclist_name +WHERE firstname LIKE 'M%'; +// end::select_like_M_start[] +CAPTURE OFF; + +// tag::no_match_upper[] +SELECT * FROM cycling.cyclist_name WHERE firstname = 'MARIANNE'; +// end::no_match_upper[] + +// tag::no_match_lower[] +SELECT * FROM cycling.cyclist_name WHERE firstname LIKE 'm%'; +// end::no_match_lower[] + +// tag::no_match_equality[] +SELECT * FROM cycling.cyclist_name WHERE firstname = 'M%'; +SELECT * FROM cycling.cyclist_name WHERE firstname = '%M'; +SELECT * FROM cycling.cyclist_name WHERE firstname = '%M%'; +SELECT * FROM cycling.cyclist_name WHERE firstname = 'm%'; +// end::no_match_equality[] + +DROP INDEX IF EXISTS fn_contains; + +// tag::fn_contains[] +CREATE CUSTOM INDEX IF NOT EXISTS fn_contains +ON cycling.cyclist_name (firstname) +USING 'org.apache.cassandra.index.sasi.SASIIndex' +WITH OPTIONS = { 'mode': 'CONTAINS' }; +// end::fn_contains[] + +// These examples generate an error if they are run before the fn_contains index +// is created +// tag::like[] +SELECT * FROM cycling.cyclist_name WHERE firstname LIKE '%m%'; +SELECT * FROM cycling.cyclist_name WHERE firstname LIKE '%m%' ALLOW FILTERING; +SELECT * FROM cycling.cyclist_name WHERE firstname LIKE '%M%'; +// end::like[] + +CAPTURE 'select_marianne_allow_filtering_from_cyclist_name.results'; +// tag::select_marianne_allow_filtering[] +SELECT * +FROM cycling.cyclist_name +WHERE firstname = 'Marianne' +ALLOW FILTERING; +// end::select_marianne_allow_filtering[] +CAPTURE OFF; + +CAPTURE 'select_like_M_partial_from_cyclist_name.results'; +// tag::select_like_M_partial[] +SELECT * +FROM cycling.cyclist_name +WHERE firstname LIKE '%M%'; +// end::select_like_M_partial[] +CAPTURE OFF; + +CAPTURE 'select_arianne_from_cyclist_name.results'; +// tag::select_arianne[] +SELECT * +FROM cycling.cyclist_name +WHERE firstname LIKE '%arianne'; +// end::select_arianne[] +CAPTURE OFF; + +CAPTURE 'select_arian_from_cyclist_name.results'; +// tag::select_arian_name[] +SELECT * +FROM cycling.cyclist_name +WHERE firstname LIKE '%arian%'; +// end::select_arian_name[] +CAPTURE OFF; + +CAPTURE 'select_mar_from_cyclist_name.results'; +// tag::select_greater_Mar[] +SELECT * +FROM cycling.cyclist_name +WHERE firstname > 'Mar' +ALLOW FILTERING; +// end::select_greater_Mar[] +CAPTURE OFF; + +// These examples do not return a match when they are run before the +// fn_suffix_allcase index is created +// tag::no_match_partial[] +SELECT * FROM cycling.cyclist_name WHERE firstname = 'MariAnne' ALLOW FILTERING; +SELECT * FROM cycling.cyclist_name WHERE firstname LIKE '%m%'; +SELECT * FROM cycling.cyclist_name WHERE firstname LIKE '%M'; +SELECT * FROM cycling.cyclist_name WHERE firstname LIKE 'm%'; +// end::no_match_partial[] + +DROP INDEX IF EXISTS fn_suffix_allcase; + +// tag::fn_suffix_allcase[] +CREATE CUSTOM INDEX IF NOT EXISTS fn_suffix_allcase +ON cycling.cyclist_name (firstname) +USING 'org.apache.cassandra.index.sasi.SASIIndex' +WITH OPTIONS = { + 'mode': 'CONTAINS', + 'analyzer_class': 'org.apache.cassandra.index.sasi.analyzer.NonTokenizingAnalyzer', + 'case_sensitive': 'false' +}; +// end::fn_suffix_allcase[] + +CAPTURE 'select_like_m_lower_from_cyclist_name.results'; +// tag::select_like_m_lower[] +SELECT * +FROM cycling.cyclist_name +WHERE firstname LIKE '%m%'; +// end::select_like_m_lower[] +CAPTURE OFF; + +// tag::alter[] +ALTER TABLE cycling.cyclist_name +ADD age int; + +UPDATE cycling.cyclist_name +SET age = 23 +WHERE id = 5b6962dd-3f90-4c93-8f61-eabfa4a803e2; + +INSERT INTO cycling.cyclist_name ( + id, age, firstname, lastname +) VALUES ( + 8566eb59-07df-43b1-a21b-666a3c08c08a, 18, 'Marianne', 'DAAE' +); +// end::alter[] + +CAPTURE 'select_name_and_age_filter_from_cyclist_name.results'; +// tag::select_name_and_age_filter[] +SELECT * +FROM cycling.cyclist_name +WHERE firstname = 'Marianne' + AND age > 20 +ALLOW FILTERING; +// end::select_name_and_age_filter[] +CAPTURE OFF; + +// Undo the changes in the alter section +DELETE FROM cycling.cyclist_name +WHERE id = 8566eb59-07df-43b1-a21b-666a3c08c08a; +ALTER TABLE cycling.cyclist_name +DROP age; + +// Delete data in specified columns from a row, changes cyclist Alex Frame to null in name columns +// tag::deletecolumndata[] +DELETE firstname, lastname +FROM cycling.cyclist_name +WHERE id = e7ae5cf3-d358-4d99-b900-85902fda9bb0; +// end::deletecolumndata[] + +// View output +CAPTURE 'cyclist_name_delete_firstname_and_lastname.results'; +SELECT * +FROM cycling.cyclist_name; +CAPTURE OFF; + +// Delete an entire row, deletes cyclist Alex Frame altogether +CAPTURE 'cyclist_name_delete_applied_true.results'; +// tag::deleteentirerow[] +DELETE FROM cycling.cyclist_name +WHERE id = e7ae5cf3-d358-4d99-b900-85902fda9bb0 +IF EXISTS; +// end::deleteentirerow[] +CAPTURE OFF; + +// View output +CAPTURE 'cyclist_name_delete_entire_row.results'; +SELECT * +FROM cycling.cyclist_name; +CAPTURE OFF; + +// Delete a row based on a static column condition, attempts to delete cyclist Michael Matthews but lastname does not match +CAPTURE 'cyclist_name_delete_condition.results'; +// tag::deletecondition[] +DELETE FROM cycling.cyclist_name +WHERE id = fb372533-eb95-4bb4-8685-6ef61e994caa +IF firstname = 'Michael' + AND lastname = 'Smith'; +// end::deletecondition[] +CAPTURE OFF; + +// View output +SELECT * +FROM cycling.cyclist_name; + +// Delete a row with a WHERE clause, deletes cyclist Steven Kruikswijk +// tag::deleterowhere[] +DELETE FROM cycling.cyclist_name +WHERE id = 6ab09bec-e68e-48d9-a5f8-97e6fb4c9b47; +// end::deleterowhere[] + +// View output +CAPTURE 'cyclist_name_delete_row_where.results'; +SELECT * +FROM cycling.cyclist_name; +CAPTURE OFF; + +// Delete rows using an IN clause on a primary key, deletes cyclists Marianne and Paolo +// tag::deletein[] +DELETE FROM cycling.cyclist_name +WHERE id IN ( + 5b6962dd-3f90-4c93-8f61-eabfa4a803e2, 220844bf-4860-49d6-9a4b-6b5d3a79cbfb +); +// end::deletein[] + +// View output +CAPTURE 'cyclist_name_delete_in.results'; +SELECT * +FROM cycling.cyclist_name; +CAPTURE OFF; + +// tag::delete_lastname[] +DELETE lastname +FROM cycling.cyclist_name +WHERE id = c7fceba0-c141-4207-9494-a29f9809de6f; +// end::delete_lastname[] + +// Reinsert data +INSERT INTO cycling.cyclist_name (id, lastname, firstname) VALUES (5b6962dd-3f90-4c93-8f61-eabfa4a803e2, 'VOS','Marianne'); +INSERT INTO cycling.cyclist_name (id, lastname, firstname) VALUES (e7cd5752-bc0d-4157-a80f-7523add8dbcd, 'VAN DER BREGGEN','Anna'); +INSERT INTO cycling.cyclist_name (id, lastname, firstname) VALUES (e7ae5cf3-d358-4d99-b900-85902fda9bb0, 'FRAME','Alex'); +INSERT INTO cycling.cyclist_name (id, lastname, firstname) VALUES (220844bf-4860-49d6-9a4b-6b5d3a79cbfb, 'TIRALONGO','Paolo'); +INSERT INTO cycling.cyclist_name (id, lastname, firstname) VALUES (6ab09bec-e68e-48d9-a5f8-97e6fb4c9b47, 'KRUIKSWIJK','Steven'); +INSERT INTO cycling.cyclist_name (id, lastname, firstname) VALUES (fb372533-eb95-4bb4-8685-6ef61e994caa, 'MATTHEWS', 'Michael'); + +// tag::comment[] +ALTER TABLE cycling.cyclist_name +ADD comment text; +// end::comment[] + +// tag::update_set_comment[] +UPDATE cycling.cyclist_name +SET comment = 'Rides hard, gets along with others, a real winner' +WHERE id = fb372533-eb95-4bb4-8685-6ef61e994caa; + +UPDATE cycling.cyclist_name +SET comment = 'Rides fast, does not get along with others, a real dude' +WHERE id = 5b6962dd-3f90-4c93-8f61-eabfa4a803e2; +// end::update_set_comment[] + +DROP INDEX IF EXISTS cycling.stdanalyzer_idx; + +// tag::stdanalyzer_idx[] +CREATE CUSTOM INDEX IF NOT EXISTS stdanalyzer_idx +ON cycling.cyclist_name (comment) USING 'org.apache.cassandra.index.sasi.SASIIndex' +WITH OPTIONS = { + 'mode': 'CONTAINS', + 'analyzer_class': 'org.apache.cassandra.index.sasi.analyzer.StandardAnalyzer', + 'analyzed': 'true', + 'tokenization_skip_stop_words': 'and, the, or', + 'tokenization_enable_stemming': 'true', + 'tokenization_normalize_lowercase': 'true', + 'tokenization_locale': 'en' +}; +// end::stdanalyzer_idx[] + +SOURCE 'cyclist_name-queries.cql'; + +// Undo UPDATE statements +UPDATE cycling.cyclist_name +SET comment = NULL +WHERE id = fb372533-eb95-4bb4-8685-6ef61e994caa; + +UPDATE cycling.cyclist_name +SET comment = NULL +WHERE id = 5b6962dd-3f90-4c93-8f61-eabfa4a803e2; + +// tag::update[] +UPDATE cycling.cyclist_name +SET comment = 'Rides hard, gets along with others, a real winner' +WHERE id = fb372533-eb95-4bb4-8685-6ef61e994caa +IF EXISTS; +// end::update[] + +// tag::multcolumns[] +UPDATE cycling.cyclist_name +SET + firstname = 'Marianne', + lastname = 'VOS' +WHERE id = 88b8fd18-b1ed-4e96-bf79-4280797cba80; +// end::multcolumns[] + +// tag::records[] +UPDATE cycling.cyclist_name +SET firstname = NULL +WHERE id IN ( + 5b6962dd-3f90-4c93-8f61-eabfa4a803e2, + fb372533-eb95-4bb4-8685-6ef61e994caa +); +// end::records[] + +// tag::upsert[] +UPDATE cycling.cyclist_name +SET + firstname = 'Anna', + lastname = 'VAN DER BREGGEN' +WHERE id = e7cd5752-bc0d-4157-a80f-7523add8dbcd; +// end::upsert[] + +// tag::if[] +UPDATE cycling.cyclist_name +SET comment = 'Rides hard, gets along with others, a real winner' +WHERE id = fb372533-eb95-4bb4-8685-6ef61e994caa +IF comment = NULL; +// end::if[] + +// tag::fail[] +UPDATE cycling.cyclist_name +SET comment = 'Rides hard, gets along with others, a real winner' +WHERE id = fb372533-eb95-4bb4-8685-6ef61e994cac +IF comment = 'Rides hard, gets along with others, a real winner'; +// end::fail[] + +// tag::count_lastname[] +SELECT COUNT(lastname) +FROM cycling.cyclist_name; +// end::count_lastname[] + +// tag::count_rows[] +SELECT COUNT(*) +FROM cycling.cyclist_name; +// end::count_rows[] + +// tag::insert_Roxxane[] +INSERT INTO cycling.cyclist_name ( + id, lastname, firstname +) VALUES ( + 4647f6d3-7bd2-4085-8d6c-1229351b5498, 'KNETEMANN', 'Roxxane' +) +IF NOT EXISTS; +// end::insert_Roxxane[] + +// tag::update_Roxxane[] +UPDATE cycling.cyclist_name +SET firstname = 'Roxane' +WHERE id = 4647f6d3-7bd2-4085-8d6c-1229351b5498 +IF firstname = 'Roxxane'; +// end::update_Roxxane[] + +DELETE FROM cycling.cyclist_name +WHERE id = 4647f6d3-7bd2-4085-8d6c-1229351b5498; + diff --git a/doc/modules/cassandra/examples/CQL/cyclist_races-table.cql b/doc/modules/cassandra/examples/CQL/cyclist_races-table.cql new file mode 100644 index 0000000000..3e503a3ed8 --- /dev/null +++ b/doc/modules/cassandra/examples/CQL/cyclist_races-table.cql @@ -0,0 +1,62 @@ +SOURCE 'keyspace-create-simple.cql'; +SOURCE 'keyspace-use.cql'; + +DROP TABLE IF EXISTS cycling.cyclist_races; + +// Find all races for a particular cyclist +// CREATE TYPE - User-Defined Type, race +// CREATE TABLE WITH LIST, SIMPLE PRIMARY KEY +SOURCE 'user-defined-type-create-race.cql'; + +// tag::frozenlist[] +CREATE TABLE IF NOT EXISTS cycling.cyclist_races ( + id UUID PRIMARY KEY, + lastname text, + firstname text, + races list> +); +// end::frozenlist[] + +// tag::insertFL[] +INSERT INTO cycling.cyclist_races ( + id, + lastname, + firstname, + races +) VALUES ( + 5b6962dd-3f90-4c93-8f61-eabfa4a803e2, + 'VOS', + 'Marianne', + [ { + race_title:'Rabobank 7-Dorpenomloop Aalburg', + race_date:'2015-05-09', + race_time:'02:58:33'}, + { + race_title:'Ronde van Gelderland', + race_date:'2015-04-19', + race_time:'03:22:23' + } + ] +); +// end::insertFL[] + +INSERT INTO cycling.cyclist_races ( + id, lastname, firstname, races +) VALUES ( + e7cd5752-bc0d-4157-a80f-7523add8dbcd, 'VAN DER BREGGEN', 'Anna', [ {race_title:'Festival Luxembourgeois du cyclisme feminin Elsy Jacobs - Prologue - Garnich > Garnich',race_date:'2015-05-01',race_time:'08:13:00'},{race_title:'Festival Luxembourgeois du cyclisme feminin Elsy Jacobs - Stage 2 - Garnich > Garnich',race_date:'2015-05-02',race_time:'02:41:52'},{race_title:'Festival Luxembourgeois du cyclisme feminin Elsy Jacobs - Stage 3 - Mamer > Mamer',race_date:'2015-05-03',race_time:'02:31:24'} ] +); + +// tag::add[] +ALTER TABLE cycling.cyclist_races +ADD manager UUID; +// end::add[] + +// tag::list[] +ALTER TABLE cycling.cyclist_races +ADD completed list; +// end::list[] + +// tag::drop[] +ALTER TABLE cycling.cyclist_races +DROP manager; +// end::drop[] \ No newline at end of file diff --git a/doc/modules/cassandra/examples/CQL/popular_count-table.cql b/doc/modules/cassandra/examples/CQL/popular_count-table.cql new file mode 100644 index 0000000000..6aad6b237a --- /dev/null +++ b/doc/modules/cassandra/examples/CQL/popular_count-table.cql @@ -0,0 +1,42 @@ +SOURCE 'keyspace-create-simple.cql'; +SOURCE 'keyspace-use.cql'; + +DROP TABLE IF EXISTS cycling.popular_count; + +// tag::create[] +CREATE TABLE IF NOT EXISTS cycling.popular_count ( + id UUID PRIMARY KEY, + popularity counter +); +// end::create[] + +// tag::batch[] +BEGIN COUNTER BATCH + + UPDATE cycling.popular_count + SET popularity = popularity + 1 + WHERE id = 6ab09bec-e68e-48d9-a5f8-97e6fb4c9b47; + + UPDATE cycling.popular_count + SET popularity = popularity + 125 + WHERE id = 6ab09bec-e68e-48d9-a5f8-97e6fb4c9b47; + + UPDATE cycling.popular_count + SET popularity = popularity - 64 + WHERE id = 6ab09bec-e68e-48d9-a5f8-97e6fb4c9b47; + +APPLY BATCH; +// end::batch[] + +// tag::count[] +UPDATE cycling.popular_count +SET popularity = popularity + 2 +WHERE id = 6ab09bec-e68e-48d9-a5f8-97e6fb4c9b47; +// end::count[] + +CAPTURE 'select_all_from_popular_count.results'; +// tag::select[] +SELECT * +FROM cycling.popular_count; +// end::select[] +CAPTURE OFF; \ No newline at end of file diff --git a/doc/modules/cassandra/examples/CQL/race_times-table.cql b/doc/modules/cassandra/examples/CQL/race_times-table.cql new file mode 100644 index 0000000000..1b4a0a06da --- /dev/null +++ b/doc/modules/cassandra/examples/CQL/race_times-table.cql @@ -0,0 +1,43 @@ +SOURCE 'race_times-table.cql'; + +// tag::duration[] +INSERT INTO cycling.race_times ( + finish_time, + race_name, cyclist_name, race_date +) VALUES ( + 1h4m48s20ms, + '17th Santos Tour Down Under', 'Rohan DENNIS', '2017-04-14' +); +// end::duration[] + +// tag::update_duration[] +UPDATE cycling.race_times +SET finish_time = 2h5m22s14ms +WHERE race_name = '17th Santos Tour Down Under' + AND cyclist_name = 'Rohan DENNIS' + AND race_date = '2017-04-14'; +// end::update_duration[] + +CAPTURE 'select_all_from_race_times.results'; +// tag::select_duration[] +SELECT * +FROM cycling.race_times +WHERE race_name = '17th Santos Tour Down Under' + AND cyclist_name = 'Rohan DENNIS' + AND race_date = '2017-04-14'; +// end::select_duration[] +CAPTURE OFF; + +// tag::select_race_times_where_race_date_is_calculation[] +SELECT * +FROM cycling.race_times +WHERE race_date = '2017-04-15' - 1d; +// end::select_race_times_where_race_date_is_calculation[] + +// tag::rename[] +ALTER TABLE cycling.race_times +RENAME race_date TO date; +// end::rename[] + +ALTER TABLE cycling.race_times +RENAME date TO race_date; \ No newline at end of file diff --git a/doc/modules/cassandra/examples/CQL/race_winners-table.cql b/doc/modules/cassandra/examples/CQL/race_winners-table.cql new file mode 100644 index 0000000000..de3a1c4072 --- /dev/null +++ b/doc/modules/cassandra/examples/CQL/race_winners-table.cql @@ -0,0 +1,73 @@ +SOURCE 'keyspace-create-simple.cql'; +SOURCE 'keyspace-use.cql'; + +DROP TABLE IF EXISTS cycling.race_winners; + +SOURCE 'user-defined-type-create-fullname.cql'; + +// tag::usetype[] +CREATE TABLE IF NOT EXISTS cycling.race_winners ( + cyclist_name FROZEN, + race_name text, + race_position int, + PRIMARY KEY (race_name, race_position) +); +// end::usetype[] + +// tag::insert[] +INSERT INTO cycling.race_winners ( + race_name, race_position, + cyclist_name +) VALUES ( + 'National Championships South Africa WJ-ITT (CN)', 1, + { firstname:'Frances', lastname:'DU TOUT' } +); +// end::insert[] + +INSERT INTO cycling.race_winners ( + race_name, race_position, + cyclist_name +) VALUES ( + 'National Championships South Africa WJ-ITT (CN)', 2, + { firstname:'Lynette', lastname:'BENSON' } +); + +INSERT INTO cycling.race_winners ( + race_name, race_position, + cyclist_name +) VALUES ( + 'National Championships South Africa WJ-ITT (CN)', 3, + { firstname:'Anja', lastname:'GERBER' } +); + +INSERT INTO cycling.race_winners ( + race_name, race_position, + cyclist_name +) VALUES ( + 'National Championships South Africa WJ-ITT (CN)', 4, + { firstname:'Ame', lastname:'VENTER' } +); + +INSERT INTO cycling.race_winners ( + race_name, race_position, + cyclist_name +) VALUES ( + 'National Championships South Africa WJ-ITT (CN)', 5, + { firstname:'Danielle', lastname:'VAN NIEKERK' } +); + +// tag::comment_hyphens[] +SELECT * FROM cycling.race_winners; -- End of line comment +// end::comment_hyphens[] + +// tag::comment_slashes[] +SELECT * FROM cycling.race_winners; // End of line comment +// end::comment_slashes[] + +// tag::comment_span[] +/* This is a + comment that spans multiple + lines */ +SELECT * FROM cycling.race_winners; +// end::comment_span[] + diff --git a/doc/modules/cassandra/examples/CQL/rank_by_year_and_name-table.cql b/doc/modules/cassandra/examples/CQL/rank_by_year_and_name-table.cql new file mode 100644 index 0000000000..399dcdbe39 --- /dev/null +++ b/doc/modules/cassandra/examples/CQL/rank_by_year_and_name-table.cql @@ -0,0 +1,136 @@ +SOURCE 'keyspace-create-simple.cql'; +SOURCE 'keyspace-use.cql'; + +DROP TABLE IF EXISTS cycling.rank_by_year_and_name; + +// Store race information by year and race name using a COMPOSITE PARTITION KEY + +// tag::use_and_compositepk[] +USE cycling; +CREATE TABLE rank_by_year_and_name ( + race_year int, + race_name text, + cyclist_name text, + rank int, + PRIMARY KEY ((race_year, race_name), rank) +); +// end::use_and_compositepk[] + +DROP TABLE IF EXISTS cycling.rank_by_year_and_name; + +// tag::compositepk[] +CREATE TABLE IF NOT EXISTS cycling.rank_by_year_and_name ( + race_year int, + race_name text, + cyclist_name text, + rank int, + PRIMARY KEY ((race_year, race_name), rank) +); +// end::compositepk[] + +// tag::dropindex[] +DROP INDEX IF EXISTS cycling.rank_idx; +// end::dropindex[] + +// tag::createindex[] +CREATE INDEX IF NOT EXISTS rank_idx +ON cycling.rank_by_year_and_name (rank); +// end::createindex[] + +// tag::drop_race_year_idx[] +DROP INDEX IF EXISTS cycling.race_year_idx; +// end::drop_race_year_idx[] + +// tag::create_race_year_idx[] +CREATE INDEX IF NOT EXISTS race_year_idx ON +cycling.rank_by_year_and_name (race_year); +// end::create_race_year_idx[] + +INSERT INTO cycling.rank_by_year_and_name (race_year, race_name, cyclist_name, rank) VALUES (2015, 'Tour of Japan - Stage 4 - Minami > Shinshu', 'Benjamin PRADES', 1); +INSERT INTO cycling.rank_by_year_and_name (race_year, race_name, cyclist_name, rank) VALUES (2015, 'Tour of Japan - Stage 4 - Minami > Shinshu', 'Adam PHELAN', 2); +INSERT INTO cycling.rank_by_year_and_name (race_year, race_name, cyclist_name, rank) VALUES (2015, 'Tour of Japan - Stage 4 - Minami > Shinshu', 'Thomas LEBAS', 3); +INSERT INTO cycling.rank_by_year_and_name (race_year, race_name, cyclist_name, rank) VALUES (2014, 'Tour of Japan - Stage 4 - Minami > Shinshu', 'Benjamin PRADES', 3); +INSERT INTO cycling.rank_by_year_and_name (race_year, race_name, cyclist_name, rank) VALUES (2014, 'Tour of Japan - Stage 4 - Minami > Shinshu', 'Daniel MARTIN', 1); +INSERT INTO cycling.rank_by_year_and_name (race_year, race_name, cyclist_name, rank) VALUES (2014, 'Tour of Japan - Stage 4 - Minami > Shinshu', 'Johan Esteban CHAVES', 2); +INSERT INTO cycling.rank_by_year_and_name (race_year, race_name, cyclist_name, rank) VALUES (2015, 'Giro d''Italia - Stage 11 - Forli > Imola', 'Ilnur ZAKARIN', 1); +INSERT INTO cycling.rank_by_year_and_name (race_year, race_name, cyclist_name, rank) VALUES (2015, 'Giro d''Italia - Stage 11 - Forli > Imola', 'Carlos BETANCUR', 2); +INSERT INTO cycling.rank_by_year_and_name (race_year, race_name, cyclist_name, rank) VALUES (2014, '4th Tour of Beijing', 'Phillippe GILBERT', 1); +INSERT INTO cycling.rank_by_year_and_name (race_year, race_name, cyclist_name, rank) VALUES (2014, '4th Tour of Beijing', 'Daniel MARTIN', 2); +INSERT INTO cycling.rank_by_year_and_name (race_year, race_name, cyclist_name, rank) VALUES (2014, '4th Tour of Beijing', 'Johan Esteban CHAVES', 3); +INSERT INTO cycling.rank_by_year_and_name (race_year, race_name, cyclist_name, rank) VALUES (2014, '4th Tour of Beijing', 'Phillippe GILBERT', 1); +INSERT INTO cycling.rank_by_year_and_name (race_year, race_name, cyclist_name, rank) VALUES (2014, '4th Tour of Beijing', 'Daniel MARTIN', 2); +INSERT INTO cycling.rank_by_year_and_name (race_year, race_name, cyclist_name, rank) VALUES (2014, '4th Tour of Beijing', 'Johan Esteban CHAVES', 3); + +// Show all inserted data +CAPTURE 'select_all_from_rank_by_year_and_name.results'; +SELECT * +FROM cycling.rank_by_year_and_name; +CAPTURE OFF; + +CAPTURE 'select_all_from_rank_by_year_and_name_Japan_2014.results'; +// tag::select_with_name_and_year[] +SELECT * +FROM cycling.rank_by_year_and_name +WHERE race_year = 2014 + AND race_name = 'Tour of Japan - Stage 4 - Minami > Shinshu'; +// end::select_with_name_and_year[] +CAPTURE OFF; + +// tag::sepstatementswithand[] +SELECT + rank, + cyclist_name AS name +FROM cycling.rank_by_year_and_name +WHERE "race_name" = 'Tour of Japan - Stage 4 - Minami > Shinshu' + AND race_year = 2014; +// end::sepstatementswithand[] + +// tag::columnalias[] +CAPTURE 'select_best_rank_from_rank_by_year_and_name.results'; +SELECT + MIN(rank) AS best_rank, + cyclist_name +FROM cycling.rank_by_year_and_name +WHERE "race_name" = 'Tour of Japan - Stage 4 - Minami > Shinshu' + AND race_year = 2014; +// end::columnalias[] +CAPTURE OFF; + +// The following query generates a warning, which is normal +// tag::countrows[] +SELECT COUNT(*) +FROM cycling.rank_by_year_and_name; +// end::countrows[] + +// tag::limitrows[] +SELECT cyclist_name +FROM cycling.rank_by_year_and_name +LIMIT 50000; +// end::limitrows[] + +// Query by partition +CAPTURE 'select_all_from_rank_by_year_and_name_partition_limit.results'; +// tag::partlimit[] +SELECT * +FROM cycling.rank_by_year_and_name +PER PARTITION LIMIT 2; +// end::partlimit[] +CAPTURE OFF; + +// Select rank - filter on a clustering column +CAPTURE 'select_all_from_rank_by_year_and_name_rank_1.results'; +// tag::selectrank[] +SELECT * +FROM cycling.rank_by_year_and_name +WHERE rank = 1; +// end::selectrank[] +CAPTURE OFF; + +CAPTURE 'select_all_from_rank_by_year_and_name_2014.results'; +// tag::select_with_year[] +SELECT * +FROM cycling.rank_by_year_and_name +WHERE race_year = 2014; +// end::select_with_year[] +CAPTURE OFF; + diff --git a/doc/modules/cassandra/examples/CQLSH/comments-desc_table.cqlsh b/doc/modules/cassandra/examples/CQLSH/comments-desc_table.cqlsh new file mode 100644 index 0000000000..d26f1f2bdc --- /dev/null +++ b/doc/modules/cassandra/examples/CQLSH/comments-desc_table.cqlsh @@ -0,0 +1 @@ +DESC cycling.comments; diff --git a/doc/modules/cassandra/examples/RESULTS/comments-desc_table.result b/doc/modules/cassandra/examples/RESULTS/comments-desc_table.result new file mode 100644 index 0000000000..676de59955 --- /dev/null +++ b/doc/modules/cassandra/examples/RESULTS/comments-desc_table.result @@ -0,0 +1,21 @@ +CREATE TABLE cycling.comments ( + id uuid, + created_at timestamp, + comment text, + commenter text, + record_id timeuuid, + PRIMARY KEY (id, created_at) +) WITH CLUSTERING ORDER BY (created_at DESC) + AND bloom_filter_fp_chance = 0.01 + AND caching = {'keys': 'NONE', 'rows_per_partition': '10'} + AND comment = '' + AND compaction = {'class': 'org.apache.cassandra.db.compaction.SizeTieredCompactionStrategy', 'enabled': 'true', 'max_threshold': '32', 'min_threshold': '4'} + AND compression = {'chunk_length_in_kb': '64', 'class': 'org.apache.cassandra.io.compress.DeflateCompressor'} + AND crc_check_chance = 1.0 + 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 speculative_retry = '99PERCENTILE'; + diff --git a/doc/modules/cassandra/examples/RESULTS/select_after_batch_food_from_cyclist_expenses.result b/doc/modules/cassandra/examples/RESULTS/select_after_batch_food_from_cyclist_expenses.result new file mode 100644 index 0000000000..cf94b2335b --- /dev/null +++ b/doc/modules/cassandra/examples/RESULTS/select_after_batch_food_from_cyclist_expenses.result @@ -0,0 +1,7 @@ + cyclist_name | expense_id | balance | amount | description | paid +--------------+------------+---------+--------+-------------+------- + Vera ADRIAN | 1 | -32.95 | 7.95 | Breakfast | False + Vera ADRIAN | 2 | -32.95 | 13.44 | Lunch | True + Vera ADRIAN | 3 | -32.95 | 25 | Dinner | False + +(3 rows) diff --git a/doc/modules/cassandra/examples/RESULTS/select_after_batch_paid_from_cyclist_expenses.result b/doc/modules/cassandra/examples/RESULTS/select_after_batch_paid_from_cyclist_expenses.result new file mode 100644 index 0000000000..3cf4f48b88 --- /dev/null +++ b/doc/modules/cassandra/examples/RESULTS/select_after_batch_paid_from_cyclist_expenses.result @@ -0,0 +1,7 @@ + cyclist_name | expense_id | balance | amount | description | paid +--------------+------------+---------+--------+-------------+------ + Vera ADRIAN | 1 | 0 | 7.95 | Breakfast | True + Vera ADRIAN | 2 | 0 | 13.44 | Lunch | True + Vera ADRIAN | 3 | 0 | 25 | Dinner | True + +(3 rows) diff --git a/doc/modules/cassandra/examples/RESULTS/select_after_update_from_cyclist_expenses.result b/doc/modules/cassandra/examples/RESULTS/select_after_update_from_cyclist_expenses.result new file mode 100644 index 0000000000..320241f170 --- /dev/null +++ b/doc/modules/cassandra/examples/RESULTS/select_after_update_from_cyclist_expenses.result @@ -0,0 +1,5 @@ + cyclist_name | expense_id | balance | amount | description | paid +--------------+------------+---------+--------+-------------+------- + Vera ADRIAN | 1 | -7.95 | 7.95 | Breakfast | False + +(1 rows) diff --git a/doc/modules/cassandra/examples/RESULTS/select_initial_from_country_flag.result b/doc/modules/cassandra/examples/RESULTS/select_initial_from_country_flag.result new file mode 100644 index 0000000000..f871c61ebb --- /dev/null +++ b/doc/modules/cassandra/examples/RESULTS/select_initial_from_country_flag.result @@ -0,0 +1,8 @@ + country | cyclist_name | flag +---------+--------------+------ + Belgium | Andre | 1 + Belgium | Jacques | 1 + France | Andre | 3 + France | George | 3 + +(4 rows) diff --git a/doc/modules/cassandra/examples/RESULTS/select_initial_from_cyclist_expenses.result b/doc/modules/cassandra/examples/RESULTS/select_initial_from_cyclist_expenses.result new file mode 100644 index 0000000000..1ab984128a --- /dev/null +++ b/doc/modules/cassandra/examples/RESULTS/select_initial_from_cyclist_expenses.result @@ -0,0 +1,5 @@ + cyclist_name | expense_id | balance | amount | description | paid +--------------+------------+---------+--------+-------------+------- + Vera ADRIAN | 1 | 0 | 7.95 | Breakfast | False + +(1 rows) diff --git a/doc/modules/cassandra/examples/RESULTS/true.result b/doc/modules/cassandra/examples/RESULTS/true.result new file mode 100644 index 0000000000..5ef1258ba0 --- /dev/null +++ b/doc/modules/cassandra/examples/RESULTS/true.result @@ -0,0 +1,3 @@ + [applied] +----------- + True diff --git a/doc/modules/cassandra/nav.adoc b/doc/modules/cassandra/nav.adoc index 53a1d83af6..1a2eed974e 100644 --- a/doc/modules/cassandra/nav.adoc +++ b/doc/modules/cassandra/nav.adoc @@ -2,9 +2,10 @@ ** xref:cassandra:overview/faq/index.adoc[] -** xref:cassandra:getting-started/index.adoc[] +** xref:cassandra:getting-started/index.adoc[] *** xref:cassandra:getting-started/cassandra-quickstart.adoc[] *** xref:cassandra:getting-started/sai-quickstart.adoc[] +*** xref:cassandra:getting-started/vector-search-quickstart.adoc[] *** xref:cassandra:installing/installing.adoc[] *** xref:cassandra:getting-started/configuring.adoc[] *** xref:cassandra:getting-started/querying.adoc[] @@ -17,7 +18,7 @@ ** xref:cassandra:architecture/index.adoc[] *** xref:cassandra:architecture/overview.adoc[] -*** xref:cassandra:architecture/dynamo.adoc[] +*** xref:cassandra:architecture/dynamo.adoc[] *** xref:cassandra:architecture/storage-engine.adoc[] *** xref:cassandra:architecture/guarantees.adoc[] *** xref:cassandra:architecture/messaging.adoc[] @@ -66,8 +67,9 @@ ** xref:cassandra:vector-search/overview.adoc[] *** xref:cassandra:vector-search/concepts.adoc[] **** xref:cassandra:vector-search/data-modeling.adoc[] -*** xref:cassandra:vector-search/quickstarts.adoc[] -**** xref:cassandra:getting-started/vector-search-quickstart.adoc[] +// *** xref:cassandra:vector-search/quickstarts.adoc[] +*** xref:cassandra:getting-started/vector-search-quickstart.adoc[] +*** xref:cassandra:vector-search/vector-search-working-with.adoc[] // **** xref:getting-started/sai-quickstart.adoc[] ** xref:cassandra:managing/index.adoc[] diff --git a/doc/modules/cassandra/pages/new/index.adoc b/doc/modules/cassandra/pages/new/index.adoc index 9a173e5078..7cf4c41837 100644 --- a/doc/modules/cassandra/pages/new/index.adoc +++ b/doc/modules/cassandra/pages/new/index.adoc @@ -5,13 +5,11 @@ This section covers the new features in Apache Cassandra 5.0. -* https://cwiki.apache.org/confluence/x/FQRACw[ACID Transactions (Accord)] * https://issues.apache.org/jira/browse/CASSANDRA-16052[Storage Attached Indexes] * https://issues.apache.org/jira/browse/CASSANDRA-17240[Trie Memtables] * https://issues.apache.org/jira/browse/CASSANDRA-18398[Trie SSTables] * https://github.com/apache/cassandra/blob/trunk/NEWS.txt[More Guardrails] * https://issues.apache.org/jira/browse/CASSANDRA-8877[TTL and writetime on collections and UDTs] -* https://cwiki.apache.org/confluence/x/YyD1D[Transactional Cluster Metadata] * https://issues.apache.org/jira/browse/CASSANDRA-16895[JDK 17] * https://issues.apache.org/jira/browse/CASSANDRA-17221[New Mathematical CQL functions: abs, exp, log, log10 and round] * https://issues.apache.org/jira/browse/CASSANDRA-18060[New CQL native scalar functions for collections] diff --git a/doc/modules/cassandra/pages/reference/cql-commands/create-index.adoc b/doc/modules/cassandra/pages/reference/cql-commands/create-index.adoc index d2d9771468..48bcd218ab 100644 --- a/doc/modules/cassandra/pages/reference/cql-commands/create-index.adoc +++ b/doc/modules/cassandra/pages/reference/cql-commands/create-index.adoc @@ -21,7 +21,12 @@ include::example$BNF/index_name.bnf[] CREATE INDEX [ IF NOT EXISTS ] ON [.] ([ ( KEYS | FULL ) ] ) - (ENTRIES ) ; + (ENTRIES ) + // | [ (KEYS()) ] + // | [ (VALUES()) ] + // | [ (ENTRIES()) ] + [USING 'sai' + [ WITH OPTIONS = { } ]]; ---- // end::syntax[] @@ -47,7 +52,7 @@ Enclose in quotes to use special characters or preserve capitalization. If no name is specified, {product} names the index: `__idx`. *keyspace_name*:: -Name of the keyspace that contains the table to index. +Name of the keyspace that contains the table to index. If no name is specified, the current keyspace is used. == Usage notes diff --git a/doc/modules/cassandra/pages/reference/cql-commands/create-table-examples.adoc b/doc/modules/cassandra/pages/reference/cql-commands/create-table-examples.adoc new file mode 100644 index 0000000000..47ab849734 --- /dev/null +++ b/doc/modules/cassandra/pages/reference/cql-commands/create-table-examples.adoc @@ -0,0 +1,98 @@ += Examples +:description: CREATE TABLE CQL examples. + +== Create a table with UUID as the primary key + +Create the `cyclist_name` table with UUID as the primary key: + +[source,language-cql] +---- +include::cassandra:example$CQL/cyclist_name-table.cql[tag=simple] +---- + +== Create a compound primary key + +Create the `cyclist_category` table and store the data in reverse order: + +[source,language-cql] +---- +include::cassandra:example$CQL/cyclist_category-table.cql[tag=cpartitionkey] +---- + +== Create a composite partition key + +Create a table that is optimized for query by cyclist rank by year: + +[source,language-cql] +---- +include::cassandra:example$CQL/rank_by_year_and_name-table.cql[tag=compositepk] +---- + +== Create a table with a vector column + +Create a table with a vector column + +[source,language-cql] +---- +include::cassandra:example$CQL/vector-search/vector-search-cycling.cql[tag=create-vs-table] +---- + +== Create a table with a frozen UDT + +Create the `race_winners` table that has a frozen user-defined type (UDT): + +[source,language-cql] +---- +include::cassandra:example$CQL/race_winners-table.cql[tag=usetype] +---- + +See xref:developing/user-defined-type-create.adoc[Create a user-defined type] for information on Create UDTs. +UDTs can be created unfrozen if only non-collection fields are used in the user-defined type creation. +If the table is created with an unfrozen UDT, then xref:developing/inserting/insert-user-defined-type.adoc[individual field values can be updated and deleted]. + +== Create a table with a CDC log + +Create a change data capture log for the `cyclist_id` table: + +[source,language-cql] +---- +include::cassandra:example$CQL/cyclist_id-table.cql[tag=comp_pk] +---- + +CDC logging must be enabled in cassandra.yaml. + +[CAUTION] +==== +Before enabling CDC logging, have a plan for moving and consuming the log information. +After the disk space limit is reached, writes to CDC-enabled tables are rejected until more space is freed. +See https://docs.datastax.com/en/dse/6.8/dse-admin/datastax_enterprise/config/configCassandra_yaml.html#configCassandra_yaml__cdcSpaceSection[Change-data-capture (CDC) space settings] for information about available CDC settings. +==== + +== Storing data in descending order + +The following example shows a table definition that stores the categories with the highest points first. + +[source,language-cql] +---- +include::cassandra:example$CQL/cyclist_category-table.cql[tag=cpartitionkey] +---- + +[[restore-commit-log]] +== Restoring from the table ID for commit log replay + +Recreate a table with its original ID to facilitate restoring table data by replaying commit logs: + +[source,language-cql] +---- +include::cassandra:example$CQL/cyclist_emails-table.cql[tag=ID] +---- + +To retrieve a table's ID, query the `id` column of `system_schema.tables`. +For example: + +[source,language-cql] +---- +include::cassandra:example$CQL/cyclist_emails-table.cql[tag=select_id_from_system_schema] +---- + +To perform a restoration of the table, see xref:managing/operating/backups.adoc[Backups] for more information. diff --git a/doc/modules/cassandra/pages/reference/cql-commands/create-table.adoc b/doc/modules/cassandra/pages/reference/cql-commands/create-table.adoc new file mode 100644 index 0000000000..69cb7cc743 --- /dev/null +++ b/doc/modules/cassandra/pages/reference/cql-commands/create-table.adoc @@ -0,0 +1,95 @@ += CREATE TABLE +:description: Defines the columns of a new table. + +{description} + +{product} supports creating a new https://cassandra.apache.org/_/glossary.html#table[table] in the selected keyspace. +Use `IF NOT EXISTS` to suppress the error message if the table already exists; +no table is created. +A xref:cassandra:reference/static.adoc[static column] can store the same data in multiple clustered rows of a partition, and then retrieve that data with a single `SELECT` statement. + +Tables support a single xref:developing/cql/counter-column.adoc[counter column]. + +*See also:* xref:cassandra:reference/cql-commands/alter-table.adoc[ALTER TABLE], +xref:cassandra:reference/cql-commands/drop-table.adoc[DROP TABLE], +xref:cassandra:reference/cql-commands/create-custom-index.adoc[CREATE CUSTOM INDEX] for Storage-Attached Indexes (SAI), xref:cassandra:reference/cql-commands/create-index.adoc[CREATE INDEX] for secondary indexes (2i) + +== Syntax + +BNF definition: + +[source,bnf] +---- +include::cassandra:example$BNF/create_table.bnf[] +---- + +// tag::syntax[] +---- +CREATE TABLE [ IF NOT EXISTS ] [.] + ( [ , ... ] | PRIMARY KEY (column_list) ) + [ WITH [ ] + [ [ AND ] CLUSTERING ORDER BY [ (ASC | DESC) ] ] + [ [ AND ] ID = '' ] ] ; +---- +// end::syntax[] + +.Syntax legend +[%collapsible] +==== +include::partial$cql-syntax-legend.adoc[] +==== + +== Required parameters + +*table_name*:: +Name of the table to index. + +*column_name*:: +Name of the column. + +// Column Definitions + +include::cassandra:partial$table-column-definitions.adoc[] + +// Primary Key + +include::cassandra:partial$primary-key-column.adoc[] + +// Table Options + +include::cassandra:partial$table-properties.adoc[] + +// Compression + +include::cassandra:partial$compress-subproperties.adoc[] + +// Compaction + +include::cassandra:partial$compact-subproperties.adoc[] + +== Optional parameters + +// Table Keywords + +include::cassandra:partial$cluster-order.adoc[] + +*index_name*:: +Name of the index. +Enclose in quotes to use special characters or preserve capitalization. +If no name is specified, {product} names the index: `__idx`. + +*keyspace_name*:: +Name of the keyspace that contains the table to index. +If no name is specified, the current keyspace is used. + +== Usage notes + +If the column already contains data, it is indexed during the execution of this statement. +After an index has been created, it is automatically updated when data in the column changes. + +Indexing with the `CREATE INDEX` command can impact performance. +Before creating an index, be aware of when and xref:cassandra:developing/indexing/2i/2i-when-to-use.adoc#when-no-index[when not to create an index]. + +*Restriction:* Indexing counter columns is not supported. + +include::create-table-examples.adoc[leveloffset=+1] diff --git a/doc/modules/cassandra/pages/reference/cql-commands/drop-table.adoc b/doc/modules/cassandra/pages/reference/cql-commands/drop-table.adoc new file mode 100644 index 0000000000..2aba87ccdb --- /dev/null +++ b/doc/modules/cassandra/pages/reference/cql-commands/drop-table.adoc @@ -0,0 +1,52 @@ += DROP TABLE +:description: Immediate, irreversible removal of a table, including all data contained in the table. + +{description} + +*Restriction:* xref:reference:cql-commands/drop-materialized-view.adoc[Drop all materialized views] associated with the table before dropping the table. +An error message lists any materialized views that are based on the table: `+InvalidRequest: Error from server: code=2200 [Invalid query] message="Cannot drop table when materialized views still depend on it (cycling.{cyclist_by_age})"+` + +*See also:* xref:cassandra:reference/cql-commands/create-table.adoc[CREATE TABLE], +xref:cassandra:reference/cql-commands/alter-table.adoc[ALTER TABLE], +xref:cassandra:reference/cql-commands/create-custom-index.adoc[CREATE CUSTOM INDEX] for Storage-Attached Indexes (SAI), xref:cassandra:reference/cql-commands/create-index.adoc[CREATE INDEX] for secondary indexes (2i) + +== Syntax + +BNF definition: + +[source,bnf] +---- +include::cassandra:example$BNF/drop_table.bnf[] +---- + +// tag::syntax[] +---- +DROP TABLE [ IF EXISTS ] [.] ; +---- +// end::syntax[] + +.Syntax legend +[%collapsible] +==== +include::cassandra:partial$cql-syntax-legend.adoc[] +==== + +== Required parameters + +*table_name*:: +Name of the table to drop. + +== Optional parameters + +*keyspace_name*:: +Name of the keyspace that contains the table to drop. +If no name is specified, the current keyspace is used. + +== Examples + +Drop the `cyclist_name` table: + +[source,language-cql] +---- +include::cassandra:example$CQL/cyclist_name-table.cql[tag=droptble] +---- diff --git a/doc/modules/cassandra/pages/vector-search/_query-vector-data-cycling.adoc b/doc/modules/cassandra/pages/vector-search/_query-vector-data-cycling.adoc index e6892e2c12..081d664880 100644 --- a/doc/modules/cassandra/pages/vector-search/_query-vector-data-cycling.adoc +++ b/doc/modules/cassandra/pages/vector-search/_query-vector-data-cycling.adoc @@ -1,24 +1,24 @@ = Query vector data with CQL -To query data using Vector Search, use a `SELECT` query: +To query data using Vector Search, use a `SELECT` query: [source,cql] ---- include::example$CQL/vector-search/vector-search-cycling.cql[tag=select-vector-data-cycling] ---- -To obtain the distance calculation of the best scoring node closest to the query data as part of the results, use a `SELECT` query: +To obtain the similarity calculation of the best scoring node closest to the query data as part of the results, use a `SELECT` query: [source,cql] ---- include::example$CQL/vector-search/vector-search-cycling.cql[tag=select-vector-data-similarity-cycling] ---- -The supported functions for this type of query are: +The supported functions for this type of query are: * similarity_dot_product * similarity_cosine -* similarity_euclidean +* similarity_euclidean with the parameters of (, ). Both parameters represent vectors. diff --git a/doc/modules/cassandra/pages/vector-search/overview.adoc b/doc/modules/cassandra/pages/vector-search/overview.adoc index 3448d65d06..ee06d4cbd4 100644 --- a/doc/modules/cassandra/pages/vector-search/overview.adoc +++ b/doc/modules/cassandra/pages/vector-search/overview.adoc @@ -21,10 +21,10 @@ Create, check, alter, drop, and query Vector Search. // xref:cassandra:vector-search/vector-search-operations.adoc[Vector Search operations]:: // Configuring and monitoring. -xref:cassandra:vector-search/vector-search-query.adoc[Querying with Vector Search]:: -Understand how to run Vector Search queries. +// xref:cassandra:vector-search/vector-search-query.adoc[Querying with Vector Search]:: +// Understand how to run Vector Search queries. xref:cassandra:vector-search/data-modeling.adoc[Data modeling with Vector Search]:: The ins and outs of data modeling with Vector Search. -*Reference:* xref:cassandra:reference/cql-commands/create-table.adoc[CREATE TABLE], xref:cassandra:reference/cql-commands/create-custom-index.adoc[CREATE CUSTOM INDEX] \ No newline at end of file +*Reference:* xref:cassandra:reference/cql-commands/create-table.adoc[CREATE TABLE], xref:cassandra:reference/cql-commands/create-index.adoc[CREATE INDEX], xref:cassandra:reference/cql-commands/create-custom-index.adoc[CREATE CUSTOM INDEX] \ No newline at end of file diff --git a/doc/modules/cassandra/pages/vector-search/vector-search-working-with.adoc b/doc/modules/cassandra/pages/vector-search/vector-search-working-with.adoc new file mode 100644 index 0000000000..a90c642c95 --- /dev/null +++ b/doc/modules/cassandra/pages/vector-search/vector-search-working-with.adoc @@ -0,0 +1,13 @@ += Working with Vector Search + +include::_create-vector-keyspace-cycling.adoc[leveloffset=+1] + +include::_use-vector-keyspace-cycling.adoc[leveloffset=+1] + +include::_create-vector-table-cycling.adoc[leveloffset=+1] + +include::_create-vector-index-cycling.adoc[leveloffset=+1] + +include::_load-vector-data-cycling.adoc[leveloffset=+1] + +include::_query-vector-data-cycling.adoc[leveloffset=+1] \ No newline at end of file diff --git a/doc/modules/cassandra/partials/cluster-order.adoc b/doc/modules/cassandra/partials/cluster-order.adoc new file mode 100644 index 0000000000..6fa744bb72 --- /dev/null +++ b/doc/modules/cassandra/partials/cluster-order.adoc @@ -0,0 +1,14 @@ +=== Table keywords + +*CLUSTERING ORDER BY ( column_name ASC | DESC)* :: +Order rows storage to make use of the on-disk sorting of columns. +Specifying order can make query results more efficient. +Options are: ++ +`ASC`: ascending (default order) ++ +`DESC`: descending, reverse order + +*ID* :: +If a table is accidentally dropped with xref:reference/cql-commands/drop-table.adoc[DROP TABLE], use this option to +xref:reference/cql-commands/create-table.adoc#restore-commit-log[recreate the table] and run a commit log replay to retrieve the data. diff --git a/doc/modules/cassandra/partials/compact-subproperties.adoc b/doc/modules/cassandra/partials/compact-subproperties.adoc new file mode 100644 index 0000000000..1cee84b7d2 --- /dev/null +++ b/doc/modules/cassandra/partials/compact-subproperties.adoc @@ -0,0 +1,262 @@ +=== compaction = \{compaction_map} +:description: Construct a map of the compaction option and its subproperties. + +Defines the strategy for cleaning up data after writes. + +Syntax uses a simple JSON format: + +[source,language-cql] +---- +compaction = { + 'class' : '', + '' : [, ...] } +---- + +where the is xref:STCS[SizeTieredCompactionStrategy], xref:TWCS[TimeWindowCompactionStrategy], or xref:LCS[LeveledCompactionStrategy]. + +[IMPORTANT] +==== +Use only compaction implementations bundled with {product}. +See xref:managing/operating/compaction/index.adoc[Compaction] for more details. +==== + +==== Common properties + +The following properties apply to all compaction strategies. + +[source,language-cql] +---- +compaction = { + 'class' : 'compaction_strategy_name', + 'enabled' : (true | false), + 'log_all' : (true | false), + 'only_purge_repaired_tombstone' : (true | false), + 'tombstone_threshold' : , + 'tombstone_compaction_interval' : , + 'unchecked_tombstone_compaction' : (true | false), + 'min_threshold' : , + 'max_threshold' : } +---- + +*enabled* :: +Enable background compaction. + +* `true` runs minor compactions. +* `false` disables minor compactions. + ++ +[TIP] +==== +Use `nodetool enableautocompaction` to start running compactions. +==== + +{empty}:: +Default: `true` + +*log_all* :: +Activates advanced logging for the entire cluster. ++ +Default: `false` + +*only_purge_repaired_tombstone* :: +Enabling this property prevents data from resurrecting when repair is not run within the `gc_grace_seconds`. +When its been a long time between repairs, the database keeps all tombstones. ++ + +* `true` - Only allow tombstone purges on repaired SSTables. +* `false` - Purge tombstones on SSTables during compaction even if the table has not been repaired. + ++ +Default: `false` + +*tombstone_threshold* :: +The ratio of garbage-collectable tombstones to all contained columns. +If the ratio exceeds this limit, compactions starts only on that table to purge the tombstones. ++ +Default: `0.2` + +*tombstone_compaction_interval* :: +Number of seconds before compaction can run on an SSTable after it is created. +An SSTable is eligible for compaction when it exceeds the `tombstone_threshold`. +Because it might not be possible to drop tombstones when doing a single SSTable compaction, and since the compaction is triggered base on an estimated tombstone ratio, this setting makes the minimum interval between two single SSTable compactions tunable to prevent an SSTable from being constantly re-compacted. ++ +Default: `86400` (1 day) + +*unchecked_tombstone_compaction* :: +Setting to `true` allows tombstone compaction to run without pre-checking which tables are eligible for the operation. +Even without this pre-check, {product} checks an SSTable to make sure it is safe to drop tombstones. ++ +Default: `false` + +*min_threshold* :: +The minimum number of SSTables to trigger a minor compaction. ++ +*Restriction:* Not used in `LeveledCompactionStrategy`. ++ +Default: `4` + +*max_threshold* :: +The maximum number of SSTables before a minor compaction is triggered. ++ +*Restriction:* Not used in `LeveledCompactionStrategy`. ++ +Default: `32` + +[[STCS]] +==== SizeTieredCompactionStrategy + +The compaction class `SizeTieredCompactionStrategy` (STCS) triggers a minor compaction when table meets the `min_threshold`. +Minor compactions do not involve all the tables in a keyspace. +See +xref:operating/compaction/stcs.adoc#stcs_options[SizeTieredCompactionStrategy (STCS)]. + +[NOTE] +==== +Default compaction strategy. +==== + +The following properties only apply to SizeTieredCompactionStrategy: + +[source,language-cql] +---- +compaction = { + 'class' : 'SizeTieredCompactionStrategy', + 'bucket_high' : , + 'bucket_low' : , + 'min_sstable_size' : } +---- + +*bucket_high* :: +Size-tiered compaction merges sets of SSTables that are approximately the same size. +The database compares each SSTable size to the average of all SSTable sizes for this table on the node. +It merges SSTables whose size in KB are within [average-size * bucket_low] and [average-size * bucket_high]. ++ +Default: `1.5` + +*bucket_low* :: +Size-tiered compaction merges sets of SSTables that are approximately the same size. +The database compares each SSTable size to the average of all SSTable sizes for this table on the node. +It merges SSTables whose size in KB are within [average-size * bucket_low] and [average-size * bucket_high]. ++ +Default: `0.5` + +*min_sstable_size* :: +STCS groups SSTables into buckets. +The bucketing process groups SSTables that differ in size by less than 50%. +This bucketing process is too fine-grained for small SSTables. +If your SSTables are small, use this option to define a size threshold in MB below which all SSTables belong to one unique bucket. ++ +Default: `50` (MB) + +[NOTE] +==== +The `cold_reads_to_omit` property for +xref:operating/compaction/stcs.adoc#stcs_options[SizeTieredCompactionStrategy (STCS)] is no longer supported. +==== + +[[TWCS]] +==== TimeWindowCompactionStrategy + +The compaction class `TimeWindowCompactionStrategy` (TWCS) compacts SSTables using a series of _time windows_ or _buckets_. +TWCS creates a new time window within each successive time period. +During the active time window, TWCS compacts all SSTables flushed from memory into larger SSTables using STCS. +At the end of the time period, all of these SSTables are compacted into a single SSTable. +Then the next time window starts and the process repeats. +See xref:operating/compaction/twcs.adoc#twcs_options[TimeWindowCompactionStrategy (TWCS)]. + +[NOTE] +==== +All of the properties for STCS are also valid for TWCS. +==== + +The following properties apply only to TimeWindowCompactionStrategy: + +[source,language-cql] +---- +compaction = { + 'class' : 'TimeWindowCompactionStrategy, + 'compaction_window_unit' : , + 'compaction_window_size' : , + 'split_during_flush' : (true | false) } +---- + +*compaction_window_unit* :: +Time unit used to define the bucket size. +The value is based on the Java `TimeUnit`. +For the list of valid values, see the Java API `TimeUnit` page located at https://docs.oracle.com/javase/8/docs/api/java/util/concurrent/TimeUnit.html. ++ +Default: `days` + +*compaction_window_size* :: +Units per bucket. ++ +Default: `1` + +[[LCS]] +==== LeveledCompactionStrategy + +The compaction class `LeveledCompactionStrategy` (LCS) creates SSTables of a fixed, relatively small size (160 MB by default) that are grouped into levels. +Within each level, SSTables are guaranteed to be non-overlapping. +Each level (L0, L1, L2 and so on) is 10 times as large as the previous. +Disk I/O is more uniform and predictable on higher than on lower levels as SSTables are continuously being compacted into progressively larger levels. +At each level, row keys are merged into non-overlapping SSTables in the next level. +See https://docs.datastax.com/en/dse/6.8/dse-arch/datastax_enterprise/dbInternals/dbIntHowDataMaintain.html#dbIntHowDataMaintain__lcs-compaction[LeveledCompactionStrategy (LCS)]. + +[NOTE] +==== +For more guidance, see https://www.datastax.com/dev/blog/when-to-use-leveled-compaction[When to Use Leveled Compaction] and https://www.datastax.com/dev/blog/leveled-compaction-in-apache-cassandra[Leveled Compaction] blog. +==== + +The following properties only apply to LeveledCompactionStrategy: + +[source,language-cql] +---- +compaction = { + 'class' : 'LeveledCompactionStrategy, + 'sstable_size_in_mb' : } +---- + +*sstable_size_in_mb* :: +The target size for SSTables that use the LeveledCompactionStrategy. +Although SSTable sizes should be less or equal to sstable_size_in_mb, it is possible that compaction could produce a larger SSTable during compaction. +This occurs when data for a given partition key is exceptionally large. +The {product} database does not split the data into two SSTables. ++ +Default: `160` ++ +[CAUTION] +==== +The default value, 160 MB, may be inefficient and negatively impact database indexing and the queries that rely on indexes. +For example, consider the benefit of using higher values for sstable_size_in_mb in tables that use (SAI) indexes. +For related information, see xref:developing/cql/indexing/sai/configuring.adoc#saiConfigure__saiCompactionStrategies[Compaction strategies]. +==== + +==== DateTieredCompactionStrategy (deprecated) + +[IMPORTANT] +==== +Use xref:TWCS[TimeWindowCompactionStrategy] instead. +==== + +Stores data written within a certain period of time in the same SSTable. + +*base_time_seconds* :: +The size of the first time window. ++ +Default: `3600` + +*max_sstable_age_days (deprecated)* :: +{product} does not compact SSTables if its most recent data is older than this property. +Fractional days can be set. ++ +Default: `1000` + +*max_window_size_seconds* :: +The maximum window size in seconds. ++ +Default: `86400` + +*timestamp_resolution* :: +Units, or , to match the timestamp of inserted data. ++ +Default: `MICROSECONDS` diff --git a/doc/modules/cassandra/partials/compaction-strategies.adoc b/doc/modules/cassandra/partials/compaction-strategies.adoc new file mode 100644 index 0000000000..d37e8e0dd7 --- /dev/null +++ b/doc/modules/cassandra/partials/compaction-strategies.adoc @@ -0,0 +1,9 @@ +|=== +| Compaction Strategy | | | + +| xref:managing/operating/compaction/ucs.adoc[UCS] +| xref:managing/operating/compaction/ccs.adoc[LCS] +| xref:managing/operating/compaction/stsc.adoc[STCS] +| xref:managing/operating/compaction/twcs.adoc[TWCS] + +|=== diff --git a/doc/modules/cassandra/partials/compress-subproperties.adoc b/doc/modules/cassandra/partials/compress-subproperties.adoc new file mode 100644 index 0000000000..1a0d3a4753 --- /dev/null +++ b/doc/modules/cassandra/partials/compress-subproperties.adoc @@ -0,0 +1,69 @@ +=== compression = { compression_map } +:description: Sets table compression. + +Configure the `compression_map` by specifying the compression algorithm `class` followed by the subproperties in simple JSON format. + +[TIP] +==== +Implement custom compression classes using the `org.apache.cassandra.io.compress.ICompressor` interface. +==== + +[source, console] +---- +compression = { + ['class' : '', + 'chunk_length_in_kb' : '', + 'crc_check_chance' : '',] + | 'sstable_compression' : ''] +} +---- + +*class* :: +Sets the compressor name. +{product} provides the following built-in classes: ++ +[width="100%",cols="40%,19%,11%,13%,6%,11%",options="header",] +|=== +|Compression Algorithm |Cassandra Class |Compression |Decompression +|Ratio |C* Version + +|https://lz4.github.io/lz4/[LZ4] |`LZ4Compressor` | A+ | A+ | C+ | `>=1.2.2` + +|https://lz4.github.io/lz4/[LZ4HC] |`LZ4Compressor` | C+ | A+ | B+ | `>= 3.6` + +|https://facebook.github.io/zstd/[Zstd] |`ZstdCompressor` | A- | A- | A+ | `>= 4.0` + +|http://google.github.io/snappy/[Snappy] |`SnappyCompressor` | A- | A | C | `>= 1.0` + +|https://zlib.net[Deflate (zlib)] |`DeflateCompressor` | C | C | A | `>= 1.0` +|=== ++ +[IMPORTANT] +==== +Use only compression implementations bundled with {product}. +==== ++ +Choosing the right compressor depends on your requirements for space savings over read performance. +LZ4 is fastest to decompress, followed by Snappy, then by Deflate. +Compression effectiveness is inversely correlated with decompression speed. +The extra compression from Deflate or Snappy is not enough to make up for the decreased performance for general-purpose workloads, but for archival data they may be worth considering. ++ +*Default*: `LZ4Compressor`. +*chunk_length_in_kb* :: +Size (in KB) of the block. +On disk, SSTables are compressed by block to allow random reads. +Values larger than the default value might improve the compression rate, but increases the minimum size of data to be read from disk when a read occurs. +The default value is a good middle ground for compressing tables. +Adjust compression size to account for read/write access patterns (how much data is typically requested at once) and the average size of rows in the table. ++ +*Default*: `64`. +*crc_check_chance* :: +When compression is enabled, each compressed block includes a checksum of that block for the purpose of detecting disk bit rot and avoiding the propagation of corruption to other replica. +This option defines the probability with which those checksums are checked during read. +By default they are always checked. +Set to 0 to disable checksum checking and to 0.5, for instance, to check them on every other read. ++ +*Default*: `1.0`. +*sstable_compression* :: +Disables compression. +Specify a null value. diff --git a/doc/modules/cassandra/partials/primary-key-column.adoc b/doc/modules/cassandra/partials/primary-key-column.adoc new file mode 100644 index 0000000000..9abe065f64 --- /dev/null +++ b/doc/modules/cassandra/partials/primary-key-column.adoc @@ -0,0 +1,29 @@ +== column_definition +:description: Sets the column name, defines the data type, and optionally sets a column to static or counter. + +Enclosed in parentheses after the table name, use a comma-separated list to define multiple columns. +All tables must have at least one https://cassandra.apache.org/_/glossary.html#primary-key[primary key] column. +Each column is defined using the following syntax: `+column_name cql_type_definition [STATIC | PRIMARY KEY] [, ...]+` + +*Restriction:* + +* A table must have at least one `PRIMARY KEY`. +* When `PRIMARY KEY` is at the end of a column definition, that column is the only primary key for the table, and is defined as the https://cassandra.apache.org/_/glossary.html#[partition-key][partition key]. +* A static column cannot be a primary key. +* Primary keys can include frozen collections. + +*column_name* :: +Use a unique name for each column in a table. +To preserve case or use special characters, enclose the name in double-quotes. +cql_type_definition :: +Defines the type of data allowed in the column. +See xref:reference:data-types.adoc[CQL data type] or a xref:reference:user-defined-type.adoc[user-defined type]. +*STATIC* :: +Optional, the column has a single value. +*PRIMARY KEY* :: +When the `PRIMARY KEY` is one column, append PRIMARY KEY to the end of the column definition. +This is only schema information required to create a table. +When there is one primary key, it is the partition key; +the data is divided and stored by the unique values in this column: ``column_name cql_type_definition PRIMARY KEY``. ++ +Alternatively, you can declare the primary key consisting of only one column in the same way as you declare a compound primary key. diff --git a/doc/modules/cassandra/partials/single-partition-batch-note.adoc b/doc/modules/cassandra/partials/single-partition-batch-note.adoc new file mode 100644 index 0000000000..04c8dcba8c --- /dev/null +++ b/doc/modules/cassandra/partials/single-partition-batch-note.adoc @@ -0,0 +1,10 @@ +[NOTE] +==== +If there are two different tables in the same keyspace and the two tables have the same partition key, this scenario is considered a single partition batch. +There will be a single mutation for each table. +This happens because the two tables could have different columns, even though the keyspace and partition are the same. +Batches allow a caller to bundle multiple operations into a single batch request. +All the operations are performed by the same coordinator. +The best use of a batch request is for a single partition in multiple tables in the same keyspace. +Also, batches provide a guarantee that mutations will be applied in a particular order. +==== diff --git a/doc/modules/cassandra/partials/table-column-definitions.adoc b/doc/modules/cassandra/partials/table-column-definitions.adoc new file mode 100644 index 0000000000..9abe065f64 --- /dev/null +++ b/doc/modules/cassandra/partials/table-column-definitions.adoc @@ -0,0 +1,29 @@ +== column_definition +:description: Sets the column name, defines the data type, and optionally sets a column to static or counter. + +Enclosed in parentheses after the table name, use a comma-separated list to define multiple columns. +All tables must have at least one https://cassandra.apache.org/_/glossary.html#primary-key[primary key] column. +Each column is defined using the following syntax: `+column_name cql_type_definition [STATIC | PRIMARY KEY] [, ...]+` + +*Restriction:* + +* A table must have at least one `PRIMARY KEY`. +* When `PRIMARY KEY` is at the end of a column definition, that column is the only primary key for the table, and is defined as the https://cassandra.apache.org/_/glossary.html#[partition-key][partition key]. +* A static column cannot be a primary key. +* Primary keys can include frozen collections. + +*column_name* :: +Use a unique name for each column in a table. +To preserve case or use special characters, enclose the name in double-quotes. +cql_type_definition :: +Defines the type of data allowed in the column. +See xref:reference:data-types.adoc[CQL data type] or a xref:reference:user-defined-type.adoc[user-defined type]. +*STATIC* :: +Optional, the column has a single value. +*PRIMARY KEY* :: +When the `PRIMARY KEY` is one column, append PRIMARY KEY to the end of the column definition. +This is only schema information required to create a table. +When there is one primary key, it is the partition key; +the data is divided and stored by the unique values in this column: ``column_name cql_type_definition PRIMARY KEY``. ++ +Alternatively, you can declare the primary key consisting of only one column in the same way as you declare a compound primary key. diff --git a/doc/modules/cassandra/partials/table-properties.adoc b/doc/modules/cassandra/partials/table-properties.adoc new file mode 100644 index 0000000000..2c49a7a495 --- /dev/null +++ b/doc/modules/cassandra/partials/table-properties.adoc @@ -0,0 +1,146 @@ +[[table_options]] +== table_options +:description: CQL table properties and descriptions of the syntax. + +Tunes data handling, including I/O operations, compression, and compaction. +Table property options use the following syntax: + +* Single values: ` = ''` +* Multiple values: `+ = { '' : '' [, ...] } [AND ...]+` ++ +Simple JSON format, key-value pairs in a comma-separated list enclosed by curly brackets. + +[NOTE] +==== +When no value is specified, the default is used. +==== + +In a CREATE TABLE (or ALTER TABLE) CQL statement, use a `WITH` clause to define table property options. +Separate multiple values with `AND`. + +[source,language-cql] +---- +CREATE TABLE [.] +WITH option_name = '' +AND option_name = {}; +---- + +*bloom_filter_fp_chance = * :: +False-positive probability for SSTable https://en.wikipedia.org/wiki/Bloom_filter[bloom filter]. +When a client requests data, the bloom filter checks if the row exists before executing disk I/O. +Values range from 0 to 1.0, where: `0` is the minimum value use to enable the largest possible bloom filter (uses the most memory) and `1.0` is the maximum value disabling the bloom filter. + +[TIP] +==== +Recommended setting: `0.1`. +A higher value yields diminishing returns. +==== + +*Default*: `bloom_filter_fp_chance = '0.01'` + +*caching = { 'keys' : 'value', 'rows_per_partition' : 'value'}* :: +Optimizes the use of cache memory without manual tuning. +Weighs the cached data by size and access frequency. +Coordinate this setting with the global caching properties in the cassandra.yaml file. +Valid values: + +* `ALL`-- all primary keys or rows +* `NONE`-- no primary keys or rows +* ``: (rows per partition only) -- specify a whole number *Default*: `{ 'keys': 'ALL', 'rows_per_partition': 'NONE' }` + +*cdc* :: +Creates a Change Data Capture (CDC) log on the table. ++ +Valid values: + +* `TRUE`- create CDC log +* `FALSE`- do not create CDC log +*comments = 'some text that describes the table'* :: +Provide documentation on the table. + +[TIP] +==== +Enter a description of the types of queries the table was designed to satisfy. +==== + +[[DefaultTTL]]*default_time_to_live* :: +TTL (Time To Live) in seconds, where zero is disabled. +The maximum configurable value is `630720000` (20 years). +Beginning in 2018, the expiration timestamp can exceed the maximum value supported by the storage engine; +see the warning below. +If the value is greater than zero, TTL is enabled for the entire table and an expiration timestamp is added to each column. +A new TTL timestamp is calculated each time the data is updated and the row is removed after all the data expires. ++ +Default value: `0` (disabled). ++ +[WARNING] +==== +The database storage engine can only encode TTL timestamps through `January 19 2038 03:14:07 UTC` due to the https://en.wikipedia.org/wiki/Year_2038_problem[Year 2038 problem]. +The TTL date overflow policy determines whether requests with expiration timestamps later than the maximum date are rejected or inserted. +==== + +[[gc_grace_seconds]]*gc_grace_seconds* :: +Seconds after data is marked with a tombstone (deletion marker) before it is eligible for garbage-collection. +Default value: 864000 (10 days). +The default value allows time for the database to maximize consistency prior to deletion. ++ +[NOTE] +==== +Tombstoned records within the grace period are excluded from xref:managing/operating/hints.adoc[hints] or xref:developing/cql/ddl.adoc#batch_statement[batched mutations]. +==== ++ +In a single-node cluster, this property can safely be set to zero. +You can also reduce this value for tables whose data is not explicitly deleted -- for example, tables containing only data with https://cassandra.apache.org/_/glossary.html#gloss_ttl[TTL] set, or tables with `default_time_to_live` set. +However, if you lower the `gc_grace_seconds` value, consider its interaction with these operations: ++ + +* *hint replays*: When a node goes down and then comes back up, other nodes replay the write operations (called xref:managing/operating/hints.adoc[hints]) that are queued for that node while it was unresponsive. +The database does not replay hints older than gc_grace_seconds after creation. +The xref:managing/configuration/configuration/cass_yaml_file.adoc#max_hint_window[max_hint_window] setting in the +xref:managing/configuration/configuration/cass_yaml_file.adoc[cassandra.yaml] file sets the time limit (3 hours by default) for collecting hints for the unresponsive node. + +* *batch replays*: Like hint queues, xref:developing/cql/ddl.adoc#batch_statement[batch operations] store database mutations that are replayed in sequence. +As with hints, the database does not replay a batched mutation older than gc_grace_seconds after creation. +If your application uses batch operations, consider the possibility that decreasing gc_grace_seconds increases the chance that a batched write operation may restore deleted data. +The configuration/cass_yaml_file.html#batchlog_replay_throttle[batchlog_replay_throttle] property in the cassandra.yaml file give some control of the batch replay process. +The most important factors, however, are the size and scope of the batches you use. + +*memtable_flush_period_in_ms* :: +Milliseconds before `memtables` associated with the table are flushed. +When memtable_flush_period_in_ms=0, the memtable will flush when: + +* the flush threshold is met +* on shutdown +* on nodetool flush +* when commitlogs get full *Default*: `0` + +*min_index_interval* :: +Minimum gap between index entries in the index summary. +A lower min_index_interval means the index summary contains more entries from the index, which allows the database to search fewer index entries to execute a read. +A larger index summary may also use more memory. +The value for min_index_interval is the densest possible sampling of the index. + +*max_index_interval* :: +If the total memory usage of all index summaries reaches this value, +{product} decreases the index summaries for the coldest SSTables to the maximum set by max_index_interval. +The max_index_interval is the sparsest possible sampling in relation to memory pressure. + +*speculative_retry* :: +Configures https://www.datastax.com/dev/blog/rapid-read-protection-in-cassandra-2-0-2[rapid read protection]. +Normal read requests are sent to just enough replica nodes to satisfy the https://cassandra.apache.org/_/glossary.html#gloss_consistency_level[consistency level]. +In rapid read protection, extra read requests are sent to other replicas, even after the consistency level has been met. +The speculative retry property specifies the trigger for these extra read requests. ++ + +* ALWAYS: The coordinator node sends extra read requests to all other replicas after every read of that table. +* percentile: Track each table's typical read latency (in milliseconds). +Coordinator node retrieves the typical latency time of the table being read and calculates X percent of that figure. +The coordinator sends redundant read requests if the number of milliseconds it waits without responses exceeds that calculated figure. ++ +For example, if the speculative_retry property for Table_A is set to `80percentile`, and that table's typical latency is 60 milliseconds, the coordinator node handling a read of Table_A would send a normal read request first, and send out redundant read requests if it received no responses within 48ms, which is 80% of 60ms. ++ +* ms: The coordinator node sends extra read requests to all other replicas if the coordinator node has not received any responses within `N` milliseconds. +* NONE: The coordinator node does not send extra read requests after any read of that table. + +include::partial$compaction-strategies.adoc[] +