Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

NoSQL com Cassandra e Python

4,277 views

Published on

Published in: Technology
  • Login to see the comments

NoSQL com Cassandra e Python

  1. 1. NoSQL com Python Gustavo Pinto @gustavopinto
  2. 2. gustavopinto2004 - belém, grad, php2006 - amazontic, java, rails2008 - curitiba, msc, python2009 - aprioriti, xp, scrum2011 - 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 porpartes..
  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. ThriftIdiomatic low level API
  31. 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. 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. 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. 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. pycassaHigh level API
  37. 37. Instalação1. easy_install pycassa
  38. 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. 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. 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. 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. 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. 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. 44. Para saber maishttps://bitly.com/bundles/gustavopinto/2
  45. 45. Para saber mais

×