I can't run describe keyspaces for some reason, even though I'm clearly connecting to my Cassandra 3.3 host via the 3.1 python driver. Some other commands seem to work fine.
Thanks in advance!
from cassandra.cluster import Cluster
cluster = Cluster(['192.168.1.53'])
#session = cluster.connect('node_data')
session = cluster.connect()
session.execute('USE node_data')
rows = session.execute('SELECT * FROM users')
session.execute('DESCRIBE KEYSPACES;')
---------------------------------------------------------------------------
SyntaxException Traceback (most recent call last)
<ipython-input-5-8b1f82917aa9> in <module>()
----> 1 session.execute('DESCRIBE KEYSPACES;')
2
/Users/natemarks/.virtualenvs/cassandra/lib/python2.7/site-packages/cassandra/cluster.so in cassandra.cluster.Session.execute (cassandra/cluster.c:27107)()
/Users/natemarks/.virtualenvs/cassandra/lib/python2.7/site-packages/cassandra/cluster.so in cassandra.cluster.ResponseFuture.result (cassandra/cluster.c:60227)()
SyntaxException: <ErrorMessage code=2000 [Syntax error in CQL query] message="line 1:0 no viable alternative at input 'DESCRIBE' ([DESCRIBE]...)">
As a general rule, 'no viable alternative input at 'something' usually means you forgot to close a parentheses/quote/forgot to put indented code after a if statement, or something to that effect.
Python module for working with Cassandra database is called Cassandra Driver. It is also developed by Apache foundation. This module contains an ORM API, as well as a core API similar in nature to DB-API for relational databases. Installation of Cassandra driver is easily done using pip utility.
Apache Cassandra is a column-family NoSQL data store designed for write-heavy persistent storage in Python web applications and data projects. Apache Cassandra is an implementation of the NoSQL database concept.
DESCRIBE
is a cqlsh-specific command, so it is not supported by the drivers since it is not considered a CQL command. You can find a full listing of the cqlsh commands here.
Alternatively you can get at a keyspace's schema using the python-driver by accessing Cluster.metadata
and then accessing the keyspaces
dict.
cluster.metadata.keyspaces
cluster.metadata.keyspaces['node_data']
cluster.metadata.keyspaces['node_data'].tables
cluster.metadata.keyspaces['node_data'].tables['users']
cluster.metadata.keyspaces['node_data'].tables['users'].columns
cluster.metadata.keyspaces['node_data'].tables['users'].columns['uid']
By accessing the cluster metadata you can get all info related to any keyspace, table, and column stored in the given cassandra cluster.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With