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-1623378: Support mocking functions that are not supported in snowpark #2076

Closed
GuyOmer opened this issue Aug 13, 2024 · 2 comments
Closed
Assignees
Labels
feature New feature or request local testing Local Testing issues/PRs

Comments

@GuyOmer
Copy link

GuyOmer commented Aug 13, 2024

What is the current behavior?

Trying to mock a non snowpark function (like greatest_ignore_nulls) results in an exception.

@patch("greatest_ignore_nulls")
def mock_GREATEST_IGNORE_NULLS(*columns: Iterable[ColumnEmulator]) -> ColumnEmulator:
    ....

# Results in
# NotImplementedError: [Local Testing] Function greatest_ignore_nulls is not supported in snowpark-python.

What is the desired behavior?

Same mocking API.

If this is not an existing feature in snowflake-snowpark-python. How would this impact/improve non-local testing mode?

This will be a complementary feature to using call_function.

References, Other Background

Additionally, it is not possible to mock call_function.

@GuyOmer GuyOmer added feature New feature or request local testing Local Testing issues/PRs labels Aug 13, 2024
@github-actions github-actions bot changed the title Support mocking functions that are not supported in snowpark SNOW-1623378: Support mocking functions that are not supported in snowpark Aug 13, 2024
@sfc-gh-aling
Copy link
Contributor

sfc-gh-aling commented Aug 20, 2024

hey @GuyOmer , thanks for reaching out.

this is because greatest_ignore_nulls is not implemented in the snowpark python library, for now the patch only works for functions available in snowflake.snowpark.functions.

one workaround is to manually add a fake greatest_ignore_nulls function into the functions module as below:

import snowflake.snowpark.functions
from snowflake.snowpark import Session, Column
from snowflake.snowpark._internal.type_utils import ColumnOrName
from snowflake.snowpark.functions import call_function
from snowflake.snowpark.mock import patch, ColumnEmulator, ColumnType
from snowflake.snowpark.types import IntegerType

session = Session.builder.configs({"local_testing": True}).create()

# this is just a placeholder, implementation does not matter
def fake_greatest_ignore_nulls(*columns: ColumnOrName) -> Column:
    return None

@patch("greatest_ignore_nulls")
def mock_GREATEST_IGNORE_NULLS(*columns) -> ColumnEmulator:
    return ColumnEmulator([1], sf_type=ColumnType(IntegerType(), nullable=False))

# dynamically add function to module so that local test can find it
snowflake.snowpark.functions.greatest_ignore_nulls = fake_greatest_ignore_nulls

df = session.create_dataframe(
    [1, 2, 3, 4],
    schema=["a"]
)
df.select(call_function("greatest_ignore_nulls", df["a"])).show()

I agree we should provide a better way to patch functions not defined in the functions.py module

@sfc-gh-jrose
Copy link
Contributor

Support for this usecase should be released in v1.25.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New feature or request local testing Local Testing issues/PRs
Projects
None yet
Development

No branches or pull requests

3 participants