cql - cassandra commands notes

9
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:- cqlsh 10.199.240.220 - To connect to Cassandra instance 10.199.240.220 in EC2 Cloud using putty. 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;

Upload: sunil-kumar-gunasekaran

Post on 20-Jan-2015

1.007 views

Category:

Education


7 download

DESCRIPTION

 

TRANSCRIPT

Page 1: CQL - Cassandra commands Notes

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:-

cqlsh 10.199.240.220 - To connect to Cassandra instance 10.199.240.220 in EC2 Cloud using putty.

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;

Page 2: CQL - Cassandra commands Notes

DESCRIBE KEYSPACE:-

Describe keyspace sunil_keyspace; To describe particular keyspace

CREATE TABLE:-

create table users (user_id varchar, 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, ‘[email protected]’,’Dallas’); To insert records to the table

META DATA OF TABLE:-

describe table users; To get meta data info for particular table.

Page 3: CQL - Cassandra commands Notes

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.

Page 4: CQL - Cassandra commands Notes

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.

Page 5: CQL - Cassandra commands Notes

TRUNCATE:

truncate users; 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 found.

Page 6: CQL - Cassandra commands Notes

Sample Facebook Project:-

Create facebook keyspace and use facebook keyspace.

Complete list of CQL Data types:-

Page 7: CQL - Cassandra commands Notes

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.

Page 8: CQL - Cassandra commands Notes

ALTER TABLE AND USAGE OF COLLECTION DATATYPES:-