Cassandra Tutorials – Working in EC2 Cloud:Putty Details:Host name: dev-use1b-pr-33-huginn-dev-0002.prv-openclass.com
IP of Cassandra Instance:10.199.240.220
CONNECT TO CASSANDRA INSTANCE:-
- To connect to Cassandra instance 10.199.240.220 in EC2 Cloud
LIST OF ALL KEYSPACES: Select * from system.system.schema_keyspaces;To get info of all existing keyspaces.
Here system is a reserve Cassandra keyspace.
WORK IN KEYSPACE: USE sunil_keyspace; To use particular keyspace;
DESCRIBE KEYSPACE: Describe keyspacesunil_keyspace; To describe particular keyspace
CREATE TABLE: create table users (user_idvarchar, age int, email varchar, city varchar, PRIMARY KEY (user_id));
INSERT RECORDS IN TABLE: insert into users (user_id, age, email, city) values (‘jsmith’, 32,
‘firstname.lastname@example.org’,’Dallas’); To insert records to the table
META DATA OF TABLE: describe table users; To get meta data info for particular table.
RECORDS OF TABLE: select * from users; To retrieve records from particular table.
STRUCTURE OF USERS TABLE:Key Concept:Below is representation of how users table is stored in Cassandra database. KEyspace is
container and Table has each rows associated with a primary key. Important point is that a row may
contain varied columns as shown in picture.
DELETE RECORDS OR PARTICULAR COLUMN: delete email from users where user_id=’sunilk’; This deletes email column from sunilk row in
users table. We can see that they appear as null.
select from users where user_id=’sunilk’; Deletes entire row.
truncateusers; To delete all records of particular table. But meta data of table is still present.
DROP TABLE AND KEYSPACE:
drop table users; To delete both records and meta data. No trace of meta data nor records is
Sample Facebook Project: Create facebookkeyspace and use facebookkeyspace.
Complete list of CQL Data types:-
Create UserProfiles table with following records or rows as seen below.
Updating record of Angela Thomas setting age to 20 and profile picture to 0x5d1b.
For retrieving particular row of table.
INDEXES:For non-indexed columns, no output is returned on query. Below is indexing command.
ALTER TABLE AND USAGE OF COLLECTION DATATYPES:-