Repository: getredash/redash

Issue:
NameError: global name 'cassandra' is not defined
Hey,

### Issue Summary
I added `export REDASH_ADDITIONAL_QUERY_RUNNERS=redash.query_runner.cass` to `opt/redash/.env`. After that, I was able to create a new cassandra datasource but when querying is failing and displaying: **global name 'cassandra' is not defined** 

I have installed the DataStax Cassandra driver `sudo pip install cassandra-driver` and using Python 2.7.6. 

These are the traces of `/opt/redash/logs/celery_error.log`

```
2016-11-23 02:09:15,625: WARNING/Worker-5] Unexpected error while running query:
Traceback (most recent call last):
  File "/opt/redash/redash.0.12.0.b2449/redash/tasks/queries.py", line 410, in run
    data, error = query_runner.run_query(annotated_query, self.user)
  File "/opt/redash/redash.0.12.0.b2449/redash/query_runner/cass.py", line 90, in run_query
    except cassandra.cluster.Error, e:
NameError: global name 'cassandra' is not defined
```
### Technical details

* Redash version 0.12.0+b2449
* OS Ubuntu 3.13.0-88-generic / Browser: Chrome.
* How did you install Redash: running the provisioning script

Thanks

NameError: global name 'cassandra' is not defined
Hey,

### Issue Summary
I added `export REDASH_ADDITIONAL_QUERY_RUNNERS=redash.query_runner.cass` to `opt/redash/.env`. After that, I was able to create a new cassandra datasource but when querying is failing and displaying: **global name 'cassandra' is not defined** 

I have installed the DataStax Cassandra driver `sudo pip install cassandra-driver` and using Python 2.7.6. 

These are the traces of `/opt/redash/logs/celery_error.log`

```
2016-11-23 02:09:15,625: WARNING/Worker-5] Unexpected error while running query:
Traceback (most recent call last):
  File "/opt/redash/redash.0.12.0.b2449/redash/tasks/queries.py", line 410, in run
    data, error = query_runner.run_query(annotated_query, self.user)
  File "/opt/redash/redash.0.12.0.b2449/redash/query_runner/cass.py", line 90, in run_query
    except cassandra.cluster.Error, e:
NameError: global name 'cassandra' is not defined
```
### Technical details

* Redash version 0.12.0+b2449
* OS Ubuntu 3.13.0-88-generic / Browser: Chrome.
* How did you install Redash: running the provisioning script

Thanks



Discussion:
If you run `python -c "import cassandra"` is it working?
> If you run python -c "import cassandra" is it working?

Yes
If you run `python -c "import cassandra"` is it working?
> If you run python -c "import cassandra" is it working?

Yes

Resolving patch:
diff --git a/redash/query_runner/cass.py b/redash/query_runner/cass.py
--- a/redash/query_runner/cass.py
+++ b/redash/query_runner/cass.py
@@ -1,18 +1,19 @@
 import json
-import sys
 import logging
 
-from redash.query_runner import *
+from redash.query_runner import BaseQueryRunner, register
 from redash.utils import JSONEncoder
 
 logger = logging.getLogger(__name__)
 
 try:
-    from cassandra.cluster import Cluster
+    from cassandra.cluster import Cluster, Error
+    from cassandra.auth import PlainTextAuthProvider
     enabled = True
 except ImportError:
     enabled = False
 
+
 class Cassandra(BaseQueryRunner):
     noop_query = "SELECT * FROM system"
 
@@ -61,11 +62,9 @@ def _get_tables(self, schema):
         return results, error
 
     def run_query(self, query, user):
-        from cassandra.cluster import Cluster
         connection = None
         try:
             if self.configuration.get('username', '') and self.configuration.get('password', ''):
-                from cassandra.auth import PlainTextAuthProvider
                 auth_provider = PlainTextAuthProvider(username='{}'.format(self.configuration.get('username', '')),
                                                       password='{}'.format(self.configuration.get('password', '')))
                 connection = Cluster([self.configuration.get('host', '')], auth_provider=auth_provider)
@@ -86,16 +85,15 @@ def run_query(self, query, user):
             json_data = json.dumps(data, cls=JSONEncoder)
 
             error = None
-
-        except cassandra.cluster.Error, e:
+        except Error as e:
             error = e.args[1]
         except KeyboardInterrupt:
             error = "Query cancelled by user."
 
         return json_data, error
 
-class ScyllaDB(Cassandra):
 
+class ScyllaDB(Cassandra):
     def __init__(self, configuration):
         super(ScyllaDB, self).__init__(configuration)
 
@@ -103,5 +101,6 @@ def __init__(self, configuration):
     def type(cls):
         return "scylla"
 
+
 register(Cassandra)
 register(ScyllaDB)


Test patch: