diff --git a/redash/query_runner/trino.py b/redash/query_runner/trino.py index a5e0457a4e..c1fb082363 100644 --- a/redash/query_runner/trino.py +++ b/redash/query_runner/trino.py @@ -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": []} diff --git a/tests/query_runner/test_trino.py b/tests/query_runner/test_trino.py index 195c4de24a..87e5dd8b00 100644 --- a/tests/query_runner/test_trino.py +++ b/tests/query_runner/test_trino.py @@ -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}"}], } ]