-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[NADE] Enable Code Generation by default in Snow App Bundle (#1167)
- Loading branch information
1 parent
0970371
commit 1db08f3
Showing
23 changed files
with
778 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
# serializer version: 1 | ||
# name: test_full_lifecycle_with_codegen | ||
dict_values(['echo_proc: test']) | ||
# --- | ||
# name: test_full_lifecycle_with_codegen.1 | ||
dict_values(['echo_fn: test']) | ||
# --- | ||
# name: test_full_lifecycle_with_codegen.10 | ||
dict_values([10]) | ||
# --- | ||
# name: test_full_lifecycle_with_codegen.2 | ||
dict_values(['echo_fn: infile: test']) | ||
# --- | ||
# name: test_full_lifecycle_with_codegen.3 | ||
dict_values(['echo_fn: test']) | ||
# --- | ||
# name: test_full_lifecycle_with_codegen.4 | ||
dict_values(['echo_fn: test']) | ||
# --- | ||
# name: test_full_lifecycle_with_codegen.5 | ||
dict_values([3]) | ||
# --- | ||
# name: test_full_lifecycle_with_codegen.6 | ||
dict_values([10]) | ||
# --- | ||
# name: test_full_lifecycle_with_codegen.7 | ||
''' | ||
[ | ||
{ | ||
"NUMBER": 1 | ||
}, | ||
{ | ||
"NUMBER": -1 | ||
}, | ||
{ | ||
"NUMBER": 1 | ||
}, | ||
{ | ||
"NUMBER": -1 | ||
}, | ||
{ | ||
"NUMBER": 1 | ||
}, | ||
{ | ||
"NUMBER": -1 | ||
}, | ||
{ | ||
"NUMBER": 1 | ||
}, | ||
{ | ||
"NUMBER": -1 | ||
}, | ||
{ | ||
"NUMBER": 1 | ||
}, | ||
{ | ||
"NUMBER": -1 | ||
} | ||
] | ||
|
||
''' | ||
# --- | ||
# name: test_full_lifecycle_with_codegen.8 | ||
dict_values(['echo_fn: infile: test']) | ||
# --- | ||
# name: test_full_lifecycle_with_codegen.9 | ||
''' | ||
[ | ||
{ | ||
"NUMBER": 1 | ||
}, | ||
{ | ||
"NUMBER": -1 | ||
}, | ||
{ | ||
"NUMBER": 1 | ||
}, | ||
{ | ||
"NUMBER": -1 | ||
}, | ||
{ | ||
"NUMBER": 1 | ||
}, | ||
{ | ||
"NUMBER": -1 | ||
}, | ||
{ | ||
"NUMBER": 1 | ||
}, | ||
{ | ||
"NUMBER": -1 | ||
}, | ||
{ | ||
"NUMBER": 1 | ||
}, | ||
{ | ||
"NUMBER": -1 | ||
} | ||
] | ||
|
||
''' | ||
# --- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
snowflake.local.yml | ||
output/ | ||
**/__pycache__/ | ||
**/.pytest_cache/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
# Copyright (c) 2024 Snowflake Inc. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
from snowflake.snowpark.functions import sproc, udf | ||
from snowflake.snowpark.types import IntegerType | ||
|
||
|
||
def helper_fn(data: str) -> str: | ||
return "infile: " + data | ||
|
||
|
||
@udf( | ||
name="echo_fn_1", | ||
native_app_params={ | ||
"schema": "ext_code_schema", | ||
"application_roles": ["app_instance_role"], | ||
}, | ||
) | ||
def echo_fn_1(echo: str) -> str: | ||
return "echo_fn: " + helper_fn(echo) | ||
|
||
|
||
# UDF name is given, imports and packages are empty, native_app_params empty, should be in the final output | ||
@udf( | ||
name="echo_fn_2", | ||
native_app_params={ | ||
"schema": "ext_code_schema", | ||
"application_roles": ["app_instance_role"], | ||
}, | ||
) | ||
def echo_fn_2(echo: str) -> str: | ||
return "echo_fn: " + echo | ||
|
||
|
||
# Inconsequential UDF Params, should have no effect on the DDL, should be in the final output | ||
@udf( | ||
name="echo_fn_4", | ||
is_permanent=True, | ||
stage_location="@some_stage", | ||
replace=False, | ||
if_not_exists=True, | ||
session=None, | ||
parallel=4, | ||
max_batch_size=2, | ||
statement_params={}, | ||
strict=True, | ||
secure=True, | ||
immutable=True, | ||
comment="some comment", | ||
native_app_params={ | ||
"schema": "ext_code_schema", | ||
"application_roles": ["app_instance_role"], | ||
}, | ||
) | ||
def echo_fn_4(echo: str) -> str: | ||
return "echo_fn: " + echo | ||
|
||
|
||
@sproc( | ||
return_type=IntegerType(), | ||
input_types=[IntegerType(), IntegerType()], | ||
packages=["snowflake-snowpark-python"], | ||
native_app_params={ | ||
"schema": "ext_code_schema", | ||
"application_roles": ["app_instance_role"], | ||
}, | ||
) | ||
def add_sp(session_, x, y): | ||
return x + y |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
# Copyright (c) 2024 Snowflake Inc. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
from snowflake.snowpark.functions import udf | ||
|
||
|
||
# Should be rejected by Snowpark since type hints are absent, sql should not be in the final output. | ||
@udf(name="echo_fn_2") | ||
def echo_fn_2(echo) -> str: | ||
return "echo_fn: " + echo | ||
|
||
|
||
""" | ||
Warning message generated by the CLI on skipping this file: | ||
Could not fetch Snowpark objects from /Users/bgoel/snowcli/tests_e2e/test_data/nativeapp/python/cli_gen/errors/e1.py due to the following Snowpark-internal error: | ||
An exception occurred while executing file: the number of arguments (1) is different from the number of argument type hints (0) | ||
""" |
Oops, something went wrong.