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

Add snowpark entities #1959

Open
wants to merge 16 commits into
base: main
Choose a base branch
from

Conversation

sfc-gh-jsikorski
Copy link
Contributor

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 on MacOS.
  • I've confirmed that my changes are working by executing CLI's commands manually on Windows.
  • 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

Basic implementation of snowpark entities - to be updated after introducing bundle map for all entities.

…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
@sfc-gh-jsikorski sfc-gh-jsikorski marked this pull request as ready for review December 20, 2024 13:52
@sfc-gh-jsikorski sfc-gh-jsikorski requested review from a team as code owners December 20, 2024 13:52
@sfc-gh-jsikorski sfc-gh-jsikorski mentioned this pull request Dec 20, 2024
5 tasks
@sfc-gh-jsikorski sfc-gh-jsikorski changed the title Add snowpark entitiers Add snowpark entities Dec 20, 2024

T = TypeVar("T")


class DeployMode(
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
class DeployMode(
class CreateMode(

WDYT?

Copy link
Contributor Author

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")
Copy link
Contributor

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?

Copy link
Contributor Author

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):
Copy link
Contributor

Choose a reason for hiding this comment

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

Please add type hints

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

Comment on lines 49 to 69
@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
Copy link
Contributor

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?

Copy link
Contributor Author

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,
):
Copy link
Contributor

Choose a reason for hiding this comment

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

Please add type hint

Copy link
Contributor Author

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))
Copy link
Contributor

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:

Suggested change
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?

Copy link
Contributor Author

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):
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

Comment on lines 197 to 207
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}"
Copy link
Contributor

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

@sfc-gh-jsikorski sfc-gh-jsikorski force-pushed the jsikorski/snowpark_entities_basic branch from 762aa80 to 801b67d Compare January 9, 2025 11:32
@sfc-gh-jsikorski sfc-gh-jsikorski requested review from sfc-gh-turbaszek and a team January 9, 2025 11:40
@sfc-gh-jsikorski sfc-gh-jsikorski mentioned this pull request Jan 9, 2025
8 tasks
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.

2 participants