![](/img/trans.png)
[英]Python cassandra-driver OperationTimeOut on every query in Celery task
[英]Cannot query for particular UUID with Python cassandra-driver
我正在尝试使用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)
给出followong输出:
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 [Invalid query] message =“在对函数system.uuid的调用中无效的参数数量:必需0,但提供1”
查询似乎调用了系统函数uuid
。 我知道entity_id
是uuid
的类型,但是我不知道如何使用session.execute
将其包含在查询中。
我用了:
Cassandra版本3.11.2
Python版本3.6.3
任何想法都非常感谢! 谢谢。
刚才我有一个类似的问题。 您必须将查询更改为以下内容:
rows =session.execute("SELECT * FROM ts_kv_latest_cf WHERE entity_id=5ee30bf0-2e8b-11e8-a810-c3c1a78797ed")
必须先提供uuid而不使用UUID
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.