table-cyclist-category

INSERT INTO cycling.cyclist_category JSON '{
  "category" : "Sprint",
  "points" : 780,
  "id" : "829aa84a-4bba-411f-a4fb-38167a987cda"
}';
COPY cycling.cyclist_category FROM 'cyclist_category.csv'
WITH DELIMITER = '|'
  AND HEADER = TRUE;
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');
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');
INSERT INTO cycling.cyclist_category JSON '{
  "category" : "GC",
  "points" : 780,
  "id" : "829aa84a-4bba-411f-a4fb-38167a987cda",
  "lastname" : "SUTHERLAND"
}';
RESTRICT ROWS ON cycling.cyclist_category USING category;
SELECT * FROM cycling.cyclist_category;
SELECT * FROM cycling.cyclist_category
  WHERE category = 'Time-trial' ORDER BY points DESC;
INSERT INTO cycling.cyclist_category JSON '{
  "category" : "Sprint",
  "points" : 700,
  "id" : "829aa84a-4bba-411f-a4fb-38167a987cda"
}';
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);
DESCRIBE TABLE cycling.cyclist_category;
DROP TABLE IF EXISTS cycling.cyclist_category;
// end:table-drop[]
" >> $results_table
echo "// end::$tag" >> $results_table
echo "Drop table cyclist_category"

tag="use-and-table-create[]"
echo -e "\n// tag::$tag" >> $results_table
$cqlsh -e "
// tag::use-and-table-create[]
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-table-create[]
" >> $results_table
echo "// end::$tag" >> $results_table
echo "Create table cyclist_category"

# DROP TABLE FOR ANOTHER TABLE CREATE
DROP TABLE IF EXISTS cycling.cyclist_category;

tag="table-create[]"
echo -e "\n// tag::$tag" >> $results_table
$cqlsh -e "
// tag::table-create[]
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::table-create[]
" >> $results_table
echo "// end::$tag" >> $results_table
echo "Create table cyclist_category"

tag="table-describe-base[]"
echo -e "\n// tag::$tag" >> $results_table
$cqlsh -e "
// tag::table-describe-base[]
DESCRIBE TABLE cycling.cyclist_category;
// end::table-describe-base[]
" >> $results_table
echo "// end::$tag" >> $results_table
echo "Described table."

tag="data-insert[]"
echo -e "// tag::$tag" >> $results_table
$cqlsh -e "
// tag::data-insert[]
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');
// end::data-insert[]
" >> $results_table
echo "// end::$tag" >> $results_table
echo "Insert cyclist_category data"

tag="restrict-rows[]"
echo -e "// tag::$tag" >> $results_table
$cqlsh -e "
// tag::restrict-rows[]
RESTRICT ROWS ON cycling.cyclist_category USING category;
// end::restrict-rows[]
" >> $results_table
echo "// end::$tag" >> $results_table
echo "Restrict rows"

# Query category ORDER BY DESCENDING points
tag="select-category-order-by[]"
echo -e "// tag::$tag" >> $results_table
$cqlsh -e "
// tag::select-category-order-by[]
SELECT * FROM cycling.cyclist_category
  WHERE category = 'Time-trial' ORDER BY points DESC;
// end::select-category-order-by[]
" >> $results_table
echo "// end::$tag" >> $results_table
echo "Select category ORDER BY points"

# Add JSON rows

tag="insert-SUTHERLAND[]"
echo -e "// tag::$tag" >> $results_table
$cqlsh -e "
// tag::insert-SUTHERLAND[]
INSERT INTO cycling.cyclist_category JSON '{
  "category" : "GC",
  "points" : 780,
  "id" : "829aa84a-4bba-411f-a4fb-38167a987cda",
  "lastname" : "SUTHERLAND"
}';
// end::insert-SUTHERLAND[]
" >> $results_table
echo "// end::$tag" >> $results_table
echo "Insert SUTHERLAND"

tag="clear-lastname[]"
echo -e "// tag::$tag" >> $results_table
$cqlsh -e "
// tag::clear-lastname[]
INSERT INTO cycling.cyclist_category JSON '{
  "category" : "Sprint",
  "points" : 780,
  "id" : "829aa84a-4bba-411f-a4fb-38167a987cda"
}';
// end::clear-lastname[]
" >> $results_table
echo "// end::$tag" >> $results_table
echo "Clear lastname"

tag="unset[]"
echo -e "// tag::$tag" >> $results_table
$cqlsh -e "
// tag::unset[]
INSERT INTO cycling.cyclist_category JSON '{
  "category" : "Sprint",
  "points" : 780,
  "id" : "829aa84a-4bba-411f-a4fb-38167a987cda"
}'
DEFAULT UNSET;
// end::unset[]
" >> $results_table
echo "// end::$tag" >> $results_table
echo "Unset"

tag="set-points[]"
echo -e "// tag::$tag" >> $results_table
$cqlsh -e "
// tag::set-points[]
INSERT INTO cycling.cyclist_category JSON '{
  "category" : "Sprint",
  "points" : 700,
  "id" : "829aa84a-4bba-411f-a4fb-38167a987cda"
}';
// end::set-points[]
" >> $results_table
echo "// end::$tag" >> $results_table
echo "Set points"

# Query all
tag="select-all[]"
echo -e "// tag::$tag" >> $results_table
$cqlsh -e "
// tag::select-all[]
SELECT * FROM cycling.cyclist_category;
// end::select-all[]
" >> $results_table
echo "// end::$tag" >> $results_table
echo "Select all data"

tag="copy[]"
echo -e "// tag::$tag" >> $results_table
$cqlsh -e "
// tag::copy[]
COPY cycling.cyclist_category FROM 'cyclist_category.csv'
WITH DELIMITER = '|'
  AND HEADER = TRUE;
// end::copy[]
" >> $results_table
echo "// end::$tag" >> $results_table
echo "Copy data"

# Truncate table
tag="table-truncate[]"
echo -e "// tag::$tag" >> $results_table
$cqlsh -e "
// tag::table-truncate[]
TRUNCATE TABLE cycling.cyclist_category;
// end::table-truncate[]
" >> $results_table
echo "// end::$tag" >> $results_table
echo "Truncate table"

# Re-insert data
tag="data-insert-again[]"
echo -e "// tag::$tag" >> $results_table
$cqlsh -e "
// tag::data-insert-again[]
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');
// end::data-insert-again[]
" >> $results_table
echo "// end::$tag" >> $results_table
echo "Insert cyclist_category data again"
TRUNCATE TABLE cycling.cyclist_category;
INSERT INTO cycling.cyclist_category JSON '{
  "category" : "Sprint",
  "points" : 780,
  "id" : "829aa84a-4bba-411f-a4fb-38167a987cda"
}'
DEFAULT UNSET;
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);

Was this helpful?

Give Feedback

How can we improve the documentation?

© 2024 DataStax | Privacy policy | Terms of use

Apache, Apache Cassandra, Cassandra, Apache Tomcat, Tomcat, Apache Lucene, Apache Solr, Apache Hadoop, Hadoop, Apache Pulsar, Pulsar, Apache Spark, Spark, Apache TinkerPop, TinkerPop, Apache Kafka and Kafka are either registered trademarks or trademarks of the Apache Software Foundation or its subsidiaries in Canada, the United States and/or other countries. Kubernetes is the registered trademark of the Linux Foundation.

General Inquiries: +1 (650) 389-6000, info@datastax.com