Skip to content

Commit

Permalink
[Cassandra] Fix: cassandra.cluster.Error wasn't imported
Browse files Browse the repository at this point in the history
  • Loading branch information
arikfr authored Nov 23, 2016
1 parent e7b17b8 commit e06740d
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions query_runner/cass.py
Original file line number Diff line number Diff line change
@@ -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"

Expand Down Expand Up @@ -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)
Expand All @@ -86,22 +85,22 @@ 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)

@classmethod
def type(cls):
return "scylla"


register(Cassandra)
register(ScyllaDB)

0 comments on commit e06740d

Please sign in to comment.