prompt: We are currently solving the following issue within our repository. Here is the issue text:
  --- BEGIN ISSUE ---
  Support for Presto username and password
  Currently the Presto query runner supports username only. We should support password as well.
  
  This probably requires upgrading the PyHive library.
  
  --- END ISSUE ---
  
  Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
  --- BEGIN FILES ---
  Path: `redash/query_runner/presto.py`
  Content:
  ```
  1 from redash.query_runner import *
  2 from redash.utils import json_dumps, json_loads
  3 
  4 import logging
  5 logger = logging.getLogger(__name__)
  6 
  7 from collections import defaultdict
  8 
  9 try:
  10     from pyhive import presto
  11     from pyhive.exc import DatabaseError
  12     enabled = True
  13 
  14 except ImportError:
  15     enabled = False
  16 
  17 PRESTO_TYPES_MAPPING = {
  18     "integer": TYPE_INTEGER,
  19     "tinyint": TYPE_INTEGER,
  20     "smallint": TYPE_INTEGER,
  21     "long": TYPE_INTEGER,
  22     "bigint": TYPE_INTEGER,
  23     "float": TYPE_FLOAT,
  24     "double": TYPE_FLOAT,
  25     "boolean": TYPE_BOOLEAN,
  26     "string": TYPE_STRING,
  27     "varchar": TYPE_STRING,
  28     "date": TYPE_DATE,
  29 }
  30 
  31 
  32 class Presto(BaseQueryRunner):
  33     noop_query = 'SHOW TABLES'
  34 
  35     @classmethod
  36     def configuration_schema(cls):
  37         return {
  38             'type': 'object',
  39             'properties': {
  40                 'host': {
  41                     'type': 'string'
  42                 },
  43                 'protocol': {
  44                     'type': 'string',
  45                     'default': 'http'
  46                 },
  47                 'port': {
  48                     'type': 'number'
  49                 },
  50                 'schema': {
  51                     'type': 'string'
  52                 },
  53                 'catalog': {
  54                     'type': 'string'
  55                 },
  56                 'username': {
  57                     'type': 'string'
  58                 },
  59             },
  60             'order': ['host', 'protocol', 'port', 'username', 'schema', 'catalog'],
  61             'required': ['host']
  62         }
  63 
  64     @classmethod
  65     def enabled(cls):
  66         return enabled
  67 
  68     @classmethod
  69     def type(cls):
  70         return "presto"
  71 
  72     def get_schema(self, get_stats=False):
  73         schema = {}
  74         query = """
  75         SELECT table_schema, table_name, column_name
  76         FROM information_schema.columns
  77         WHERE table_schema NOT IN ('pg_catalog', 'information_schema')
  78         """
  79 
  80         results, error = self.run_query(query, None)
  81 
  82         if error is not None:
  83             raise Exception("Failed getting schema.")
  84 
  85         results = json_loads(results)
  86 
  87         for row in results['rows']:
  88             table_name = '{}.{}'.format(row['table_schema'], row['table_name'])
  89 
  90             if table_name not in schema:
  91                 schema[table_name] = {'name': table_name, 'columns': []}
  92 
  93             schema[table_name]['columns'].append(row['column_name'])
  94 
  95         return schema.values()
  96 
  97     def run_query(self, query, user):
  98         connection = presto.connect(
  99                 host=self.configuration.get('host', ''),
  100                 port=self.configuration.get('port', 8080),
  101                 protocol=self.configuration.get('protocol', 'http'),
  102                 username=self.configuration.get('username', 'redash'),
  103                 catalog=self.configuration.get('catalog', 'hive'),
  104                 schema=self.configuration.get('schema', 'default'))
  105 
  106         cursor = connection.cursor()
  107 
  108 
  109         try:
  110             cursor.execute(query)
  111             column_tuples = [(i[0], PRESTO_TYPES_MAPPING.get(i[1], None)) for i in cursor.description]
  112             columns = self.fetch_columns(column_tuples)
  113             rows = [dict(zip(([c['name'] for c in columns]), r)) for i, r in enumerate(cursor.fetchall())]
  114             data = {'columns': columns, 'rows': rows}
  115             json_data = json_dumps(data)
  116             error = None
  117         except DatabaseError as db:
  118             json_data = None
  119             default_message = 'Unspecified DatabaseError: {0}'.format(db.message)
  120             if isinstance(db.message, dict):
  121                 message = db.message.get('failureInfo', {'message', None}).get('message')
  122             else:
  123                 message = None
  124             error = default_message if message is None else message
  125         except (KeyboardInterrupt, InterruptException) as e:
  126             cursor.cancel()
  127             error = "Query cancelled by user."
  128             json_data = None
  129         except Exception as ex:
  130             json_data = None
  131             error = ex.message
  132             if not isinstance(error, basestring):
  133                 error = unicode(error)
  134 
  135         return json_data, error
  136 
  137 register(Presto)
  138
  ```
  --- END FILES ---
  
  Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.
  
  Here is an example:
  
  ```diff
  diff --git a/examples/server_async.py b/examples/server_async.py
  --- a/examples/server_async.py
  +++ b/examples/server_async.py
  @@ -313,4 +313,4 @@
   
   
   if __name__ == "__main__":
  -    asyncio.run(run_async_server("."), debug=True)
  +    asyncio.run(run_async_server(), debug=True)
  diff --git a/examples/server_sync.py b/examples/server_sync.py
  --- a/examples/server_sync.py
  +++ b/examples/server_sync.py
  @@ -313,5 +313,5 @@
   
   
   if __name__ == "__main__":
  -    server = run_sync_server(".")
  +    server = run_sync_server()
       server.shutdown()
  
  ```
  
golden_diff: diff --git a/redash/query_runner/presto.py b/redash/query_runner/presto.py
  --- a/redash/query_runner/presto.py
  +++ b/redash/query_runner/presto.py
  @@ -56,8 +56,11 @@
                   'username': {
                       'type': 'string'
                   },
  +                'password': {
  +                    'type': 'string'
  +                },
               },
  -            'order': ['host', 'protocol', 'port', 'username', 'schema', 'catalog'],
  +            'order': ['host', 'protocol', 'port', 'username', 'password', 'schema', 'catalog'],
               'required': ['host']
           }
   
  @@ -100,6 +103,7 @@
                   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'))
  
verification_info: {"golden_diff": "diff --git a/redash/query_runner/presto.py b/redash/query_runner/presto.py\n--- a/redash/query_runner/presto.py\n+++ b/redash/query_runner/presto.py\n@@ -56,8 +56,11 @@\n                 'username': {\n                     'type': 'string'\n                 },\n+                'password': {\n+                    'type': 'string'\n+                },\n             },\n-            'order': ['host', 'protocol', 'port', 'username', 'schema', 'catalog'],\n+            'order': ['host', 'protocol', 'port', 'username', 'password', 'schema', 'catalog'],\n             'required': ['host']\n         }\n \n@@ -100,6 +103,7 @@\n                 port=self.configuration.get('port', 8080),\n                 protocol=self.configuration.get('protocol', 'http'),\n                 username=self.configuration.get('username', 'redash'),\n+                password=self.configuration.get('password', ''),\n                 catalog=self.configuration.get('catalog', 'hive'),\n                 schema=self.configuration.get('schema', 'default'))\n", "issue": "Support for Presto username and password\nCurrently the Presto query runner supports username only. We should support password as well.\r\n\r\nThis probably requires upgrading the PyHive library.\n", "before_files": [{"content": "from redash.query_runner import *\nfrom redash.utils import json_dumps, json_loads\n\nimport logging\nlogger = logging.getLogger(__name__)\n\nfrom collections import defaultdict\n\ntry:\n    from pyhive import presto\n    from pyhive.exc import DatabaseError\n    enabled = True\n\nexcept ImportError:\n    enabled = False\n\nPRESTO_TYPES_MAPPING = {\n    \"integer\": TYPE_INTEGER,\n    \"tinyint\": TYPE_INTEGER,\n    \"smallint\": TYPE_INTEGER,\n    \"long\": TYPE_INTEGER,\n    \"bigint\": TYPE_INTEGER,\n    \"float\": TYPE_FLOAT,\n    \"double\": TYPE_FLOAT,\n    \"boolean\": TYPE_BOOLEAN,\n    \"string\": TYPE_STRING,\n    \"varchar\": TYPE_STRING,\n    \"date\": TYPE_DATE,\n}\n\n\nclass Presto(BaseQueryRunner):\n    noop_query = 'SHOW TABLES'\n\n    @classmethod\n    def configuration_schema(cls):\n        return {\n            'type': 'object',\n            'properties': {\n                'host': {\n                    'type': 'string'\n                },\n                'protocol': {\n                    'type': 'string',\n                    'default': 'http'\n                },\n                'port': {\n                    'type': 'number'\n                },\n                'schema': {\n                    'type': 'string'\n                },\n                'catalog': {\n                    'type': 'string'\n                },\n                'username': {\n                    'type': 'string'\n                },\n            },\n            'order': ['host', 'protocol', 'port', 'username', 'schema', 'catalog'],\n            'required': ['host']\n        }\n\n    @classmethod\n    def enabled(cls):\n        return enabled\n\n    @classmethod\n    def type(cls):\n        return \"presto\"\n\n    def get_schema(self, get_stats=False):\n        schema = {}\n        query = \"\"\"\n        SELECT table_schema, table_name, column_name\n        FROM information_schema.columns\n        WHERE table_schema NOT IN ('pg_catalog', 'information_schema')\n        \"\"\"\n\n        results, error = self.run_query(query, None)\n\n        if error is not None:\n            raise Exception(\"Failed getting schema.\")\n\n        results = json_loads(results)\n\n        for row in results['rows']:\n            table_name = '{}.{}'.format(row['table_schema'], row['table_name'])\n\n            if table_name not in schema:\n                schema[table_name] = {'name': table_name, 'columns': []}\n\n            schema[table_name]['columns'].append(row['column_name'])\n\n        return schema.values()\n\n    def run_query(self, query, user):\n        connection = presto.connect(\n                host=self.configuration.get('host', ''),\n                port=self.configuration.get('port', 8080),\n                protocol=self.configuration.get('protocol', 'http'),\n                username=self.configuration.get('username', 'redash'),\n                catalog=self.configuration.get('catalog', 'hive'),\n                schema=self.configuration.get('schema', 'default'))\n\n        cursor = connection.cursor()\n\n\n        try:\n            cursor.execute(query)\n            column_tuples = [(i[0], PRESTO_TYPES_MAPPING.get(i[1], None)) for i in cursor.description]\n            columns = self.fetch_columns(column_tuples)\n            rows = [dict(zip(([c['name'] for c in columns]), r)) for i, r in enumerate(cursor.fetchall())]\n            data = {'columns': columns, 'rows': rows}\n            json_data = json_dumps(data)\n            error = None\n        except DatabaseError as db:\n            json_data = None\n            default_message = 'Unspecified DatabaseError: {0}'.format(db.message)\n            if isinstance(db.message, dict):\n                message = db.message.get('failureInfo', {'message', None}).get('message')\n            else:\n                message = None\n            error = default_message if message is None else message\n        except (KeyboardInterrupt, InterruptException) as e:\n            cursor.cancel()\n            error = \"Query cancelled by user.\"\n            json_data = None\n        except Exception as ex:\n            json_data = None\n            error = ex.message\n            if not isinstance(error, basestring):\n                error = unicode(error)\n\n        return json_data, error\n\nregister(Presto)\n", "path": "redash/query_runner/presto.py"}], "after_files": [{"content": "from redash.query_runner import *\nfrom redash.utils import json_dumps, json_loads\n\nimport logging\nlogger = logging.getLogger(__name__)\n\nfrom collections import defaultdict\n\ntry:\n    from pyhive import presto\n    from pyhive.exc import DatabaseError\n    enabled = True\n\nexcept ImportError:\n    enabled = False\n\nPRESTO_TYPES_MAPPING = {\n    \"integer\": TYPE_INTEGER,\n    \"tinyint\": TYPE_INTEGER,\n    \"smallint\": TYPE_INTEGER,\n    \"long\": TYPE_INTEGER,\n    \"bigint\": TYPE_INTEGER,\n    \"float\": TYPE_FLOAT,\n    \"double\": TYPE_FLOAT,\n    \"boolean\": TYPE_BOOLEAN,\n    \"string\": TYPE_STRING,\n    \"varchar\": TYPE_STRING,\n    \"date\": TYPE_DATE,\n}\n\n\nclass Presto(BaseQueryRunner):\n    noop_query = 'SHOW TABLES'\n\n    @classmethod\n    def configuration_schema(cls):\n        return {\n            'type': 'object',\n            'properties': {\n                'host': {\n                    'type': 'string'\n                },\n                'protocol': {\n                    'type': 'string',\n                    'default': 'http'\n                },\n                'port': {\n                    'type': 'number'\n                },\n                'schema': {\n                    'type': 'string'\n                },\n                'catalog': {\n                    'type': 'string'\n                },\n                'username': {\n                    'type': 'string'\n                },\n                'password': {\n                    'type': 'string'\n                },\n            },\n            'order': ['host', 'protocol', 'port', 'username', 'password', 'schema', 'catalog'],\n            'required': ['host']\n        }\n\n    @classmethod\n    def enabled(cls):\n        return enabled\n\n    @classmethod\n    def type(cls):\n        return \"presto\"\n\n    def get_schema(self, get_stats=False):\n        schema = {}\n        query = \"\"\"\n        SELECT table_schema, table_name, column_name\n        FROM information_schema.columns\n        WHERE table_schema NOT IN ('pg_catalog', 'information_schema')\n        \"\"\"\n\n        results, error = self.run_query(query, None)\n\n        if error is not None:\n            raise Exception(\"Failed getting schema.\")\n\n        results = json_loads(results)\n\n        for row in results['rows']:\n            table_name = '{}.{}'.format(row['table_schema'], row['table_name'])\n\n            if table_name not in schema:\n                schema[table_name] = {'name': table_name, 'columns': []}\n\n            schema[table_name]['columns'].append(row['column_name'])\n\n        return schema.values()\n\n    def run_query(self, query, user):\n        connection = presto.connect(\n                host=self.configuration.get('host', ''),\n                port=self.configuration.get('port', 8080),\n                protocol=self.configuration.get('protocol', 'http'),\n                username=self.configuration.get('username', 'redash'),\n                password=self.configuration.get('password', ''),\n                catalog=self.configuration.get('catalog', 'hive'),\n                schema=self.configuration.get('schema', 'default'))\n\n        cursor = connection.cursor()\n\n\n        try:\n            cursor.execute(query)\n            column_tuples = [(i[0], PRESTO_TYPES_MAPPING.get(i[1], None)) for i in cursor.description]\n            columns = self.fetch_columns(column_tuples)\n            rows = [dict(zip(([c['name'] for c in columns]), r)) for i, r in enumerate(cursor.fetchall())]\n            data = {'columns': columns, 'rows': rows}\n            json_data = json_dumps(data)\n            error = None\n        except DatabaseError as db:\n            json_data = None\n            default_message = 'Unspecified DatabaseError: {0}'.format(db.message)\n            if isinstance(db.message, dict):\n                message = db.message.get('failureInfo', {'message', None}).get('message')\n            else:\n                message = None\n            error = default_message if message is None else message\n        except (KeyboardInterrupt, InterruptException) as e:\n            cursor.cancel()\n            error = \"Query cancelled by user.\"\n            json_data = None\n        except Exception as ex:\n            json_data = None\n            error = ex.message\n            if not isinstance(error, basestring):\n                error = unicode(error)\n\n        return json_data, error\n\nregister(Presto)\n", "path": "redash/query_runner/presto.py"}]}