【发布时间】:2018-03-23 13:47:27
【问题描述】:
我正在尝试使用 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:来自服务器的错误:code=2200 [Invalid query] message="调用函数 system.uuid 的参数数量无效:需要 0,但提供了 1"
查询似乎调用了系统函数uuid。我知道entity_id 属于uuid 类型,但我不知道如何使用session.execute 将其包含在我的查询中。
我用过:
Cassandra 版本 3.11.2
Python 版本 3.6.3
非常感谢任何想法!谢谢。
【问题讨论】:
标签: python thingsboard cassandra-driver