Skip to content

Commit e0898aa

Browse files
authored
Merge pull request getredash#1482 from yershalom/master
[Cassandra] Add: schema browser support & explicit protocol version
2 parents e497ce4 + 8a3bbca commit e0898aa

File tree

1 file changed

+16
-6
lines changed

1 file changed

+16
-6
lines changed

query_runner/cass.py

+16-6
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616

1717
class Cassandra(BaseQueryRunner):
18-
noop_query = "SELECT * FROM system.compactions_in_progress"
18+
noop_query = "SELECT dateof(now()) FROM system.local"
1919

2020
@classmethod
2121
def enabled(cls):
@@ -53,23 +53,33 @@ def configuration_schema(cls):
5353
def type(cls):
5454
return "Cassandra"
5555

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

6161
results, error = self.run_query(query, None)
62-
return results, error
62+
results = json.loads(results)
63+
64+
schema = {}
65+
for row in results['rows']:
66+
table_name = row['columnfamily_name']
67+
column_name = row['column_name']
68+
if table_name not in schema:
69+
schema[table_name] = {'name': table_name, 'columns': []}
70+
schema[table_name]['columns'].append(column_name)
71+
72+
return schema.values()
6373

6474
def run_query(self, query, user):
6575
connection = None
6676
try:
6777
if self.configuration.get('username', '') and self.configuration.get('password', ''):
6878
auth_provider = PlainTextAuthProvider(username='{}'.format(self.configuration.get('username', '')),
6979
password='{}'.format(self.configuration.get('password', '')))
70-
connection = Cluster([self.configuration.get('host', '')], auth_provider=auth_provider)
80+
connection = Cluster([self.configuration.get('host', '')], auth_provider=auth_provider, protocol_version=3)
7181
else:
72-
connection = Cluster([self.configuration.get('host', '')])
82+
connection = Cluster([self.configuration.get('host', '')], protocol_version=3)
7383

7484
session = connection.connect()
7585
session.set_keyspace(self.configuration['keyspace'])

0 commit comments

Comments
 (0)