Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Cassandra] Add: schema browser support & explicit protocol version #1482

Merged
merged 4 commits into from
Jan 3, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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