-
Notifications
You must be signed in to change notification settings - Fork 58
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
Conversation
16cb9a3
to
2bc5392
Compare
d69854a
to
2bcc62e
Compare
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. |
….. LIKE ... based on object name from NativeAppManager and ImageRepositoryManager to a mixin.
998e3fe
to
0d81de0
Compare
There was a problem hiding this 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
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 |
There was a problem hiding this comment.
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
?
There was a problem hiding this comment.
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
, andSqlExecutionMixin
)
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.
#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>
Pre-review checklist
Changes description
Introduced
SqlExecutionMixin.show_specific_object
to share code between all the times we need toshow objects like
in order to get more information about a particular entity.Original author: @sfc-gh-davwang