Successfully reported this slideshow.
Your SlideShare is downloading. ×

NoSQL com Cassandra e Python

Ad
Ad
Ad
Ad
Ad
Ad
Ad
Ad
Ad
Ad
Ad
Upcoming SlideShare
gemdiff
gemdiff
Loading in …3
×

Check these out next

1 of 62 Ad

More Related Content

Slideshows for you (20)

Viewers also liked (20)

Advertisement

Similar to NoSQL com Cassandra e Python (20)

Advertisement

Recently uploaded (20)

NoSQL com Cassandra e Python

  1. 1. NoSQL com Python Gustavo Pinto @gustavopinto
  2. 2. gustavopinto 2004 - belém, grad, php 2006 - amazontic, java, rails 2008 - curitiba, msc, python 2009 - aprioriti, xp, scrum 2011 - recife, phd
  3. 3. novo século novos problemas
  4. 4. O que você usaria?
  5. 5. O que você usaria?
  6. 6. NoSQL
  7. 7. Hash table + Distributed
  8. 8. Vamos por partes..
  9. 9. Estrutura de dados
  10. 10. Desnormalização JOIN
  11. 11. eventualmente consistente Replication Factor = 3
  12. 12. tolerante a falhas
  13. 13. BASE ACID ● Basically ● Atomic ● Available ● Consistent ● Soft State ● Isolated ● Eventually ● Durable Consistent
  14. 14. ferramentas
  15. 15. Banco de dados distribuido, tolerante a falhas, escalável, orientado a colunas
  16. 16. x ... em 50 GB de dados
  17. 17. Intalação ● download cassanda-xxx.tar.gz ● cd cassandra/bin/ ● ./cassandra
  18. 18. Intalação ● download cassanda-xxx.tar.gz ● cd cassandra/bin/ ● ./cassandra
  19. 19. Intalação ● download cassanda-xxx.tar.gz ● cd cassandra/bin/ ● ./cassandra ● ./cassandra-cli -h localhost -p 9160
  20. 20. show keyspaces;
  21. 21. create keyspace pugpe; use pugpe;
  22. 22. create column family encontroxvi with comparator = UTF8Type;
  23. 23. set encontroxvi['08:30~09:00']['Titulo'] = 'Apresentacao'; set encontroxvi['08:30~09:00']['Palestrante'] = 'Marcel';
  24. 24. set encontroxvi['08:30~09:00']['Titulo'] = 'Apresentacao'; set encontroxvi['08:30~09:00']['Palestrante'] = 'Marcel';
  25. 25. set encontroxvi['08:30~09:00']['Titulo'] = 'Apresentacao'; set encontroxvi['08:30~09:00']['Palestrante'] = 'Marcel';
  26. 26. set encontroxvi['08:30~09:00']['Titulo'] = 'Apresentacao'; set encontroxvi['08:30~09:00']['Palestrante'] = 'Marcel';
  27. 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. 28. get encontroxvi['08:30~09:00'];
  29. 29. get encontroxvi['08:30~09:00'];
  30. 30. Thrift Idiomatic low level API
  31. 31. Instalação 1. Download thrift-0.2.0-incubating.tar.gz 2. Instale as dependências (apt-get install ..) 3. ./configure (se tudo der certo) 4. make (se tudo der certo..) 5. make install
  32. 32. Instalação 1. Download thrift-0.2.0-incubating.tar.gz 2. Instale as dependências (apt-get install ..) 3. ./configure (se tudo der certo) 4. make (se tudo der certo..) 5. make install
  33. 33. from thrift import Thrift from thrift.transport import TTransport from thrift.transport import TSocket from thrift.transport import THttpClient from thrift.protocol import TBinaryProtocol from cassandra import Cassandra from cassandra.ttypes import * import time socket = TSocket.TSocket("localhost", 9160) transport = TTransport.TBufferedTransport(socket) protocol = TBinaryProtocol.TBinaryProtocol(transport) client = Cassandra.Client(protocol)
  34. 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. 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. 36. pycassa High level API
  37. 37. Instalação 1. easy_install pycassa
  38. 38. import pycassa pool = 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. 39. import pycassa pool = 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. 40. import pycassa pool = 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. 41. import pycassa pool = 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. 42. import pycassa pool = 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. 43. import pycassa pool = 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. 44. Para saber mais https://bitly.com/bundles/gustavopinto/2
  45. 45. Para saber mais

×