go to  ForumEasy.com   
JavaPro
Home » Archive » Message


[Email To Friend][View in Live Context][prev topic « prev post | next post » next topic]
  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
cqlsh> use playlist;


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
exit;


 

> On 09/30/2015 01:43:53 AM EricJ wrote:


You can start CQL console by entering:
C:\..\bin> cqlsh


If you have customized your Cassandra by:
 rpc_address: 10.11.12.13


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:

  •  


     
    Powered by ForumEasy © 2002-2022, All Rights Reserved. | Privacy Policy | Terms of Use
     
    Get your own forum today. It's easy and free.