lab 4: interfacing with cassandra
DESCRIPTION
Cloud Computing Workshop 2013, ITUTRANSCRIPT
![Page 1: Lab 4: Interfacing with Cassandra](https://reader035.vdocument.in/reader035/viewer/2022062306/554fb4f9b4c90586258b53c2/html5/thumbnails/1.jpg)
4: Interfacing with Cassandra
Zubair Nabi
April 20, 2013
Zubair Nabi 4: Interfacing with Cassandra April 20, 2013 1 / 16
![Page 2: Lab 4: Interfacing with Cassandra](https://reader035.vdocument.in/reader035/viewer/2022062306/554fb4f9b4c90586258b53c2/html5/thumbnails/2.jpg)
Introduction1
Project website: http://cassandra.apache.org/
Column based key value store (multi-level dictionary)Consists of keyspaces and column families
I Keyspace: Namespace for column families (typically one perapplication)
I Column family: Contains multiple columns, each of which has a name,value, and timestamp, and which are referenced by row keys
1Disclaimer: Based on the wonderful talk given by Jeremiah Jordan at PyCon 2012Zubair Nabi 4: Interfacing with Cassandra April 20, 2013 2 / 16
![Page 3: Lab 4: Interfacing with Cassandra](https://reader035.vdocument.in/reader035/viewer/2022062306/554fb4f9b4c90586258b53c2/html5/thumbnails/3.jpg)
Introduction1
Project website: http://cassandra.apache.org/
Column based key value store (multi-level dictionary)
Consists of keyspaces and column familiesI Keyspace: Namespace for column families (typically one per
application)I Column family: Contains multiple columns, each of which has a name,
value, and timestamp, and which are referenced by row keys
1Disclaimer: Based on the wonderful talk given by Jeremiah Jordan at PyCon 2012Zubair Nabi 4: Interfacing with Cassandra April 20, 2013 2 / 16
![Page 4: Lab 4: Interfacing with Cassandra](https://reader035.vdocument.in/reader035/viewer/2022062306/554fb4f9b4c90586258b53c2/html5/thumbnails/4.jpg)
Introduction1
Project website: http://cassandra.apache.org/
Column based key value store (multi-level dictionary)Consists of keyspaces and column families
I Keyspace: Namespace for column families (typically one perapplication)
I Column family: Contains multiple columns, each of which has a name,value, and timestamp, and which are referenced by row keys
1Disclaimer: Based on the wonderful talk given by Jeremiah Jordan at PyCon 2012Zubair Nabi 4: Interfacing with Cassandra April 20, 2013 2 / 16
![Page 5: Lab 4: Interfacing with Cassandra](https://reader035.vdocument.in/reader035/viewer/2022062306/554fb4f9b4c90586258b53c2/html5/thumbnails/5.jpg)
Introduction1
Project website: http://cassandra.apache.org/
Column based key value store (multi-level dictionary)Consists of keyspaces and column families
I Keyspace: Namespace for column families (typically one perapplication)
I Column family: Contains multiple columns, each of which has a name,value, and timestamp, and which are referenced by row keys
1Disclaimer: Based on the wonderful talk given by Jeremiah Jordan at PyCon 2012Zubair Nabi 4: Interfacing with Cassandra April 20, 2013 2 / 16
![Page 6: Lab 4: Interfacing with Cassandra](https://reader035.vdocument.in/reader035/viewer/2022062306/554fb4f9b4c90586258b53c2/html5/thumbnails/6.jpg)
Introduction1
Project website: http://cassandra.apache.org/
Column based key value store (multi-level dictionary)Consists of keyspaces and column families
I Keyspace: Namespace for column families (typically one perapplication)
I Column family: Contains multiple columns, each of which has a name,value, and timestamp, and which are referenced by row keys
1Disclaimer: Based on the wonderful talk given by Jeremiah Jordan at PyCon 2012Zubair Nabi 4: Interfacing with Cassandra April 20, 2013 2 / 16
![Page 7: Lab 4: Interfacing with Cassandra](https://reader035.vdocument.in/reader035/viewer/2022062306/554fb4f9b4c90586258b53c2/html5/thumbnails/7.jpg)
Zubair Nabi 4: Interfacing with Cassandra April 20, 2013 3 / 16
![Page 8: Lab 4: Interfacing with Cassandra](https://reader035.vdocument.in/reader035/viewer/2022062306/554fb4f9b4c90586258b53c2/html5/thumbnails/8.jpg)
Zubair Nabi 4: Interfacing with Cassandra April 20, 2013 4 / 16
![Page 9: Lab 4: Interfacing with Cassandra](https://reader035.vdocument.in/reader035/viewer/2022062306/554fb4f9b4c90586258b53c2/html5/thumbnails/9.jpg)
Starting up
Running it: sudo cassandra -f
Running the CLI: cassandra-cli
Zubair Nabi 4: Interfacing with Cassandra April 20, 2013 5 / 16
![Page 10: Lab 4: Interfacing with Cassandra](https://reader035.vdocument.in/reader035/viewer/2022062306/554fb4f9b4c90586258b53c2/html5/thumbnails/10.jpg)
Starting up
Running it: sudo cassandra -f
Running the CLI: cassandra-cli
Zubair Nabi 4: Interfacing with Cassandra April 20, 2013 5 / 16
![Page 11: Lab 4: Interfacing with Cassandra](https://reader035.vdocument.in/reader035/viewer/2022062306/554fb4f9b4c90586258b53c2/html5/thumbnails/11.jpg)
Creating a keyspace
Connecting to the store: connect localhost/9160;
Creating a keyspace: create keyspace ApplicationDatawith placement_strategy =’org.apache.cassandra.locator.SimpleStrategy’and strategy_options =[{replication_factor:1}];
Zubair Nabi 4: Interfacing with Cassandra April 20, 2013 6 / 16
![Page 12: Lab 4: Interfacing with Cassandra](https://reader035.vdocument.in/reader035/viewer/2022062306/554fb4f9b4c90586258b53c2/html5/thumbnails/12.jpg)
Creating a keyspace
Connecting to the store: connect localhost/9160;
Creating a keyspace: create keyspace ApplicationDatawith placement_strategy =’org.apache.cassandra.locator.SimpleStrategy’and strategy_options =[{replication_factor:1}];
Zubair Nabi 4: Interfacing with Cassandra April 20, 2013 6 / 16
![Page 13: Lab 4: Interfacing with Cassandra](https://reader035.vdocument.in/reader035/viewer/2022062306/554fb4f9b4c90586258b53c2/html5/thumbnails/13.jpg)
Creating a column family
Referencing a keyspace: use ApplicationData;
Creating a column family: create column family UserInfoand comparator = ’AsciiType’;
Zubair Nabi 4: Interfacing with Cassandra April 20, 2013 7 / 16
![Page 14: Lab 4: Interfacing with Cassandra](https://reader035.vdocument.in/reader035/viewer/2022062306/554fb4f9b4c90586258b53c2/html5/thumbnails/14.jpg)
Creating a column family
Referencing a keyspace: use ApplicationData;
Creating a column family: create column family UserInfoand comparator = ’AsciiType’;
Zubair Nabi 4: Interfacing with Cassandra April 20, 2013 7 / 16
![Page 15: Lab 4: Interfacing with Cassandra](https://reader035.vdocument.in/reader035/viewer/2022062306/554fb4f9b4c90586258b53c2/html5/thumbnails/15.jpg)
Interfacing with Cassandra in Python
Package: pycassa
Webpage: https://github.com/pycassa/pycassa
Zubair Nabi 4: Interfacing with Cassandra April 20, 2013 8 / 16
![Page 16: Lab 4: Interfacing with Cassandra](https://reader035.vdocument.in/reader035/viewer/2022062306/554fb4f9b4c90586258b53c2/html5/thumbnails/16.jpg)
Interfacing with Cassandra in Python
Package: pycassa
Webpage: https://github.com/pycassa/pycassa
Zubair Nabi 4: Interfacing with Cassandra April 20, 2013 8 / 16
![Page 17: Lab 4: Interfacing with Cassandra](https://reader035.vdocument.in/reader035/viewer/2022062306/554fb4f9b4c90586258b53c2/html5/thumbnails/17.jpg)
Pycassa Basics
1 import pycassa2 from pycassa.pool import ConnectionPool3 from pycassa.columnfamily import ColumnFamily45 pool = ConnectionPool(’ApplicationData’,
6 [’localhost:9160’])
7 col_fam = ColumnFamily(pool, ’UserInfo’)
8 col_fam.insert(’John’, {’email’: ’[email protected]’})
Zubair Nabi 4: Interfacing with Cassandra April 20, 2013 9 / 16
![Page 18: Lab 4: Interfacing with Cassandra](https://reader035.vdocument.in/reader035/viewer/2022062306/554fb4f9b4c90586258b53c2/html5/thumbnails/18.jpg)
Read
1 readData = col_fam.get(’John’,
2 columns=[’email’])
Zubair Nabi 4: Interfacing with Cassandra April 20, 2013 10 / 16
![Page 19: Lab 4: Interfacing with Cassandra](https://reader035.vdocument.in/reader035/viewer/2022062306/554fb4f9b4c90586258b53c2/html5/thumbnails/19.jpg)
Delete
1 col_fam.remove(’John’,
2 columns=[’email’])
Zubair Nabi 4: Interfacing with Cassandra April 20, 2013 11 / 16
![Page 20: Lab 4: Interfacing with Cassandra](https://reader035.vdocument.in/reader035/viewer/2022062306/554fb4f9b4c90586258b53c2/html5/thumbnails/20.jpg)
Batch
1 col_fam.batch_insert(
2 {’John’: {’email’: ’[email protected]’,
3 ’state’: ’IL’,
4 ’gender’: ’M’},
5 ’Jane’: {’email’: ’[email protected]’,
6 ’state’: ’CA’
7 ’gender’: ’M’}})
Zubair Nabi 4: Interfacing with Cassandra April 20, 2013 12 / 16
![Page 21: Lab 4: Interfacing with Cassandra](https://reader035.vdocument.in/reader035/viewer/2022062306/554fb4f9b4c90586258b53c2/html5/thumbnails/21.jpg)
Batch Stream
1 b = col_fam.batch(queue_size=10)
23 b.insert(’John’,
4 {’email’: ’[email protected]’,
5 ’state’: ’IL’,
6 ’gender’: ’M’})
78 b.insert(’Jane’,
9 {’email’: ’[email protected]’,
10 ’state’: ’CA’})
1112 b.remove(’John’, [’gender’])
13 b.remove(’Jane’)
14 b.send()
Zubair Nabi 4: Interfacing with Cassandra April 20, 2013 13 / 16
![Page 22: Lab 4: Interfacing with Cassandra](https://reader035.vdocument.in/reader035/viewer/2022062306/554fb4f9b4c90586258b53c2/html5/thumbnails/22.jpg)
Batch Read
1 readData = col_fam.multiget([’John’, ’Jane’, ’Bill’])
Zubair Nabi 4: Interfacing with Cassandra April 20, 2013 14 / 16
![Page 23: Lab 4: Interfacing with Cassandra](https://reader035.vdocument.in/reader035/viewer/2022062306/554fb4f9b4c90586258b53c2/html5/thumbnails/23.jpg)
Column Slice
1 d = col_fam.get(’Jane’,
2 column_start=’email’,
3 column_finish=’state’)
Zubair Nabi 4: Interfacing with Cassandra April 20, 2013 15 / 16
![Page 24: Lab 4: Interfacing with Cassandra](https://reader035.vdocument.in/reader035/viewer/2022062306/554fb4f9b4c90586258b53c2/html5/thumbnails/24.jpg)
Reference(s)
Apache Cassandra and Python:https://pycon-2012-notes.readthedocs.org/en/latest/apache_cassandra_and_python.html
Zubair Nabi 4: Interfacing with Cassandra April 20, 2013 16 / 16