Skip to content

Commit

Permalink
Merge pull request #1482 from yershalom/master
Browse files Browse the repository at this point in the history
[Cassandra] Add: schema browser support & explicit protocol version
  • Loading branch information
arikfr authored Jan 3, 2017
2 parents 512ac9b + ca4db61 commit 2df0979
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions redash/query_runner/cass.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@


class Cassandra(BaseQueryRunner):
noop_query = "SELECT * FROM system.compactions_in_progress"
noop_query = "SELECT dateof(now()) FROM system.local"

@classmethod
def enabled(cls):
Expand Down Expand Up @@ -53,23 +53,33 @@ def configuration_schema(cls):
def type(cls):
return "Cassandra"

def _get_tables(self, schema):
def get_schema(self, get_stats=False):
query = """
select columnfamily_name from system.schema_columnfamilies where keyspace_name = '{}';
SELECT columnfamily_name, column_name FROM system.schema_columns where keyspace_name ='{}';
""".format(self.configuration['keyspace'])

results, error = self.run_query(query, None)
return results, error
results = json.loads(results)

schema = {}
for row in results['rows']:
table_name = row['columnfamily_name']
column_name = row['column_name']
if table_name not in schema:
schema[table_name] = {'name': table_name, 'columns': []}
schema[table_name]['columns'].append(column_name)

return schema.values()

def run_query(self, query, user):
connection = None
try:
if self.configuration.get('username', '') and self.configuration.get('password', ''):
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)
connection = Cluster([self.configuration.get('host', '')], auth_provider=auth_provider, protocol_version=3)
else:
connection = Cluster([self.configuration.get('host', '')])
connection = Cluster([self.configuration.get('host', '')], protocol_version=3)

session = connection.connect()
session.set_keyspace(self.configuration['keyspace'])
Expand Down

0 comments on commit 2df0979

Please sign in to comment.