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

Fix: default value for Presto password should be None #3757

Merged
merged 1 commit into from
May 5, 2019
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
30 changes: 17 additions & 13 deletions redash/query_runner/presto.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
from collections import defaultdict
from redash.query_runner import *
from redash.utils import json_dumps, json_loads

import logging
logger = logging.getLogger(__name__)

from collections import defaultdict

try:
from pyhive import presto
Expand Down Expand Up @@ -99,30 +99,33 @@ def get_schema(self, get_stats=False):

def run_query(self, query, user):
connection = presto.connect(
host=self.configuration.get('host', ''),
port=self.configuration.get('port', 8080),
protocol=self.configuration.get('protocol', 'http'),
username=self.configuration.get('username', 'redash'),
password=self.configuration.get('password', ''),
catalog=self.configuration.get('catalog', 'hive'),
schema=self.configuration.get('schema', 'default'))
host=self.configuration.get('host', ''),
port=self.configuration.get('port', 8080),
protocol=self.configuration.get('protocol', 'http'),
username=self.configuration.get('username', 'redash'),
password=self.configuration.get('password'),
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the actual change. The rest is just autopep8... 🤦‍♂

catalog=self.configuration.get('catalog', 'hive'),
schema=self.configuration.get('schema', 'default'))

cursor = connection.cursor()


try:
cursor.execute(query)
column_tuples = [(i[0], PRESTO_TYPES_MAPPING.get(i[1], None)) for i in cursor.description]
column_tuples = [(i[0], PRESTO_TYPES_MAPPING.get(i[1], None))
for i in cursor.description]
columns = self.fetch_columns(column_tuples)
rows = [dict(zip(([c['name'] for c in columns]), r)) for i, r in enumerate(cursor.fetchall())]
rows = [dict(zip(([c['name'] for c in columns]), r))
for i, r in enumerate(cursor.fetchall())]
data = {'columns': columns, 'rows': rows}
json_data = json_dumps(data)
error = None
except DatabaseError as db:
json_data = None
default_message = 'Unspecified DatabaseError: {0}'.format(db.message)
default_message = 'Unspecified DatabaseError: {0}'.format(
db.message)
if isinstance(db.message, dict):
message = db.message.get('failureInfo', {'message', None}).get('message')
message = db.message.get(
'failureInfo', {'message', None}).get('message')
else:
message = None
error = default_message if message is None else message
Expand All @@ -138,4 +141,5 @@ def run_query(self, query, user):

return json_data, error


register(Presto)