0

Using the python/thrift interface I am trying to insert a SuperColumn just like the Comments example in WTF is a Supercolumn..

I've gotten as far as to create the SuperColumn and figured out that I should use batch_mutate to insert it. But I don't know how to create the Mutation and set the key and SuperColumn type

keyspace = "Keyspace1"

col1 = Column(name = "commenter", value = "J Doe", timestamp = time.time())
col2 = Column(name = "email", value = "jdoe@example.com", timestamp = time.time())

sc = SuperColumn(name = str(uuid.uuidl()), [col1, col2])

# i am guessing the missing code goes here

mutation = Mutation(column_or_supercolumn = sc?)
client.batch_mutate(keyspace, mutation, ConsistencyLevel.ZERO)
NA.
  • 6,451
  • 9
  • 36
  • 36

1 Answers1

0

I would use pycassa or something to make life easier, but something like:

keyspace = "Keyspace1"
tableName = "Super1"
key = "jdoe"
col1 = Column(name = "commenter", value = "J Doe", timestamp = time.time())
col2 = Column(name = "email", value = "jdoe@example.com", timestamp = time.time())

newData = [Mutation(ColumnOrSuperColumn(None,
                             SuperColumn(str(uuid.uuidl()),
                                        [col1, col2])))]
dataMap = {key : {tableName : newData}}

client.batch_mutate(keyspace=keyspace,
                    mutation_map=dataMap,
                    consistency_level=ConsistencyLevel.ZERO)
Zanson
  • 3,991
  • 25
  • 31