When I try to run the following command from python (I am using the Cassandra Datastax Python Driver with Python 2.7.6)
cluster = Cluster([CASSANDRA_HOST], port=CASSANDRA_PORT, cql_version=CASSANDRA_CQL_VERSION, protocol_version=3)
session = cluster.connect(CASSANDRA_KEYSPACE)
NEW_ID = "9999999999"
CQL_FILE_NAME = "FNAME-"+NEW_ID+".cql"
cql_cmd = "SOURCE '~/dev/cql_files/"+ CQL_FILE_NAME + "'"
session.execute(cql_cmd)
I get the error below:
File "/usr/local/lib/python2.7/dist-packages/cassandra/cluster.py", line 2012, in execute
return self.execute_async(query, parameters, trace, custom_payload, timeout, execution_profile, paging_state).result()
File "/usr/local/lib/python2.7/dist-packages/cassandra/cluster.py", line 3801, in result
raise self._final_exception
cassandra.protocol.SyntaxException: <Error from server: code=2000 [Syntax error in CQL query] message="line 1:0 no viable alternative at input 'SOURCE' ([SOURCE]...)">
But when I run the same string from cqlsh it runs fine. Any ideas on what I should change? Thanks!
The string looks like this:
"SOURCE '~/dev/cql_files/FNAME-9999999999.cql'"
SOURCE
is a command unique to cqlsh, it is not actually part of the CQL specification so you cannot use it using a client driver:
Important: The CQL shell commands described in this section work only within the cqlsh shell and are not accessible from drivers. CQL shell uses native protocol and the Datastax python driver to execute CQL commands on the connected Cassandra host. For configuration information, see the Cassandra 3.0 cassandra.yaml file.