14

I'm trying to access my Cassandra server through a CQLSH client to import a huge CSV file. I'm getting a module' object has no attribute 'parse_options error.

I run the follow command:

cqlsh XXX.XXX.XX.XX XXXX --cqlversion="3.4.2" --execute="copy evolvdso.teste from '2016-10-26 15:25:10.csv' WITH DELIMITER =',' AND HEADER=TRUE --debug";

This is the debug and error message that follows:

Starting copy of evolvdso.teste with columns ['ref_equip', 'date', 'load', 'ptd_assoc'].
Traceback (most recent call last):
  File "/usr/local/bin/cqlsh", line 1133, in onecmd
    self.handle_statement(st, statementtext)
  File "/usr/local/bin/cqlsh", line 1170, in handle_statement
    return custom_handler(parsed)
  File "/usr/local/bin/cqlsh", line 1834, in do_copy
    rows = self.perform_csv_import(ks, cf, columns, fname, opts)
  File "/usr/local/bin/cqlsh", line 1846, in perform_csv_import
    csv_options, dialect_options, unrecognized_options = copyutil.parse_options(self, opts)


AttributeError: 'module' object has no attribute 'parse_options'
Andre Garcia
  • 894
  • 11
  • 30
  • What version of Cassandra are you running? Are you unconvinced that it could be https://issues.apache.org/jira/browse/CASSANDRA-12284, which I linked on your other comment? – Adam Holmberg Nov 03 '16 at 21:18
  • Im running version 3.7. Yes, i saw it , thank you. Maybe it's the same problem. I found a workaround, im using this: https://github.com/brianmhess/cassandra-loader to load the CSV to my remote database and it's working very well! – Andre Garcia Nov 04 '16 at 16:14
  • I also used pip to install the cqlsh client. Yes i assume is the same problem. :) – Andre Garcia Nov 04 '16 at 16:21
  • It's usually best to use the cqlsh version packaged with Cassandra distribution. They are not meant to be cross-version, and it's sometimes not obvious which version is published in that pypi package. – Adam Holmberg Nov 04 '16 at 16:26

4 Answers4

9

Has the same issue when I use cqlsh from pip install cqlsh. Try just use cassandra's tool cqlsh

sudo docker run -it cassandra /usr/bin/cqlsh

Refer to jira

Evan Lin
  • 1,272
  • 1
  • 12
  • 25
3

Answer in 2020:

To use cassandra's cqlsh use docker run -it cassandra /opt/cassandra/bin/cqlsh

If you are using bitnami's cassandra image, cqlsh is located at /opt/bitnami/cassandra/bin/cqlsh

And then COPY keyspace.table TO '/tmp/my_table.csv';

NRJ
  • 1,064
  • 3
  • 15
  • 32
2

I met a similar problem, the reason for my scenario is that the default cqlsh path is /usr/local/bin/cqlsh. (check with command $ which cqlsh)

Solution: using Cassandra shipped /usr/bin/cqlsh to connect the Cassandra server or run some command. For example, connect to Cassandra server using command:

$ /usr/bin/cqlsh <cassandra_listen_ip>

OR run command with

$ /usr/bin/cqlsh <cassandra_listen_ip> -e "<command>"
Jingchao Luan
  • 411
  • 4
  • 10
2

Looks like the pip version has some issues, you should install via the official packages instead like:

apt install wget apt-transport-https
wget -q -O - https://www.apache.org/dist/cassandra/KEYS | apt-key add -
sh -c 'echo "deb http://www.apache.org/dist/cassandra/debian 311x main" > /etc/apt/sources.list.d/cassandra.list'
apt update
apt install -y cassandra

Note this will also include the cassandra services, so if you don't want those to be running you may have to manually disable them.

Greg Bray
  • 14,929
  • 12
  • 80
  • 104