0

使用 python/thrift 接口我试图插入一个 SuperColumn 就像WTF 中的 Comments 示例是一个 Supercolumn..

我已经创建了 SuperColumn 并发现我应该使用 batch_mutate 来插入它。但我不知道如何创建 Mutation 并设置密钥和 SuperColumn 类型

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

1 回答 1

0

我会使用 pycassa 或其他东西让生活更轻松,但类似:

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)
于 2010-11-10T17:19:40.273 回答