我正在尝试使用 Python 包 cassandra-driver 从我的 cassandra 数据库中提取特定值。我对数据结构没有影响。
我的 Python 脚本
from cassandra.cluster import Cluster
cluster =Cluster()
session =cluster.connect('thingsboard')
rows =session.execute("SELECT * FROM ts_kv_latest_cf")
for id_row in rows:
print (id_row)
给出以下输出:
Row(entity_type='DEVICE', entity_id=UUID('5ee30bf0-2e8b-11e8-a810-c3c1a78797ed'), key='count-cola', bool_v=None, dbl_v=None, long_v=0, str_v=None, ts=1521808687455)
Row(entity_type='DEVICE', entity_id=UUID('5ee30bf0-2e8b-11e8-a810-c3c1a78797ed'), key='count-fanta', bool_v=None, dbl_v=None, long_v=0, str_v=None, ts=1521808687455)
Row(entity_type='DEVICE', entity_id=UUID('5ee30bf0-2e8b-11e8-a810-c3c1a78797ed'), key='count-sprite', bool_v=None, dbl_v=None, long_v=0, str_v=None, ts=1521808687455)
Row(entity_type='DEVICE', entity_id=UUID('477b5630-2e8a-11e8-a810-c3c1a78797ed'), key='count-cola', bool_v=None, dbl_v=None, long_v=0, str_v=None, ts=1521803445966)
Row(entity_type='DEVICE', entity_id=UUID('477b5630-2e8a-11e8-a810-c3c1a78797ed'), key='count-fanta', bool_v=None, dbl_v=None, long_v=0, str_v=None, ts=1521803445966)
Row(entity_type='DEVICE', entity_id=UUID('477b5630-2e8a-11e8-a810-c3c1a78797ed'), key='count-sprite', bool_v=None, dbl_v=None, long_v=0, str_v=None, ts=1521803445966)
我现在要做的是这样的查询:
rows =session.execute("SELECT * FROM ts_kv_latest_cf WHERE entity_id=UUID('5ee30bf0-2e8b-11e8-a810-c3c1a78797ed')")
这给了我以下错误:
cassandra.InvalidRequest:来自服务器的错误:代码 = 2200 [无效查询] 消息 =“对函数 system.uuid 的调用中的参数数量无效:需要 0,但提供了 1”
查询似乎调用了系统函数uuid
。我知道entity_id
是 的类型,uuid
但我不知道如何在我的查询中使用session.execute
.
我用了:
卡桑德拉版本 3.11.2
Python 版本 3.6.3
任何想法都非常感谢!谢谢。