We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
TreasureData getSchema fails when setting non-default region
<!--
#####################################################################
#
# Need support? USE THE FORUM! https://discuss.redash.io/c/support.
#
# Don't have steps to reproduce and actually not sure it's a bug?
# Use the forum! https://discuss.redash.io/c/support.
#
#####################################################################

**Got an idea for a new feature?** Check if it isn't on the roadmap already: https://bit.ly/redash-roadmap and start a new discussion in the features category: https://discuss.redash.io/c/feature-requests 🌟.

Found a bug? Please fill out the sections below... thank you 👍

Found a security vulnerability? Please email security@redash.io to report any security vulnerabilities. We will acknowledge receipt of your vulnerability and strive to send you regular updates about our progress. If you're curious about the status of your disclosure please feel free to email us again. If you want to encrypt your disclosure email, you can use this PGP key.

-->

### Issue Summary

There are some regions in Treasure Data, but getSchema alsways fails when setting non-default region.

### Steps to Reproduce

1. Set datasource using non-default region (e.g. Tokyo region)
2. Push schema refresh then "Schema refresh failed" error occurs

### Technical details:

* Redash Version: confirmed v5.0.2
* Browser/OS: any Browsers/OSs
* How did you install Redash: from Amazon AMI

### Details

When accessing Treasure Data to get schema, always default region will be set because the parameter is not prepared.
https://github.com/getredash/redash/blob/6c364369bb0eb98e2191c2e502fed72abe5a74c7/redash/query_runner/treasuredata.py#L82

--- 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/treasuredata.py`
Content:
```
1 import logging
2 
3 from redash.query_runner import *
4 from redash.utils import json_dumps
5 
6 logger = logging.getLogger(__name__)
7 
8 try:
9     import tdclient
10     from tdclient import errors
11 
12     enabled = True
13 
14 except ImportError:
15     enabled = False
16 
17 TD_TYPES_MAPPING = {
18     "bigint": TYPE_INTEGER,
19     "tinyint": TYPE_INTEGER,
20     "smallint": TYPE_INTEGER,
21     "int": TYPE_INTEGER,
22     "integer": TYPE_INTEGER,
23     "long": TYPE_INTEGER,
24     "double": TYPE_FLOAT,
25     "decimal": TYPE_FLOAT,
26     "float": TYPE_FLOAT,
27     "real": TYPE_FLOAT,
28     "boolean": TYPE_BOOLEAN,
29     "timestamp": TYPE_DATETIME,
30     "date": TYPE_DATETIME,
31     "char": TYPE_STRING,
32     "string": TYPE_STRING,
33     "varchar": TYPE_STRING,
34 }
35 
36 
37 class TreasureData(BaseQueryRunner):
38     should_annotate_query = False
39     noop_query = "SELECT 1"
40 
41     @classmethod
42     def configuration_schema(cls):
43         return {
44             "type": "object",
45             "properties": {
46                 "endpoint": {"type": "string"},
47                 "apikey": {"type": "string"},
48                 "type": {"type": "string"},
49                 "db": {"type": "string", "title": "Database Name"},
50                 "get_schema": {
51                     "type": "boolean",
52                     "title": "Auto Schema Retrieval",
53                     "default": False,
54                 },
55             },
56             "required": ["apikey", "db"],
57         }
58 
59     @classmethod
60     def enabled(cls):
61         return enabled
62 
63     @classmethod
64     def type(cls):
65         return "treasuredata"
66 
67     def get_schema(self, get_stats=False):
68         schema = {}
69         if self.configuration.get("get_schema", False):
70             try:
71                 with tdclient.Client(self.configuration.get("apikey")) as client:
72                     for table in client.tables(self.configuration.get("db")):
73                         table_name = "{}.{}".format(
74                             self.configuration.get("db"), table.name
75                         )
76                         for table_schema in table.schema:
77                             schema[table_name] = {
78                                 "name": table_name,
79                                 "columns": [column[0] for column in table.schema],
80                             }
81             except Exception as ex:
82                 raise Exception("Failed getting schema")
83         return list(schema.values())
84 
85     def run_query(self, query, user):
86         connection = tdclient.connect(
87             endpoint=self.configuration.get("endpoint", "https://api.treasuredata.com"),
88             apikey=self.configuration.get("apikey"),
89             type=self.configuration.get("type", "hive").lower(),
90             db=self.configuration.get("db"),
91         )
92 
93         cursor = connection.cursor()
94         try:
95             cursor.execute(query)
96             columns_tuples = [
97                 (i[0], TD_TYPES_MAPPING.get(i[1], None))
98                 for i in cursor.show_job()["hive_result_schema"]
99             ]
100             columns = self.fetch_columns(columns_tuples)
101 
102             if cursor.rowcount == 0:
103                 rows = []
104             else:
105                 rows = [
106                     dict(zip(([column["name"] for column in columns]), r))
107                     for r in cursor.fetchall()
108                 ]
109             data = {"columns": columns, "rows": rows}
110             json_data = json_dumps(data)
111             error = None
112         except errors.InternalError as e:
113             json_data = None
114             error = "%s: %s" % (
115                 str(e),
116                 cursor.show_job()
117                 .get("debug", {})
118                 .get("stderr", "No stderr message in the response"),
119             )
120         return json_data, error
121 
122 
123 register(TreasureData)
124
```
--- 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()

```

diff --git a/redash/query_runner/treasuredata.py b/redash/query_runner/treasuredata.py
--- a/redash/query_runner/treasuredata.py
+++ b/redash/query_runner/treasuredata.py
@@ -68,7 +68,7 @@
         schema = {}
         if self.configuration.get("get_schema", False):
             try:
-                with tdclient.Client(self.configuration.get("apikey")) as client:
+                with tdclient.Client(self.configuration.get("apikey"),endpoint=self.configuration.get("endpoint")) as client:
                     for table in client.tables(self.configuration.get("db")):
                         table_name = "{}.{}".format(
                             self.configuration.get("db"), table.name

{"golden_diff": "diff --git a/redash/query_runner/treasuredata.py b/redash/query_runner/treasuredata.py\n--- a/redash/query_runner/treasuredata.py\n+++ b/redash/query_runner/treasuredata.py\n@@ -68,7 +68,7 @@\n         schema = {}\n         if self.configuration.get(\"get_schema\", False):\n             try:\n-                with tdclient.Client(self.configuration.get(\"apikey\")) as client:\n+                with tdclient.Client(self.configuration.get(\"apikey\"),endpoint=self.configuration.get(\"endpoint\")) as client:\n                     for table in client.tables(self.configuration.get(\"db\")):\n                         table_name = \"{}.{}\".format(\n                             self.configuration.get(\"db\"), table.name\n", "issue": "TreasureData getSchema fails when setting non-default region\n<!--\r\n#####################################################################\r\n#\r\n# Need support? USE THE FORUM! https://discuss.redash.io/c/support.\r\n#\r\n# Don't have steps to reproduce and actually not sure it's a bug?\r\n# Use the forum! https://discuss.redash.io/c/support.\r\n#\r\n#####################################################################\r\n\r\n**Got an idea for a new feature?** Check if it isn't on the roadmap already: https://bit.ly/redash-roadmap and start a new discussion in the features category: https://discuss.redash.io/c/feature-requests \ud83c\udf1f.\r\n\r\nFound a bug? Please fill out the sections below... thank you \ud83d\udc4d\r\n\r\nFound a security vulnerability? Please email security@redash.io to report any security vulnerabilities. We will acknowledge receipt of your vulnerability and strive to send you regular updates about our progress. If you're curious about the status of your disclosure please feel free to email us again. If you want to encrypt your disclosure email, you can use this PGP key.\r\n\r\n-->\r\n\r\n### Issue Summary\r\n\r\nThere are some regions in Treasure Data, but getSchema alsways fails when setting non-default region.\r\n\r\n### Steps to Reproduce\r\n\r\n1. Set datasource using non-default region (e.g. Tokyo region)\r\n2. Push schema refresh then \"Schema refresh failed\" error occurs\r\n\r\n### Technical details:\r\n\r\n* Redash Version: confirmed v5.0.2\r\n* Browser/OS: any Browsers/OSs\r\n* How did you install Redash: from Amazon AMI\r\n\r\n### Details\r\n\r\nWhen accessing Treasure Data to get schema, always default region will be set because the parameter is not prepared.\r\nhttps://github.com/getredash/redash/blob/6c364369bb0eb98e2191c2e502fed72abe5a74c7/redash/query_runner/treasuredata.py#L82\n", "before_files": [{"content": "import logging\n\nfrom redash.query_runner import *\nfrom redash.utils import json_dumps\n\nlogger = logging.getLogger(__name__)\n\ntry:\n    import tdclient\n    from tdclient import errors\n\n    enabled = True\n\nexcept ImportError:\n    enabled = False\n\nTD_TYPES_MAPPING = {\n    \"bigint\": TYPE_INTEGER,\n    \"tinyint\": TYPE_INTEGER,\n    \"smallint\": TYPE_INTEGER,\n    \"int\": TYPE_INTEGER,\n    \"integer\": TYPE_INTEGER,\n    \"long\": TYPE_INTEGER,\n    \"double\": TYPE_FLOAT,\n    \"decimal\": TYPE_FLOAT,\n    \"float\": TYPE_FLOAT,\n    \"real\": TYPE_FLOAT,\n    \"boolean\": TYPE_BOOLEAN,\n    \"timestamp\": TYPE_DATETIME,\n    \"date\": TYPE_DATETIME,\n    \"char\": TYPE_STRING,\n    \"string\": TYPE_STRING,\n    \"varchar\": TYPE_STRING,\n}\n\n\nclass TreasureData(BaseQueryRunner):\n    should_annotate_query = False\n    noop_query = \"SELECT 1\"\n\n    @classmethod\n    def configuration_schema(cls):\n        return {\n            \"type\": \"object\",\n            \"properties\": {\n                \"endpoint\": {\"type\": \"string\"},\n                \"apikey\": {\"type\": \"string\"},\n                \"type\": {\"type\": \"string\"},\n                \"db\": {\"type\": \"string\", \"title\": \"Database Name\"},\n                \"get_schema\": {\n                    \"type\": \"boolean\",\n                    \"title\": \"Auto Schema Retrieval\",\n                    \"default\": False,\n                },\n            },\n            \"required\": [\"apikey\", \"db\"],\n        }\n\n    @classmethod\n    def enabled(cls):\n        return enabled\n\n    @classmethod\n    def type(cls):\n        return \"treasuredata\"\n\n    def get_schema(self, get_stats=False):\n        schema = {}\n        if self.configuration.get(\"get_schema\", False):\n            try:\n                with tdclient.Client(self.configuration.get(\"apikey\")) as client:\n                    for table in client.tables(self.configuration.get(\"db\")):\n                        table_name = \"{}.{}\".format(\n                            self.configuration.get(\"db\"), table.name\n                        )\n                        for table_schema in table.schema:\n                            schema[table_name] = {\n                                \"name\": table_name,\n                                \"columns\": [column[0] for column in table.schema],\n                            }\n            except Exception as ex:\n                raise Exception(\"Failed getting schema\")\n        return list(schema.values())\n\n    def run_query(self, query, user):\n        connection = tdclient.connect(\n            endpoint=self.configuration.get(\"endpoint\", \"https://api.treasuredata.com\"),\n            apikey=self.configuration.get(\"apikey\"),\n            type=self.configuration.get(\"type\", \"hive\").lower(),\n            db=self.configuration.get(\"db\"),\n        )\n\n        cursor = connection.cursor()\n        try:\n            cursor.execute(query)\n            columns_tuples = [\n                (i[0], TD_TYPES_MAPPING.get(i[1], None))\n                for i in cursor.show_job()[\"hive_result_schema\"]\n            ]\n            columns = self.fetch_columns(columns_tuples)\n\n            if cursor.rowcount == 0:\n                rows = []\n            else:\n                rows = [\n                    dict(zip(([column[\"name\"] for column in columns]), r))\n                    for r in cursor.fetchall()\n                ]\n            data = {\"columns\": columns, \"rows\": rows}\n            json_data = json_dumps(data)\n            error = None\n        except errors.InternalError as e:\n            json_data = None\n            error = \"%s: %s\" % (\n                str(e),\n                cursor.show_job()\n                .get(\"debug\", {})\n                .get(\"stderr\", \"No stderr message in the response\"),\n            )\n        return json_data, error\n\n\nregister(TreasureData)\n", "path": "redash/query_runner/treasuredata.py"}], "after_files": [{"content": "import logging\n\nfrom redash.query_runner import *\nfrom redash.utils import json_dumps\n\nlogger = logging.getLogger(__name__)\n\ntry:\n    import tdclient\n    from tdclient import errors\n\n    enabled = True\n\nexcept ImportError:\n    enabled = False\n\nTD_TYPES_MAPPING = {\n    \"bigint\": TYPE_INTEGER,\n    \"tinyint\": TYPE_INTEGER,\n    \"smallint\": TYPE_INTEGER,\n    \"int\": TYPE_INTEGER,\n    \"integer\": TYPE_INTEGER,\n    \"long\": TYPE_INTEGER,\n    \"double\": TYPE_FLOAT,\n    \"decimal\": TYPE_FLOAT,\n    \"float\": TYPE_FLOAT,\n    \"real\": TYPE_FLOAT,\n    \"boolean\": TYPE_BOOLEAN,\n    \"timestamp\": TYPE_DATETIME,\n    \"date\": TYPE_DATETIME,\n    \"char\": TYPE_STRING,\n    \"string\": TYPE_STRING,\n    \"varchar\": TYPE_STRING,\n}\n\n\nclass TreasureData(BaseQueryRunner):\n    should_annotate_query = False\n    noop_query = \"SELECT 1\"\n\n    @classmethod\n    def configuration_schema(cls):\n        return {\n            \"type\": \"object\",\n            \"properties\": {\n                \"endpoint\": {\"type\": \"string\"},\n                \"apikey\": {\"type\": \"string\"},\n                \"type\": {\"type\": \"string\"},\n                \"db\": {\"type\": \"string\", \"title\": \"Database Name\"},\n                \"get_schema\": {\n                    \"type\": \"boolean\",\n                    \"title\": \"Auto Schema Retrieval\",\n                    \"default\": False,\n                },\n            },\n            \"required\": [\"apikey\", \"db\"],\n        }\n\n    @classmethod\n    def enabled(cls):\n        return enabled\n\n    @classmethod\n    def type(cls):\n        return \"treasuredata\"\n\n    def get_schema(self, get_stats=False):\n        schema = {}\n        if self.configuration.get(\"get_schema\", False):\n            try:\n                with tdclient.Client(self.configuration.get(\"apikey\"),endpoint=self.configuration.get(\"endpoint\")) as client:\n                    for table in client.tables(self.configuration.get(\"db\")):\n                        table_name = \"{}.{}\".format(\n                            self.configuration.get(\"db\"), table.name\n                        )\n                        for table_schema in table.schema:\n                            schema[table_name] = {\n                                \"name\": table_name,\n                                \"columns\": [column[0] for column in table.schema],\n                            }\n            except Exception as ex:\n                raise Exception(\"Failed getting schema\")\n        return list(schema.values())\n\n    def run_query(self, query, user):\n        connection = tdclient.connect(\n            endpoint=self.configuration.get(\"endpoint\", \"https://api.treasuredata.com\"),\n            apikey=self.configuration.get(\"apikey\"),\n            type=self.configuration.get(\"type\", \"hive\").lower(),\n            db=self.configuration.get(\"db\"),\n        )\n\n        cursor = connection.cursor()\n        try:\n            cursor.execute(query)\n            columns_tuples = [\n                (i[0], TD_TYPES_MAPPING.get(i[1], None))\n                for i in cursor.show_job()[\"hive_result_schema\"]\n            ]\n            columns = self.fetch_columns(columns_tuples)\n\n            if cursor.rowcount == 0:\n                rows = []\n            else:\n                rows = [\n                    dict(zip(([column[\"name\"] for column in columns]), r))\n                    for r in cursor.fetchall()\n                ]\n            data = {\"columns\": columns, \"rows\": rows}\n            json_data = json_dumps(data)\n            error = None\n        except errors.InternalError as e:\n            json_data = None\n            error = \"%s: %s\" % (\n                str(e),\n                cursor.show_job()\n                .get(\"debug\", {})\n                .get(\"stderr\", \"No stderr message in the response\"),\n            )\n        return json_data, error\n\n\nregister(TreasureData)\n", "path": "redash/query_runner/treasuredata.py"}]}