如何使用python / thrift插入SuperColumn?

时间:2010-11-10 15:05:12

标签: python cassandra thrift

使用python / thrift接口我试图像WTF is a Supercolumn..中的评论示例一样插入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)

1 个答案:

答案 0 :(得分: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)