Skip to content
This repository has been archived by the owner on Nov 3, 2023. It is now read-only.

Commit

Permalink
fix: Presto _show_columns return type (apache#20757)
Browse files Browse the repository at this point in the history
(cherry picked from commit 8c0ac90)
  • Loading branch information
john-bodley committed Jul 19, 2022
1 parent bc10ada commit 384107a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
3 changes: 1 addition & 2 deletions superset/db_engine_specs/presto.py
Original file line number Diff line number Diff line change
Expand Up @@ -442,8 +442,7 @@ def _show_columns(
full_table = quote(table_name)
if schema:
full_table = "{}.{}".format(quote(schema), full_table)
columns = inspector.bind.execute("SHOW COLUMNS FROM {}".format(full_table))
return columns
return inspector.bind.execute(f"SHOW COLUMNS FROM {full_table}").fetchall()

column_type_mappings = (
(
Expand Down
18 changes: 11 additions & 7 deletions tests/integration_tests/db_engine_specs/presto_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ def verify_presto_column(self, column, expected_results):
"Null": (None, None, 2),
}
row = RowProxy(mock.Mock(), column, [None, None, None, None], keymap)
inspector.bind.execute = mock.Mock(return_value=[row])
inspector.bind.execute.return_value.fetchall = mock.Mock(return_value=[row])
results = PrestoEngineSpec.get_columns(inspector, "", "")
self.assertEqual(len(expected_results), len(results))
for expected_result, result in zip(expected_results, results):
Expand Down Expand Up @@ -749,25 +749,29 @@ def test_show_columns(self):
inspector.engine.dialect.identifier_preparer.quote_identifier = (
lambda x: f'"{x}"'
)
mock_execute = mock.MagicMock(return_value=["a", "b"])
inspector.bind.execute = mock_execute
inspector.bind.execute.return_value.fetchall = mock.MagicMock(
return_value=["a", "b"]
)
table_name = "table_name"
result = PrestoEngineSpec._show_columns(inspector, table_name, None)
assert result == ["a", "b"]
mock_execute.assert_called_once_with(f'SHOW COLUMNS FROM "{table_name}"')
inspector.bind.execute.assert_called_once_with(
f'SHOW COLUMNS FROM "{table_name}"'
)

def test_show_columns_with_schema(self):
inspector = mock.MagicMock()
inspector.engine.dialect.identifier_preparer.quote_identifier = (
lambda x: f'"{x}"'
)
mock_execute = mock.MagicMock(return_value=["a", "b"])
inspector.bind.execute = mock_execute
inspector.bind.execute.return_value.fetchall = mock.MagicMock(
return_value=["a", "b"]
)
table_name = "table_name"
schema = "schema"
result = PrestoEngineSpec._show_columns(inspector, table_name, schema)
assert result == ["a", "b"]
mock_execute.assert_called_once_with(
inspector.bind.execute.assert_called_once_with(
f'SHOW COLUMNS FROM "{schema}"."{table_name}"'
)

Expand Down

0 comments on commit 384107a

Please sign in to comment.