|   | 
CQL by Example | 
 
| 
 | 
 
 
Subject: CQL by Example
Author: EricJ
 In response to: Apache Cassandra -- Access via CQL
Posted on: 09/30/2015 01:50:04 AM
  
Step 1. Create a new keyspace called 'playlist'
  
cqlsh> create KEYSPACE playlist WITH replication 
       = {'class':'SimpleStrategy', 'replication_factor': 1 };
  Step 2. Use a keyspace Step 3. Create column families or tables 
cqlsh:playlist> create table artists_by_first_letter (
       first_letter text, 
       artist text, 
       primary key (first_letter, artist));
cqlsh:playlist> create table track_by_artist (
       track text, 
       artist text, 
       track_id UUID, 
       track_length_in_seconds int, 
       genre text,music_file text, 
       primary key (artist, track, track_id));
cqlsh:playlist> create table track_by_genre (
       track text, artist text, 
       track_id UUID, 
       track_length_in_seconds int, 
       genre text,
       music_file text, 
       primary key (genre, artist, track, track_id));
 Step 4. Populate the tables with data from files
cqlsh:playlist> copy artists_by_first_letter (first_letter, artist) 
     FROM 'scripts/artists.csv' WITH DELIMITER = '|';
cqlsh:playlist> copy track_by_artist (track_id, genre, artist, track, 
        track_length_in_seconds, music_file) 
     FROM 'scripts/songs.csv' 
     WITH DELIMITER = '|'  AND HEADER=true;
cqlsh:playlist> copy track_by_genre (track_id, genre, artist, track, 
        track_length_in_seconds, music_file) 
     FROM 'scripts/songs.csv' 
     WITH DELIMITER = '|'  AND HEADER=true;
 Step 5. Export the tables to file
cqlsh:playlist> copy artists_by_first_letter (first_letter, artist) 
     TO 'scripts/artists_out.csv'
     WITH DELIMITER = '|' AND HEADER=true;
 Step 6. Check table content
cqlsh:playlist> select * from artists_by_first_letter;
  Step 7. Quit cqlsh
 
>  
> On 09/30/2015 01:43:53 AM  EricJ wrote:
  
 You can start CQL console by entering:
 
  If you have customized your Cassandra by:
 
  you should use the following command:
 
C:\..\bin> cqlsh 10.11.12.13:9042
 
  or
 
 
C:\..\bin> cqlsh 10.11.12.13
 
  Trouble Shooting:
  You may get error while executing CQLSH âcanât detect python version cqlshâ The error indicating that, Python is not installed in your machine. Steps to follow: 1) Download & install Python 2.7.x; 2) Add "Path" environment variable for Python directory; 3) Execute command âsetup.py installâ under âC:\apache-cassandra-2.2.1\pylibâ to install python.
  
 
References:
  | 
  | 
 
  |   
 |