-
Notifications
You must be signed in to change notification settings - Fork 59
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
Snow 1761248 introduce notebook entity #2007
base: main
Are you sure you want to change the base?
Conversation
|
||
@functools.cached_property | ||
def _connection(self) -> SnowflakeConnection: | ||
return get_cli_context().connection |
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.
These two overwrite properties from parent class without any change. Are they needed?
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.
Nice catch!
I was basing on streamlit_entity implementation, removed
try: | ||
self._sql_executor.execute_query( | ||
f"DESCRIBE NOTEBOOK {self._fqn.sql_identifier}" | ||
) |
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.
The SQL here could be extracted to get_describe_sql
method - would be useful, when adding more actions
Also, maybe action_describe
is the way to go?
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.
done
return self._sql_executor.execute_query(queries) | ||
|
||
def action_deploy( | ||
self, |
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.
If we have action_deploy
- we probably should have an action_drop
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.
It currently won't be used by any command - should we implement it in this PR?
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.
If we introduce an entity- i think we should at least make some dummy methods to show, what is left to implement
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.
I've added placeholders
stage_path = self._notebook_file_stage_path | ||
cli_console.step("Creating notebook") | ||
create_str = "CREATE OR REPLACE" if replace else "CREATE" | ||
queries = dedent( |
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.
Please extract to get_create_sql
- will be useful for creating more actions and if notebooks will be used as native apps children
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.
done
return get_cli_context().connection | ||
|
||
@functools.cached_property | ||
def _fqn(self) -> FQN: |
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.
You can use self.fqn
as well
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.
Changed
|
||
class NotebookEntity(EntityBase[NotebookEntityModel]): | ||
""" | ||
A notebook. |
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.
Indeed 😺
replace: bool = ReplaceOption( | ||
help="Replace existing Notebook if it already exists.", | ||
), | ||
if_not_exists: bool = IfNotExistsOption(help="Skip if Notebook already exists."), |
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.
Current approach was to fail if object exists. Do we plan to add this flag to other commands as well?
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.
For some reason I was sure I've seen that in streamlit; removed
**options, | ||
) -> CommandResult: | ||
"""Uploads a notebook to a stage and creates a notebook. If entity_id is not provided, | ||
deploys all notebooks defined in the project definition.""" |
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.
deploys all notebooks defined in the project definition.""" | |
deploys all notebooks defined in the project definition.""" |
See how streamlit works. Also consider borrowing this helper:
snowflake-cli/src/snowflake/cli/_plugins/streamlit/commands.py
Lines 158 to 163 in 347c46a
streamlit: StreamlitEntityModel = get_entity_for_operation( | |
cli_context=cli_context, | |
entity_id=entity_id, | |
project_definition=pd, | |
entity_type="streamlit", | |
) |
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.
Fixed, nice helper!
Co-authored-by: Tomasz Urbaszek <[email protected]>
Co-authored-by: Tomasz Urbaszek <[email protected]>
stage_path: Optional[str] = Field( | ||
title="Stage directory in which the notebook file will be stored", default=None | ||
) | ||
notebook_file: Path = Field(title="Notebook file") |
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.
Should we consider using artifact approach with notbeook_file being a pointer (similar to streamlit main file)? In this way you can upload more than one file, for example .py file with scripts or a .csv data. WDYT?
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.
Good idea, added
return False | ||
|
||
def _upload_artifacts(self): | ||
stage_fqn = FQN.from_stage(self._stage_path.stage) |
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.
Don't we have _stage.path.get_fqn()
? If not wdyt about adding it?
*args, | ||
**kwargs, | ||
) -> str: | ||
with cli_console.phase(f"Deploying notebook {self.fqn}"): |
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.
Consider splitting this into two phases:
- Uploading artifacts
- Creating notebook
Pre-review checklist
Changes description
Introduce notebook entity and add command
snow notebook deploy
based on entities