Bringing together the Apache Cassandra experts from the community and DataStax.

Want to learn? Have a question? Want to share your expertise? You are in the right place!

Not sure where to begin? Getting Started



ssnmurtyraju_188715 avatar image
ssnmurtyraju_188715 asked Erick Ramirez edited

TOKEN() query returning "no viable alternative at input 'TOKEN()'"


I am trying to run below query against Cassandra table using datastax python cassandra connector. I am getting "no viable alternative at input 'TOKEN (...ECT TOKEN...)" error. Is there anything wrong in the query? Please help me as i am new to Cassandra.

statement = SimpleStatement("SELECT TOKEN(doc_id), doc_id FROM <ks>.<tablename> WHERE TOKEN(doc_id)>-8939575974182321168 AND TOKEN(doc_id)<8655779911509866528", fetch_size=30)
rows = session.execute(statement)

10 |1000

Up to 8 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.

1 Answer

Erick Ramirez avatar image
Erick Ramirez answered Erick Ramirez edited

@ssnmurtyraju_188715 It appears you're hitting a CQL syntax error and this isn't a problem with the Python driver. The query you posted looks OK so I'm assuming you didn't paste the exact query you have in your code.

If you run the exact same query in cqlsh that you have in your code, you'll be able to work which part of your query is faulty. Cheers!

UPDATE - From question #3667, you indicated that you're connecting to Azure's Cosmos DB. It's not working because even though Cosmos DB provides a CQL-like API, it's not running Apache Cassandra under the hood so you'll find that there are several unsupported Cassandra features/functionality in Cosmos DB.

My suggestion is to use DataStax Astra instead which is built on Apache Cassandra. It's FREE to try without a credit card and you can launch a database instance in just a few clicks. Cheers!

1 comment Share
10 |1000

Up to 8 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.

Thanks for reply. It worked after removing TOKEN(doc_id) from columns section but WHERE condition remains same. SELECT doc_id FROM <ks>.<tablename> WHERE TOKEN(doc_id)>-8939575974182321168 AND TOKEN(doc_id)<8655779911509866528"

0 Likes 0 ·