From 3e7b661ca898171977734a0a36b82e0cac01592e Mon Sep 17 00:00:00 2001 From: Jesse Yang Date: Tue, 18 Jun 2019 00:21:06 -0700 Subject: [PATCH 1/2] Add an `extras` field for Presto connection This is mostly for allowing self-assigned SSL certificate. For example, services like [Qubole](https://docs.qubole.com/en/latest/user-guide/presto/connect-to-presto-when-ssl-enabled.html) only allows SSL connection via self-assigned CA certificate. The default value (placeholder) should have made it obvious what this field is for for those who need it. --- redash/query_runner/presto.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/redash/query_runner/presto.py b/redash/query_runner/presto.py index 2966d1ccf9..3f283a7d21 100644 --- a/redash/query_runner/presto.py +++ b/redash/query_runner/presto.py @@ -59,8 +59,12 @@ def configuration_schema(cls): 'password': { 'type': 'string' }, + 'extras': { + 'type': 'string', + 'default': '{"requests_kwargs": null}' + } }, - 'order': ['host', 'protocol', 'port', 'username', 'password', 'schema', 'catalog'], + 'order': ['host', 'protocol', 'port', 'username', 'password', 'schema', 'catalog', 'extras'], 'required': ['host'] } @@ -105,7 +109,8 @@ def run_query(self, query, user): username=self.configuration.get('username', 'redash'), password=(self.configuration.get('password') or None), catalog=self.configuration.get('catalog', 'hive'), - schema=self.configuration.get('schema', 'default')) + schema=self.configuration.get('schema', 'default'), + **json_loads(self.configuration.get('extras') or '{}')) cursor = connection.cursor() From 39e43f119421446446f09ae6f337d83a624f4dfe Mon Sep 17 00:00:00 2001 From: Jesse Yang Date: Wed, 19 Jun 2019 23:22:16 -0700 Subject: [PATCH 2/2] Use system.jdbc for Presto tables In lower version of Presto, sometimes the old query will throw "outputFormat should not be accessed from a null StorageFormat" error (see https://github.com/prestodb/presto/issues/6972). --- redash/query_runner/presto.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/redash/query_runner/presto.py b/redash/query_runner/presto.py index 3f283a7d21..c74dc148bc 100644 --- a/redash/query_runner/presto.py +++ b/redash/query_runner/presto.py @@ -79,10 +79,11 @@ def type(cls): def get_schema(self, get_stats=False): schema = {} query = """ - SELECT table_schema, table_name, column_name - FROM information_schema.columns - WHERE table_schema NOT IN ('pg_catalog', 'information_schema') - """ + SELECT + table_schem, table_name, column_name + FROM system.jdbc.columns + WHERE table_cat = '{}' + """.format(self.configuration.get('catalog', 'hive')) results, error = self.run_query(query, None) @@ -92,7 +93,7 @@ def get_schema(self, get_stats=False): results = json_loads(results) for row in results['rows']: - table_name = '{}.{}'.format(row['table_schema'], row['table_name']) + table_name = '{}.{}'.format(row['table_schem'], row['table_name']) if table_name not in schema: schema[table_name] = {'name': table_name, 'columns': []}