Skip to content

Commit

Permalink
Display catalog information on the schema pane when connecting to Tri…
Browse files Browse the repository at this point in the history
…no (#6578)
  • Loading branch information
masayuki038 authored Nov 7, 2023
1 parent 63cef66 commit 198b422
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 18 deletions.
4 changes: 1 addition & 3 deletions redash/query_runner/trino.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,7 @@ def get_schema(self, get_stats=False):
results = json_loads(results)

for row in results["rows"]:
table_name = f'{row["table_schema"]}.{row["table_name"]}'
if not self.configuration.get("catalog"):
table_name = f"{catalog}." + table_name
table_name = f'{catalog}.{row["table_schema"]}.{row["table_name"]}'

if table_name not in schema:
schema[table_name] = {"name": table_name, "columns": []}
Expand Down
21 changes: 6 additions & 15 deletions tests/query_runner/test_trino.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,34 +17,25 @@ class TestTrino(TestCase):
@patch.object(Trino, "_get_catalogs")
@patch.object(Trino, "run_query")
def test_get_schema_no_catalog_set(self, mock_run_query, mock__get_catalogs):
mock_run_query.return_value = (
f'{{"rows": [{{"table_schema": "{TestTrino.schema_name}", "table_name": "{TestTrino.table_name}", "column_name": "{TestTrino.column_name}", "data_type": "{TestTrino.column_type}"}}]}}',
None,
)
mock__get_catalogs.return_value = [TestTrino.catalog_name]
runner = Trino({})
schema = runner.get_schema()
expected_schema = [
{
"name": f"{TestTrino.catalog_name}.{TestTrino.schema_name}.{TestTrino.table_name}",
"columns": [{"name": f"{TestTrino.column_name}", "type": f"{TestTrino.column_type}"}],
}
]
self.assertEqual(schema, expected_schema)
self._assert_schema_catalog(mock_run_query, mock__get_catalogs, runner)

@patch.object(Trino, "_get_catalogs")
@patch.object(Trino, "run_query")
def test_get_schema_catalog_set(self, mock_run_query, mock__get_catalogs):
runner = Trino({"catalog": TestTrino.catalog_name})
self._assert_schema_catalog(mock_run_query, mock__get_catalogs, runner)

def _assert_schema_catalog(self, mock_run_query, mock__get_catalogs, runner):
mock_run_query.return_value = (
f'{{"rows": [{{"table_schema": "{TestTrino.schema_name}", "table_name": "{TestTrino.table_name}", "column_name": "{TestTrino.column_name}", "data_type": "{TestTrino.column_type}"}}]}}',
None,
)
mock__get_catalogs.return_value = [TestTrino.catalog_name]
runner = Trino({"catalog": TestTrino.catalog_name})
schema = runner.get_schema()
expected_schema = [
{
"name": f"{TestTrino.schema_name}.{TestTrino.table_name}",
"name": f"{TestTrino.catalog_name}.{TestTrino.schema_name}.{TestTrino.table_name}",
"columns": [{"name": f"{TestTrino.column_name}", "type": f"{TestTrino.column_type}"}],
}
]
Expand Down

0 comments on commit 198b422

Please sign in to comment.