如何使用python/thrift插入超级列?

2024-04-19 22:35:16 发布

您现在位置:Python中文网/ 问答频道 /正文

使用python/thrift接口,我试图插入一个超级列,就像WTF is a Supercolumn..中的注释示例一样

我已经创建了超级列,并发现应该使用batch mutate来插入它。但我不知道如何创建突变,以及如何设置键和超级列类型

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)

Tags: nametimeisvaluebatchcolumnthrifttimestamp
1条回答
网友
1楼 · 发布于 2024-04-19 22:35:16

我会用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)

相关问题 更多 >