-
Notifications
You must be signed in to change notification settings - Fork 141
SNOWVATION: Replace parameter boilerplate with utility classes. #2751
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
base: main
Are you sure you want to change the base?
Conversation
72c910b to
0f2d9d2
Compare
| def conf(self) -> RuntimeConfig: | ||
| def conf(self) -> SettingStore: |
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.
we should probably keep the name same for migration sake: https://spark.apache.org/docs/latest/api/python/reference/pyspark.sql/api/pyspark.sql.conf.RuntimeConfig.html
| @pytest.mark.parametrize( | ||
| "parameter_name", | ||
| [ | ||
| "_auto_clean_up_temp_table_enabled", | ||
| "_cte_optimization_enabled", | ||
| "_large_query_breakdown_enabled", | ||
| ], | ||
| "parameter_name", ["auto_clean_up_temp_table_enabled", "cte_optimization_enabled"] | ||
| ) |
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.
merge artifact
| session.auto_clean_up_temp_table_enabled = True | ||
| assert session.auto_clean_up_temp_table_enabled is True | ||
| assert "auto_clean_up_temp_table_enabled is experimental" in caplog.text | ||
| session.auto_clean_up_temp_table_enabled = False |
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.
do we not raise warning only when we enable the param?
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 warning is only raised when setting to a non-default value.
| """ | ||
|
|
||
| name: str | ||
| description: str | None = field(default=None) |
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.
| description: str | None = field(default=None) | |
| description: Optional[str] = field(default=None) |
nit: we follow this style in the repo.
|
would it be easy to cover changes made in this PR: #2673 |
That wouldn't be too hard. I think I'd recommend downgrading from an error to a warning though so that users can be aware that they should clean things up. |
sfc-gh-aalam
left a comment
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.
approving based on
- re-naming
SettingStoretoRuntimeConfigso that we don't change names of classes - adding a simple how-to maybe in contributing.md or config.py
| when all configuration needs to be accessible from a single object. | ||
| """ | ||
|
|
||
| import pkg_resources |
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.
pkg_resources is kinda deprecated, check notes in https://setuptools.pypa.io/en/latest/pkg_resources.html
is it possible to switch to importlib as suggested?
| self._parent is not None | ||
| and (parent_value := self._parent.value) is not None | ||
| ): | ||
| return parent_value |
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.
is there a chance of a multi layer setting such that we need recursion here to get the default value?
A.default = 1
B.parent = A , default = None
C.parent = B, default = None
| name (str): The name of the setting that is used to reference it. | ||
| description (str): A docstring that describes the function of the setting. | ||
| default: (Any): The default value that a setting takes when not otherwise configured. | ||
| read_only (bool): Disallows modification of the setting when set to True. | ||
| experimental_since (str): When set this will warn users that changing the value of this | ||
| setting is experimental and may not be ready for production environments. |
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 just came to my mind that do we want a field for "deprecation"?
not blocking this PR as we can add in the future
| parameter_name (str): The name of the session parameter that holds the value for this setting. | ||
| synchronize (bool): When set to True the server side session parameter will be updated when | ||
| this settings value is changed. | ||
| telemetry_hook (Callable): A callback function that allows emitting telemetry when thissettings |
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.
nit
| telemetry_hook (Callable): A callback function that allows emitting telemetry when thissettings | |
| telemetry_hook (Callable): A callback function that allows emitting telemetry when this |
| return getattr(self._session._conn._conn, key) | ||
| return self._conf.get(key, default) | ||
|
|
||
| def is_mutable(self, key: str) -> bool: |
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 don't see is_mutable is implemented the new config class?
| def is_feature_enabled_for_version(self, parameter_name: str) -> bool: | ||
| """ | ||
| This method checks if a feature is enabled for the current session based on | ||
| the server side parameter. | ||
| """ | ||
| version = self._conn._get_client_side_session_parameter(parameter_name, "") | ||
| return ( | ||
| isinstance(version, str) | ||
| and version != "" | ||
| and pkg_resources.parse_version(self.version) | ||
| >= pkg_resources.parse_version(version) | ||
| ) | ||
|
|
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.
shall we keep this? removing this is a BCR, also I feel this func can be helpful to users
Which Jira issue is this PR addressing? Make sure that there is an accompanying issue to your PR.
Fixes SNOW-NNNNNNN
Fill out the following pre-review checklist:
Please describe how your code solves the related issue.
The goal of this refactor is to provide a central location for defining parameters and other snowpark-python configuration. This should make it easier to add additional parameters in the future as well as gate more deprecated or exerimental logic behind parameters.
Session parmeters are now all added in
Session._initialize_config. All definition needed for them should happen there.Package level confuguration settings should similarly all be defined in src/snowflake/snowpark/_internal/config.py
Parameters and package level configs can all be accessed via session.conf.
As part of this change I've moved all of the session level parameters over to the new settings style, but there are likely package level configuration options that I have missed. For now the parameters that are exposed as properties of the session object remain available in this manner, but in the future we should standardize the access method to be through the config object.