Reputation: 2836
When connecting to cassandra via pythons csh module and trying to run a simple select query I seem to get a boolean value returned rather than the query results. When I go onto the cassandra box and open the cqlsh shell and directly query cassandra I get results:
$ ./cqlsh
Connected to stg_sal_cluster at localhost:9160.
[cqlsh 4.1.1 | Cassandra 2.0.17.858 | DSE 4.6.11 | CQL spec 3.1.1 | Thrift protocol 19.39.0]
Use HELP for help.
cqlsh> use "SAL";
cqlsh:SAL> select * from sal_metadata where key='972cca8691c0804f685702d4a307b44f60cc59254094c903354f55779344bd94';
key | column1 | value
------------------------------------------------------------------+--------------------------------------------------------------------------+----------------------------------------------------------------------
972cca8691c0804f685702d4a307b44f60cc59254094c903354f55779344bd94 | Alternate|THUMBNAIL_MEDIUM_RESULT:true|h:320|mt:image/jpeg|s:19477|w:320 | sal:5797d15fe18e5d58a74c927d342142f998ea084359f6a789f1cb2ba924231d95
972cca8691c0804f685702d4a307b44f60cc59254094c903354f55779344bd94 | CI_COMPLETE | true
972cca8691c0804f685702d4a307b44f60cc59254094c903354f55779344bd94 | Capture-Date | 2008-11-08T06:13:02.000Z
972cca8691c0804f685702d4a307b44f60cc59254094c903354f55779344bd94 | ContentPermissions | SHARE
972cca8691c0804f685702d4a307b44f60cc59254094c903354f55779344bd94 | Height | 2112
972cca8691c0804f685702d4a307b44f60cc59254094c903354f55779344bd94 | Mime-Type | image/jpeg
972cca8691c0804f685702d4a307b44f60cc59254094c903354f55779344bd94 | Width | 2816
972cca8691c0804f685702d4a307b44f60cc59254094c903354f55779344bd94 | sal.loc | /opt/newbay/storage/sal/tank3
972cca8691c0804f685702d4a307b44f60cc59254094c903354f55779344bd94 | sal.size | 1385855
(9 rows)
cqlsh:SAL>
However when I try the above from a remote python shell I get the boolean value 'True' returned.
>>> import cql
>>> con=cql.connect('10.10.10.10', 9160, 'SAL')
>>> cursor = con.cursor()
>>> CQLString = "select * from sal_metadata where key='972cca8691c0804f685702d4a307b44f60cc59254094c903354f55779344bd94';"
>>> res=cursor.execute(CQLString)
>>> res.fetch()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'bool' object has no attribute 'fetch'
>>> res
True
>>>
Everywhere I look this seems to return the query results so what am I missing?
A
Upvotes: 0
Views: 760
Reputation: 12830
You need to iterate through the resultset
Here is the simplest Example :
from cassandra.cluster import Cluster
cluster = Cluster(['10.10.10.10'])
session = cluster.connect('SAL')
CQLString = "select * from sal_metadata where key='972cca8691c0804f685702d4a307b44f60cc59254094c903354f55779344bd94';"
for row in session.execute(CQLString)
print row
Upvotes: 1