-
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
Add snowpark entities #1959
base: main
Are you sure you want to change the base?
Add snowpark entities #1959
Conversation
…ntities # Conflicts: # tests/streamlit/__snapshots__/test_commands.ambr # tests/test_data/projects/example_streamlit_v2/snowflake.yml
…tities_basic # Conflicts: # src/snowflake/cli/_plugins/streamlit/streamlit_entity.py
|
||
T = TypeVar("T") | ||
|
||
|
||
class DeployMode( |
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.
class DeployMode( | |
class CreateMode( |
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.
Done
if not FeatureFlag.ENABLE_NATIVE_APP_CHILDREN.is_enabled(): | ||
raise NotImplementedError("Snowpark entity is not implemented yet") |
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.
What's the reasoning behind this flag?
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 was introduced in #1856
As we are not introducing entities in commands just yet, it seems reasonable to turn them off by default.
super().__init__(*args, **kwargs) | ||
|
||
@property | ||
def root(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.
Please add type hints
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
@property | ||
def identifier(self): | ||
return self.model.fqn.sql_identifier | ||
|
||
@property | ||
def fqn(self): | ||
return self.model.fqn | ||
|
||
@functools.cached_property | ||
def _sql_executor( | ||
self, | ||
): # maybe this could be moved to parent class, as it is used in streamlit entity as well | ||
return get_sql_executor() | ||
|
||
@functools.cached_property | ||
def _conn(self): | ||
return self._sql_executor._conn # noqa | ||
|
||
@property | ||
def model(self): | ||
return self._entity_model # noqa |
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.
Probably those properties can be move to some generic class, 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.
Done
allow_shared_libraries: bool = False, | ||
*args, | ||
**kwargs, | ||
): |
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 add type hint
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
self, action_ctx: ActionContext, mode: DeployMode, *args, **kwargs | ||
): | ||
# TODO: After introducing bundle map, we should introduce file copying part here | ||
return self._sql_executor.execute_query(self.get_deploy_sql(mode)) |
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.
There's a bit of repetition in this approach:
return self._sql_executor.execute_query(self.get_deploy_sql(mode)) | |
return self._sql_executor.execute_query(self.get_deploy_sql(mode)) |
have you considered something like
self._execute(self.get_deploy_sql(mode))
or builder pattern:
self.get_deploy_sql(mode).execute()
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.
Done
def get_execute_sql(self, execution_arguments: List[str] | None = None): | ||
raise NotImplementedError | ||
|
||
def get_usage_grant_sql(self, app_role: str): |
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.
def get_usage_grant_sql(self, app_role: str): | |
def get_usage_grant_sql(self, role: str): |
There's nothing app specific in this query as far as I can tell
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
def get_describe_sql(self): | ||
return f"DESCRIBE {self.model.type.upper()} {self.identifier}" | ||
|
||
def get_drop_sql(self): | ||
return f"DROP {self.model.type.upper()} {self.identifier}" | ||
|
||
def get_execute_sql(self, execution_arguments: List[str] | None = None): | ||
raise NotImplementedError | ||
|
||
def get_usage_grant_sql(self, app_role: str): | ||
return f"GRANT USAGE ON {self.model.type.upper()} {self.identifier} TO ROLE {app_role}" |
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 candidates to extract to parent, generic class.
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
762aa80
to
801b67d
Compare
Pre-review checklist
Changes description
Basic implementation of snowpark entities - to be updated after introducing bundle map for all entities.