开发者

How do I insert a SuperColumn with python/thrift?

开发者 https://www.devze.com 2023-01-24 15:23 出处:网络
Using the python/thrift interface I am trying to 开发者_JS百科insert a SuperColumn just like the Comments example in WTF is a Supercolumn..

Using the python/thrift interface I am trying to 开发者_JS百科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)


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)
0

精彩评论

暂无评论...
验证码 换一张
取 消