Your SlideShare is downloading. ×
NoSQL com Cassandra e Python
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

NoSQL com Cassandra e Python

3,053
views

Published on

Published in: Technology

0 Comments
4 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
3,053
On Slideshare
0
From Embeds
0
Number of Embeds
2
Actions
Shares
0
Downloads
32
Comments
0
Likes
4
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. NoSQL com Python Gustavo Pinto @gustavopinto
  • 2. gustavopinto2004 - belém, grad, php2006 - amazontic, java, rails2008 - curitiba, msc, python2009 - aprioriti, xp, scrum2011 - recife, phd
  • 3. novo século novos problemas
  • 4. O que você usaria?
  • 5. O que você usaria?
  • 6. NoSQL
  • 7. Hash table +Distributed
  • 8. Vamos porpartes..
  • 9. Estrutura de dados
  • 10. Desnormalização JOIN
  • 11. eventualmente consistente Replication Factor = 3
  • 12. tolerante a falhas
  • 13. BASE ACID● Basically ● Atomic● Available ● Consistent● Soft State ● Isolated● Eventually ● Durable Consistent
  • 14. ferramentas
  • 15. Banco de dados distribuido,tolerante a falhas, escalável, orientado a colunas
  • 16. x... em 50 GB de dados
  • 17. Intalação● download cassanda-xxx.tar.gz● cd cassandra/bin/● ./cassandra
  • 18. Intalação● download cassanda-xxx.tar.gz● cd cassandra/bin/● ./cassandra
  • 19. Intalação● download cassanda-xxx.tar.gz● cd cassandra/bin/● ./cassandra● ./cassandra-cli -h localhost -p 9160
  • 20. show keyspaces;
  • 21. create keyspace pugpe;use pugpe;
  • 22. create column family encontroxvi with comparator = UTF8Type;
  • 23. set encontroxvi[08:30~09:00][Titulo] = Apresentacao;set encontroxvi[08:30~09:00][Palestrante] = Marcel;
  • 24. set encontroxvi[08:30~09:00][Titulo] = Apresentacao;set encontroxvi[08:30~09:00][Palestrante] = Marcel;
  • 25. set encontroxvi[08:30~09:00][Titulo] = Apresentacao;set encontroxvi[08:30~09:00][Palestrante] = Marcel;
  • 26. set encontroxvi[08:30~09:00][Titulo] = Apresentacao;set encontroxvi[08:30~09:00][Palestrante] = Marcel;
  • 27. set encontroxvi[08:30~09:00][Titulo] = Apresentacao;set encontroxvi[08:30~09:00][Palestrante] = Marcel;set encontroxvi[09:00~09:40][Titulo] = noSQL;set encontroxvi[09:00~09:40][Palestrante] = Gustavo;set encontroxvi[09:00~09:40][Slide] = bit.ly/jhae1;
  • 28. get encontroxvi[08:30~09:00];
  • 29. get encontroxvi[08:30~09:00];
  • 30. ThriftIdiomatic low level API
  • 31. Instalação1. Download thrift-0.2.0-incubating.tar.gz2. Instale as dependências (apt-get install ..)3. ./configure (se tudo der certo)4. make (se tudo der certo..)5. make install
  • 32. Instalação1. Download thrift-0.2.0-incubating.tar.gz2. Instale as dependências (apt-get install ..)3. ./configure (se tudo der certo)4. make (se tudo der certo..)5. make install
  • 33. from thrift import Thriftfrom thrift.transport import TTransportfrom thrift.transport import TSocketfrom thrift.transport import THttpClientfrom thrift.protocol import TBinaryProtocolfrom cassandra import Cassandrafrom cassandra.ttypes import *import timesocket = TSocket.TSocket("localhost", 9160)transport = TTransport.TBufferedTransport(socket)protocol = TBinaryProtocol.TBinaryProtocol(transport)client = Cassandra.Client(protocol)
  • 34. keyspace = "pugpe"column_path = ColumnPath(column_family="encontroxvi",column="palestrante")key = "08:30~09:00"value = "Gustavo Pinto"timestamp = time.time()try:transport.open() # ...client.insert(keyspace,key, column_path, value,timestamp,ConsistencyLevel.ZERO) # ....
  • 35. column_parent = ColumnParent(column_family="encontroxvi") slice_range = SliceRange(start="", finish="") predicate = SlicePredicate(slice_range=slice_range) result = client.get_slice(keyspace, key,column_parent, predicate, ConsistencyLevel.ONE) # ...
  • 36. pycassaHigh level API
  • 37. Instalação1. easy_install pycassa
  • 38. import pycassapool = pycassa.ConnectionPool("pugpe")cf = pycassa.ColumnFamily(pool, "encontroxvi")cf.insert(08:30~09:00, {palestrante : marcel, palestra :abertura})cf.insert(09:00~09:40, {palestrante : gustavopinto, palestra: nosql, slide : bit.ly/...})cf.get(08:30~09:00)cf.multiget([08:30~09:00, 09:00~09:40])cf.get_count(09:00~09:40)cf.remove(09:00~09:40)
  • 39. import pycassapool = pycassa.ConnectionPool("pugpe")cf = pycassa.ColumnFamily(pool, "encontroxvi")cf.insert(08:30~09:00, {palestrante : marcel, palestra :abertura})cf.insert(09:00~09:40, {palestrante : gustavopinto, palestra: nosql, slide : bit.ly/...})cf.get(08:30~09:00)cf.multiget([08:30~09:00, 09:00~09:40])cf.get_count(09:00~09:40)cf.remove(09:00~09:40)
  • 40. import pycassapool = pycassa.ConnectionPool("pugpe")cf = pycassa.ColumnFamily(pool, "encontroxvi")cf.insert(08:30~09:00, {palestrante : marcel, palestra :abertura})cf.insert(09:00~09:40, {palestrante : gustavopinto, palestra: nosql, slide : bit.ly/...})cf.get(08:30~09:00)cf.multiget([08:30~09:00, 09:00~09:40])cf.get_count(09:00~09:40)cf.remove(09:00~09:40)
  • 41. import pycassapool = pycassa.ConnectionPool("pugpe")cf = pycassa.ColumnFamily(pool, "encontroxvi")cf.insert(08:30~09:00, {palestrante : marcel, palestra :abertura})cf.insert(09:00~09:40, {palestrante : gustavopinto,palestra : nosql, slide : bit.ly/...})cf.get(08:30~09:00)cf.multiget([08:30~09:00, 09:00~09:40])cf.get_count(09:00~09:40)cf.remove(09:00~09:40)
  • 42. import pycassapool = pycassa.ConnectionPool("pugpe")cf = pycassa.ColumnFamily(pool, "encontroxvi")cf.insert(08:30~09:00, {palestrante : marcel, palestra :abertura})cf.insert(09:00~09:40, {palestrante : gustavopinto, palestra: nosql, slide : bit.ly/...})cf.get(08:30~09:00)cf.multiget([08:30~09:00, 09:00~09:40])cf.get_count(09:00~09:40)cf.remove(09:00~09:40)
  • 43. import pycassapool = pycassa.ConnectionPool("pugpe")cf = pycassa.ColumnFamily(pool, "encontroxvi")cf.insert(08:30~09:00, {palestrante : marcel, palestra :abertura})cf.insert(09:00~09:40, {palestrante : gustavopinto, palestra: nosql, slide : bit.ly/...})cf.get(08:30~09:00)cf.multiget([08:30~09:00, 09:00~09:40])cf.get_count(09:00~09:40)cf.remove(09:00~09:40)
  • 44. Para saber maishttps://bitly.com/bundles/gustavopinto/2
  • 45. Para saber mais