Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cassandra 3.1 python driver 'no viable alternative at input describe'

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]...)">
like image 334
Nate Marks Avatar asked Mar 14 '16 11:03

Nate Marks


People also ask

What does no viable alternative at input mean?

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.

Can Cassandra be used with Python?

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.

What is Cassandra in Python?

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.


2 Answers

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.

like image 119
Andy Tolbert Avatar answered Oct 11 '22 14:10

Andy Tolbert


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.

like image 41
natbusa Avatar answered Oct 11 '22 14:10

natbusa