Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get view names along with tables #498

Closed
wants to merge 8 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def check_draft_datasource_config(
datasource.test_connection(test_assets=True) # raises `TestConnectionError` on failure

if isinstance(datasource, SQLDatasource):
table_names = self._get_table_names(datasource=datasource)
table_names = self._get_table_names(datasource=datasource, include_views=True)
self._update_table_names_list(config_id=event.config_id, table_names=table_names)

return ActionResult(
Expand All @@ -69,9 +69,12 @@ def check_draft_datasource_config(
created_resources=[],
)

def _get_table_names(self, datasource: Datasource) -> list[str]:
def _get_table_names(self, datasource: Datasource, *, include_views: bool) -> list[str]:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rename to _get_table_and_view_names and remove the boolean flag. We don't have a need for the conditional and it makes the API less clear.

inspector: Inspector = inspect(datasource.get_engine())
return inspector.get_table_names()
names: list[str] = inspector.get_table_names()
if include_views:
names.extend(inspector.get_view_names())
return names

def _update_table_names_list(self, config_id: UUID, table_names: list[str]) -> None:
with create_session(access_token=self._auth_key) as session:
Expand Down
4 changes: 4 additions & 0 deletions great_expectations_cloud/agent/actions/list_table_names.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@


class ListTableNamesAction(AgentAction[ListTableNamesEvent]):
"""Return a list of the current table names (and views) for a given SQL based Datasource using the sqlalchemy inspector."""

# TODO: New actions need to be created that are compatible with GX v1 and registered for v1.
# This action is registered for v0, see register_event_action()

Expand All @@ -36,6 +38,8 @@ def run(self, event: ListTableNamesEvent, id: str) -> ActionResult:

inspector: Inspector = inspect(datasource.get_engine())
table_names: list[str] = inspector.get_table_names()
# consider views as well
table_names.extend(inspector.get_view_names())

self._add_or_update_table_names_list(
datasource_id=str(datasource.id), table_names=table_names
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "great_expectations_cloud"
version = "20241017.0.dev1"
version = "20241021.0.dev0"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

outdated

description = "Great Expectations Cloud"
authors = ["The Great Expectations Team <[email protected]>"]
repository = "https://github.com/great-expectations/cloud"
Expand Down
4 changes: 3 additions & 1 deletion tests/agent/actions/test_draft_datasource_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,9 @@ def test_test_draft_datasource_config_success_sql_ds(
assert action_result.created_resources == []

# assert that the action properly calls helper methods to get table names and update the draft config
_get_table_names_spy.assert_called_with(datasource=datasource_cls(**datasource_config))
_get_table_names_spy.assert_called_with(
datasource=datasource_cls(**datasource_config), include_views=True
)
_update_table_names_list_spy.assert_called_with(config_id=config_id, table_names=table_names)
Comment on lines +173 to 176
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These assertions don't add any value to the test and make refactoring harder. Testing that a method calls a private helper makes no guarantee that what the helper is doing is correct.

These tests is already verifying that the correct endpoint is called with the correct tables/views and that is enough

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some tests here should guarantee that we return views as well



Expand Down
2 changes: 2 additions & 0 deletions tests/agent/actions/test_list_table_names_action.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,10 @@ def test_run_list_table_names_action_returns_action_result(
)

table_names = ["table_1", "table_2", "table_3"]
view_names = ["view_1", "view_2"]
inspector = mocker.Mock(spec=Inspector)
inspector.get_table_names.return_value = table_names
inspector.get_view_names.return_value = view_names
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would expect this test to fail since we're not getting different results. The test should guarantee that we're sending back the correct results


mock_inspect.return_value = inspector

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ def test_running_draft_datasource_config_action(
"organization_users",
"validations",
"api_tokens",
"pg_stat_statements", # view
]
# add spies to the action methods
_get_table_names_spy = mocker.spy(action, "_get_table_names")
Expand Down
1 change: 1 addition & 0 deletions tests/integration/actions/test_list_table_names.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ def test_running_list_table_names_action(
"organization_users",
"user_asset_alerts",
"validations",
"pg_stat_statements",
]

# add spy to the action method
Expand Down
Loading