I am trying to extract a particular value from my cassandra database using the Python package cassandra-driver. I have no influence on the data structure.
My Python script
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)
gives the followong output:
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)
What I want to do now is a query of this sort:
rows =session.execute("SELECT * FROM ts_kv_latest_cf WHERE entity_id=UUID('5ee30bf0-2e8b-11e8-a810-c3c1a78797ed')")
This gives me the following error:
cassandra.InvalidRequest: Error from server: code=2200 [Invalid query] message="Invalid number of arguments in call to function system.uuid: 0 required but 1 provided"
It seems like the query calls the system function uuid
. I know that the entity_id
is of the type of uuid
but I have no clue how I could include this in my query using session.execute
.
I used:
Cassandra Version 3.11.2
Python Version 3.6.3
Any ideas are much appreciated! Thanks.
just a moment ago I had a similar problem. You have to change your query to something like this:
rows =session.execute("SELECT * FROM ts_kv_latest_cf WHERE entity_id=5ee30bf0-2e8b-11e8-a810-c3c1a78797ed")
uuid must be given without UUID
before.