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

[SNOW-1791241] Add a session parameter to disable scoped read only temp table #2587

Merged
merged 3 commits into from
Nov 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
- Treat an empty `subset` (e.g. `[]`) as if it specified all columns instead of no columns.
- Raise a `TypeError` for a scalar `subset` instead of filtering on just that column.
- Raise a `ValueError` for a `subset` of type `pandas.Index` instead of filtering on the columns in the index.
- Disable creation of scoped read only table to mitigate Disable creation of scoped read only table to mitigate `TableNotFoundError` when using dynamic pivot in notebook environment.

#### Improvements
- Improve np.where with scalar x value by eliminating unnecessary join and temp table creation.
Expand Down
2 changes: 1 addition & 1 deletion src/snowflake/snowpark/modin/plugin/_internal/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ def _create_read_only_table(
readonly_table_name = (
f"{random_name_for_temp_object(TempObjectType.TABLE)}{READ_ONLY_TABLE_SUFFIX}"
)
use_scoped_temp_table = session._use_scoped_temp_objects
use_scoped_temp_table = session._use_scoped_temp_read_only_table
# If we need to materialize into a temp table our create table expression
# needs to be SELECT * FROM (object).
if materialize_into_temp_table:
Expand Down
9 changes: 9 additions & 0 deletions src/snowflake/snowpark/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,10 @@
_PYTHON_SNOWPARK_ENABLE_THREAD_SAFE_SESSION = (
"PYTHON_SNOWPARK_ENABLE_THREAD_SAFE_SESSION"
)
# Flag for controlling the usage of scoped temp read only table.
_PYTHON_SNOWPARK_ENABLE_SCOPED_TEMP_READ_ONLY_TABLE = (
"PYTHON_SNOWPARK_ENABLE_SCOPED_TEMP_READ_ONLY_TABLE"
)
# The complexity score lower bound is set to match COMPILATION_MEMORY_LIMIT
# in Snowflake. This is the limit where we start seeing compilation errors.
DEFAULT_COMPLEXITY_SCORE_LOWER_BOUND = 10_000_000
Expand Down Expand Up @@ -541,6 +545,11 @@ def __init__(
_PYTHON_SNOWPARK_USE_SCOPED_TEMP_OBJECTS_STRING, True
)
)
self._use_scoped_temp_read_only_table: bool = (
self._conn._get_client_side_session_parameter(
_PYTHON_SNOWPARK_ENABLE_SCOPED_TEMP_READ_ONLY_TABLE, False
Comment on lines +549 to +550

Choose a reason for hiding this comment

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

If it's for native app, I think it's easier to look up from self._conn._conn._session_parameters['<param_name>'], similar to what we did for ENABLE_FIX_1375538, WDYT @sfc-gh-sfan?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

oh, i believe that function does look into the _conn._session_parameters, here is the implementation

    def _get_client_side_session_parameter(self, name: str, default_value: Any) -> Any:
        """It doesn't go to Snowflake to retrieve the session parameter.
        Use this only when you know the Snowflake session parameter is sent to the client when a session/connection is created.
        """
        return (
            self._conn._session_parameters.get(name, default_value)
            if self._conn._session_parameters
            else default_value
        )

Choose a reason for hiding this comment

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

Cool! I think you need to define a server side parameter too, similar to PYTHON_SNOWPARK_ENABLE_THREAD_SAFE_SESSION above: https://sourcegraph.c2.us-central1.gcp-dev.app.snowflake.com/github.com/snowflakedb/snowflake/-/blob/GlobalServices/src/main/java/com/snowflake/core/parameters/SnowparkEcosystemParameters.java?L774:42

And default it to false.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@sfc-gh-deliu i will follow up with you on this, i though you mentioned that i don't need a server side parameter, and you can set this up in the session automatically

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@sfc-gh-deliu i double checked with @sfc-gh-sfan , we do not need a definition for this parameter at server side. but he suggest we have a parameter control for turning this on for native app. I think we can do that when doing the server side change

)
)
self._file = FileOperation(self)
self._lineage = Lineage(self)
self._sql_simplifier_enabled: bool = (
Expand Down
8 changes: 4 additions & 4 deletions tests/integ/modin/io/test_read_snowflake.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,10 @@

@pytest.fixture(params=paramList)
def setup_use_scoped_object(request, session):
use_scoped_objects = session._use_scoped_temp_objects
session._use_scoped_temp_objects = request.param
use_scoped_objects = session._use_scoped_temp_read_only_table
session._use_scoped_temp_read_only_table = request.param
yield
session._use_scoped_temp_objects = use_scoped_objects
session._use_scoped_temp_read_only_table = use_scoped_objects


def read_snowflake_and_verify_snapshot_creation(
Expand Down Expand Up @@ -85,7 +85,7 @@ def read_snowflake_and_verify_snapshot_creation(
assert len(query_history.queries) == 1

# test if the scoped snapshot is created
scoped_pattern = " SCOPED " if session._use_scoped_temp_objects else " "
scoped_pattern = " SCOPED " if session._use_scoped_temp_read_only_table else " "
table_create_sql = query_history.queries[-1].sql_text
table_create_pattern = f"CREATE OR REPLACE{scoped_pattern}TEMPORARY READ ONLY TABLE SNOWPARK_TEMP_TABLE_[0-9A-Z]+.*{READ_ONLY_TABLE_SUFFIX}.*"
assert re.match(table_create_pattern, table_create_sql) is not None
Expand Down
Loading