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

Create a pattern for drilling down to a single "show objects like" row #748

Merged
merged 11 commits into from
Feb 13, 2024

Conversation

sfc-gh-cgorrie
Copy link
Contributor

@sfc-gh-cgorrie sfc-gh-cgorrie commented Feb 7, 2024

Pre-review checklist

  • I've confirmed that instructions included in README.md are still correct after my changes in the codebase.
  • I've added or updated automated unit tests to verify correctness of my new code.
  • I've added or updated integration tests to verify correctness of my new code.
  • I've confirmed that my changes are working by executing CLI's commands manually.
  • I've confirmed that my changes are up-to-date with the target branch.
  • I've described my changes in the release notes.
  • I've described my changes in the section below.

Changes description

Introduced SqlExecutionMixin.show_specific_object to share code between all the times we need to show objects like in order to get more information about a particular entity.

Original author: @sfc-gh-davwang

@sfc-gh-cgorrie sfc-gh-cgorrie force-pushed the refactor-get-object-row branch from 16cb9a3 to 2bc5392 Compare February 8, 2024 16:51
@sfc-gh-cgorrie sfc-gh-cgorrie marked this pull request as ready for review February 8, 2024 19:21
@sfc-gh-cgorrie sfc-gh-cgorrie force-pushed the refactor-get-object-row branch from d69854a to 2bcc62e Compare February 8, 2024 22:01
sfc-gh-davwang
sfc-gh-davwang previously approved these changes Feb 8, 2024
tests/nativeapp/test_manager.py Show resolved Hide resolved
@sfc-gh-davwang
Copy link
Contributor

sfc-gh-davwang commented Feb 8, 2024

if you're amenable to including it, here's a PR to use your new function in image_registry/manager: #755. Feel free to merge it in yourself if you approve.

sfc-gh-astus
sfc-gh-astus previously approved these changes Feb 9, 2024
Copy link
Contributor

@sfc-gh-bgoel sfc-gh-bgoel left a comment

Choose a reason for hiding this comment

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

LGTM for both Project and NA

Comment on lines +147 to +169
def show_specific_object(
self,
object_type_plural: str,
unqualified_name: str,
name_col: str = "name",
in_clause: str = "",
) -> Optional[dict]:
"""
Executes a "show <objects> like" query for a particular entity with a
given (unqualified) name. This command is useful when the corresponding
"describe <object>" query does not provide the information you seek.
"""
show_obj_query = f"show {object_type_plural} like {identifier_to_show_like_pattern(unqualified_name)} {in_clause}".strip()
show_obj_cursor = self._execute_query( # type: ignore
show_obj_query, cursor_class=DictCursor
)
if show_obj_cursor.rowcount is None:
raise SnowflakeSQLExecutionError(show_obj_query)
show_obj_row = find_first_row(
show_obj_cursor,
lambda row: row[name_col] == unquote_identifier(unqualified_name),
)
return show_obj_row
Copy link
Contributor

Choose a reason for hiding this comment

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

Why it's there not in ObjectManager?

Copy link
Contributor Author

@sfc-gh-cgorrie sfc-gh-cgorrie Feb 12, 2024

Choose a reason for hiding this comment

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

To me, that's a different layer. My mental model of layers:

  • command "spec" / app layer (i.e. commands.py)
  • command implementation layer (i.e. managers; e.g. ObjectManager.py)
  • utility layer (e.g. utils/*.py, and SqlExecutionMixin)

Suppose we were to put it in ObjectManager. Other managers that want to use it would have to instantiate an ObjectManager(), then call this. Right now there's no args for the constructor but I'm not sure we can count on that going forward given the design (e.g. if we ever needed to support multiple concurrent connections). So this felt like the cleanest place to put it, aside from the architectural concern noted above.

@sfc-gh-cgorrie sfc-gh-cgorrie merged commit 00414d5 into main Feb 13, 2024
17 checks passed
@sfc-gh-cgorrie sfc-gh-cgorrie deleted the refactor-get-object-row branch February 13, 2024 16:46
sfc-gh-sichen pushed a commit that referenced this pull request Oct 17, 2024
#748)

* SNOW-1011766: Factoring out shared logic of getting a row from SHOW ... LIKE ... based on object name from NativeAppManager and ImageRepositoryManager to a mixin.

* Adding identifier_to_show_like_pattern

* move show_specific_object to SqlExecutionMixin

* add test and remove TODO

* CR review

* using show_specific_object in image_repository.manager.get_repository_url (#755)

---------

Co-authored-by: David Wang <d.wang@snowflake.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants