go to  ForumEasy.com   
JavaPro
Home » Archive » Message


[Email To Friend][View in Live Context][prev topic « prev post | next post » next topic]
  How do I know what 'keyspace' the node currently hosts?
 
Subject: How do I know what 'keyspace' the node currently hosts?
Author: EricJ
In response to: CQL by Example
Posted on: 09/30/2015 01:53:03 AM


cqlsh> select * from system.schema_keyspaces;

 keyspace_name      | durable_writes | strategy_class  | strategy_options
--------------------+----------------+---------------------------------------------
        system_auth |           True | SimpleStrategy | {"replication_factor":"1"}
           playlist |           True | SimpleStrategy | {"replication_factor":"1"}
 system_distributed |           True | SimpleStrategy | {"replication_factor":"3"}
             system |           True | LocalStrategy  |                       {}
      system_traces |           True | SimpleStrategy | {"replication_factor":"2"}
(5 rows)


Here, the keyspace 'playlist' is created by user, others are system's.


 

> On 09/30/2015 01:50:04 AM EricJ wrote:

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;





References:

 


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