forked from onecompiler/tutorials
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4c0c029
commit 6dcf960
Showing
190 changed files
with
7,387 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
CQL also provides collection data types. Following list provides different data types available in cassandra. | ||
|
||
1. List - Collection of one or more ordered elements. | ||
1. map - Collection of key-value pairs. | ||
1. set - Collection of one or more elments. | ||
|
||
### List | ||
List is used to maintain the order of elements allowing duplicates. | ||
|
||
* Creating a Table with List | ||
```sh | ||
CREATE TABLE employee(id int PRIMARY KEY, name text, email list<text>); | ||
``` | ||
|
||
* Inserting Data into List | ||
```sh | ||
INSERT INTO employee(id, name, email) VALUES (1, 'john', | ||
['[email protected]','[email protected]']) | ||
``` | ||
* Updating a List | ||
```sh | ||
UPDATE employee SET email = email +['[email protected]'] | ||
WHERE name = 'john'; | ||
``` | ||
|
||
### SET | ||
SET is used to store group of data and the elements will be returned in sorted order. | ||
|
||
* Creating a Table with Set | ||
```sh | ||
CREATE TABLE employee2(id int PRIMARY KEY, name text, mobile set<varint>); | ||
``` | ||
|
||
* Inserting Data into Set | ||
```sh | ||
INSERT INTO employee2(id, name, mobile) VALUES (1, 'kevin', | ||
{9999911122, 9998855664}) | ||
``` | ||
* Updating a List | ||
```sh | ||
UPDATE employee2 SET mobile = mobile +{9898989898} | ||
WHERE name = 'kevin'; | ||
``` | ||
|
||
|
||
### MAP | ||
Map is used to store key-value pair of elements. | ||
|
||
* Creating a Table with Map | ||
```sh | ||
CREATE TABLE employee3(id int PRIMARY KEY, name text, address map<text, text>); | ||
``` | ||
|
||
* Inserting Data into Map | ||
```sh | ||
INSERT INTO employee3(id, name, address) VALUES (1, 'smith', | ||
{'home':'san jose','work':'chicago'}) | ||
``` | ||
* Updating a Map | ||
```sh | ||
UPDATE employee3 SET address = address +{'permanent':'New york'} | ||
WHERE name = 'smith'; | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
INSERT command is used to insert data into columns of the table. | ||
|
||
Syntax | ||
|
||
```sh | ||
INSERT INTO <tablename> | ||
(<column1 name>, <column2 name>....) | ||
VALUES (<value1>, <value2>....) | ||
USING <option> | ||
``` | ||
|
||
|
||
Example : | ||
```sh | ||
INSERT INTO student (id, name, city) | ||
VALUES(1, 'Paul', 'Texas'); | ||
INSERT INTO student (id, name, city) | ||
VALUES(2, 'John', 'New York'); | ||
INSERT INTO student (id, name, city) | ||
VALUES(1, 'Max', 'New Jersey'); | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
A keyspace is RDBMS database which contains tables, columns and data. | ||
|
||
### Syntax | ||
```sh | ||
CREATE KEYSPACE <identifier> WITH <properties> | ||
``` | ||
|
||
```sh | ||
Create keyspace KeyspaceName with replicaton={'class':strategy name, | ||
'replication_factor': No of replications on different nodes} | ||
``` | ||
|
||
### Strategy, Replication Factor | ||
|
||
There are two types of strategy declarations. | ||
|
||
* Simple Strategy - It is used in case of single data center. This is not a wise choice for production, it may lead to latency. | ||
* NetworkTopologyStrategy - It is used in case of more data centers. Replication factor is provided for each data center separately. | ||
|
||
Replication Factor- Replication factor is the number of replicas of data placed on different nodes. Atleast 3 replication factor is required to attain no single point of failure. | ||
|
||
Example | ||
|
||
```sh | ||
CREATE KEYSPACE whichdb | ||
WITH replication = {'class':'SimpleStrategy', 'replication_factor' : 3}; | ||
``` | ||
|
||
|
||
DESCRIBE Keyword is used to display all the keyspaces created. | ||
```sh | ||
DESCRIBE keyspaces | ||
|
||
system_schema system system_traces | ||
system_auth system_distributed whichdb | ||
``` | ||
|
||
USE keyword is used to use the keyspace | ||
```sh | ||
USE whichdb | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
CREATE command is used to create a table. Here column family is used to store data just like tables in RDBMS. | ||
|
||
Syntax | ||
|
||
```sh | ||
CREATE (TABLE | COLUMNFAMILY) <tablename> | ||
('<column-definition>' , '<column-definition>') | ||
(WITH <option> AND <option>) | ||
``` | ||
|
||
or | ||
|
||
```sh | ||
CREATE TABLE tablename( | ||
column1 name datatype PRIMARYKEY, | ||
column2 name data type, | ||
column3 name data type. | ||
) | ||
|
||
``` | ||
|
||
Example : | ||
```sh | ||
CREATE TABLE student( | ||
id int PRIMARY KEY, | ||
name text, | ||
city text, | ||
mobile varint | ||
); | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
DELETE command is used to delete data from cassandra table, You can delete complete table or particular data based on condition | ||
|
||
```sh | ||
DELETE FROM <identifier> WHERE <condition>; | ||
``` | ||
|
||
### Deleting an Entire Table | ||
```sh | ||
DELETE FROM student; | ||
``` | ||
|
||
### Deleting an Particular Data based on condition | ||
WHERE clause is specified. | ||
```sh | ||
DELETE FROM student where id = 3; | ||
``` | ||
|
||
### Deleting an specific column name | ||
```sh | ||
DELETE city FROM student WHERE id=4; | ||
``` | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
Drop command is used to drop keyspaces with all the data, columns and indexes from cassandra | ||
|
||
```sh | ||
DROP keyspace whichdb | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
## Reading whole table from a keyspace | ||
SELECT is used to read data from cassandra table. | ||
|
||
```sh | ||
SELECT FROM <tablename> | ||
|
||
SELECT * FROM student; | ||
``` | ||
|
||
## Reading Particular columns in a table | ||
Required columns are specified instead of *. | ||
```sh | ||
SELECT id, name, city FROM student; | ||
``` | ||
|
||
## Reading data from table based on condition | ||
WHERE clause is used to return a data based on given condition | ||
|
||
```sh | ||
SELECT * FROM student WHERE id=2; | ||
``` | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
UPDATE command is used to update the data in table. Where clause can used to update rows based on condition. | ||
|
||
|
||
Syntax | ||
```sh | ||
UPDATE <TABLE> | ||
SET <COLUMN> = <VALUE> | ||
<COLUMN> = <value>.... | ||
WHERE <condition> | ||
``` | ||
|
||
## Update multiple values | ||
```sh | ||
UPDATE <TABLE> | ||
SET <COLUMN1> = <VALUE1>, | ||
SET <COLUMN2> = <VALUE2> | ||
<COLUMN> = <value>.... | ||
WHERE <condition> | ||
``` | ||
|
||
|
||
### Example | ||
|
||
```sh | ||
UPDATE student SET city='New York',name='Rahul' | ||
WHERE id=2; | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
[ | ||
{ | ||
"title": "Introduction", | ||
"path": "introduction", | ||
"links": [ | ||
{ | ||
"title": "What is Cassandra", | ||
"path": "what-is-cassandra" | ||
}, | ||
{ | ||
"title": "Key Concepts", | ||
"path": "key-concepts" | ||
}, | ||
{ | ||
"title": "Installation", | ||
"path": "installation" | ||
} | ||
] | ||
}, | ||
{ | ||
"title": "CRUD Operations", | ||
"path": "crud-operations", | ||
"links": [ | ||
{ | ||
"title": "Creating Keyspace", | ||
"path": "creating-keyspace" | ||
}, | ||
{ | ||
"title": "Deleting Keyspace", | ||
"path": "deleting-keyspace" | ||
}, | ||
{ | ||
"title": "Creating Table", | ||
"path": "creating-table" | ||
}, | ||
{ | ||
"title": "Inserting Data", | ||
"path": "creating-data" | ||
}, | ||
{ | ||
"title": "Updating Data", | ||
"path": "updating-data" | ||
}, | ||
{ | ||
"title": "Deleting Data", | ||
"path": "deleting-data" | ||
} | ||
] | ||
}, | ||
{ | ||
"title": "Advanced Topics", | ||
"path": "advanced", | ||
"links": [ | ||
{ | ||
"title": "Collection Data types", | ||
"path": "collection-data-types" | ||
} | ||
] | ||
} | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
## Installing on MacOS | ||
|
||
Easiest way to get Cassandra installed on MacOS is via Homebrew. You can run the following command to install Cassandra in MacOS | ||
```sh | ||
brew install cassandra | ||
``` | ||
|
||
## Installing on Windows | ||
|
||
We can download the latest version of cassandra from the following website | ||
http://cassandra.apache.org/download/ | ||
|
||
Run the installation and open cassandra | ||
|
||
### Installing Fron Debian Packages | ||
```sh | ||
echo "deb http://www.apache.org/dist/cassandra/debian 311x main" | sudo tee -a /etc/apt/sources.list.d/cassandra.sources.list | ||
sudo apt-get update | ||
sudo apt-get install cassandra | ||
``` | ||
|
||
### Installing Fron RPM Packages | ||
```sh | ||
[cassandra] | ||
name=Apache Cassandra | ||
baseurl=https://www.apache.org/dist/cassandra/redhat/311x/ | ||
gpgcheck=1 | ||
repo_gpgcheck=1 | ||
gpgkey=https://www.apache.org/dist/cassandra/KEYS | ||
|
||
sudo yum install cassandra | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
## Cassandra Query Language | ||
Cassandra Query Language (CQL) is used to access Cassandra database through queries. CQL Treats Database as keyspaces as a container of tables. | ||
|
||
## Terms Related to Cassandra | ||
* Node - Node is place where data is stored. | ||
* Data Center - Data center is a collection of related nodes. | ||
* Cluster - Cluster is component containing one or more data centers. | ||
* Commit log - This is a crash recovery mechanism, every write operation is written into the log. | ||
|
||
## Data Replication in Cassandra | ||
In cassandra nodes in a cluster acts as replicas for a given piece of data. If a node responds with out-of-date value, Cassandra will return the recent value and performs a repair in the background to repair the old value. | ||
|
||
## Keyspace, Table, Data | ||
Cassandra provides keyspaces(Database) which contains multiple tables. Tables contain data | ||
|
||
## Cassandra CQLsh | ||
Cassandra CQL shell is utility to interact with Cassandra using CQL Queries. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Cassandra is a free and open-source, distributed NoSQL database management system. It is provided by Apache. It is designed to handle huge amount of data providing high performance, high scalability across servers without any failure. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
CouchDB curl utility provides PUT method to insert data/document into couchdb database. | ||
|
||
Syntax : | ||
```sh | ||
curl -X PUT http://127.0.0.1:5984/<database>/"id" -d ' { document } ' | ||
``` | ||
Example : | ||
```sh | ||
curl -X PUT \ | ||
http://127.0.0.1:5984/employee/1 \ | ||
-H 'Content-Type: application/json' \ | ||
-d '{ | ||
"name": "John", | ||
"city": "New york", | ||
"mobile": 9921829381 | ||
}' | ||
|
||
{ | ||
"ok": true, | ||
"id": "1", | ||
"rev": "1-fef96a337fdc6197293y41fs64a4d2ea" | ||
} | ||
``` | ||
Document id, datbase name needs to be specified in curl request. | ||
|
||
Document can be displayed in the following manner. | ||
|
||
```sh | ||
curl -X GET http://127.0.0.1:5984/employee/1 | ||
|
||
{ | ||
"_id": "1", | ||
"rev": "1-fef96a337fdc6197293y41fs64a4d2ea", | ||
"name": "John", | ||
"city": "New york", | ||
"mobile": 9921829381 | ||
} | ||
``` | ||
|
Oops, something went wrong.