Python 使用CQLEngine更新UDT集
我是Cassandra的新手,我正在尝试使用CQLEngine ORM来更新包含UDT的集合列,但我不能,而且文档中没有提到任何关于自定义类型的内容 我的代码是Python 使用CQLEngine更新UDT集,python,cassandra,cqlengine,Python,Cassandra,Cqlengine,我是Cassandra的新手,我正在尝试使用CQLEngine ORM来更新包含UDT的集合列,但我不能,而且文档中没有提到任何关于自定义类型的内容 我的代码是 class MyType(UserType): val = columns.Text() point = columns.Integer() key = columns.Text() def __init__(self, val, point, key, **values): supe
class MyType(UserType):
val = columns.Text()
point = columns.Integer()
key = columns.Text()
def __init__(self, val, point, key, **values):
super().__init__(**values)
self.val = val
self.point = point
self.key = key
class MyModel(Model):
myid = columns.UUID(primary_key=True)
set_clm = columns.Set(columns.Integer)
mytype = columns.Set(UserDefinedType(MyType))
def __init__(self, set_clm, mytype, **values):
super().__init__(**values)
self.myid = uuid4()
self.set_clm = set_clm
self.mytype = mytype
s = MyModel.objects(myid="2b3adb7d-9e68-49fc-9aa0-26dbec607f9d").update(
mytype__add=set(MyType(val="1", point=2, key="3"))
)
MyModel最初在集合中保留NULL,但当我尝试更新它时,我得到以下错误:
cassandra.InvalidRequest:来自服务器的错误:code=2200[无效查询]message=“mytype的设置文字无效:值'point'不是冻结类型”
'point'不是冻结类型
->每当我重新运行代码时,此部分会随机更改(下次运行时,“val”列等会出现相同的错误)
谁能帮我添加UDT集吗?好的。我已经解决了。我是为那些在谷歌上找到它的人写的 这是添加到集合的正确方法:
mytype\uu add={mytype(val=“1”,point=2,key=“3”)}
并且还为MyType实现\uuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuu
def __hash__():
return hash(self.__repr__())
但是使用了一个更智能的\uuuuuuuuuuuuuuuuuuuuu
函数。这只是一个例子。希望对其他人有帮助