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

feat: Basic functions implementation #3269

Merged
merged 45 commits into from
Dec 12, 2024
Merged
Show file tree
Hide file tree
Changes from 43 commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
cd6cf4d
functions basic impl starts here
sfc-gh-asawicki Dec 10, 2024
8c53454
Add common delete for function resources
sfc-gh-asawicki Dec 10, 2024
3a8fd05
Add common delete for procedure resources
sfc-gh-asawicki Dec 10, 2024
9600673
Start basic java function implementation
sfc-gh-asawicki Dec 10, 2024
944f67f
Prepare read function for java function
sfc-gh-asawicki Dec 10, 2024
9239648
Prepare update function for java function
sfc-gh-asawicki Dec 10, 2024
6a81447
Pass first java function resource test
sfc-gh-asawicki Dec 10, 2024
3d34f25
Add missing schema to procedures too
sfc-gh-asawicki Dec 10, 2024
ecbcd3d
Fix check destroy
sfc-gh-asawicki Dec 10, 2024
b7ecf3c
Prepare function parameters test (WIP)
sfc-gh-asawicki Dec 10, 2024
684389a
Fix check destroy
sfc-gh-asawicki Dec 11, 2024
add6010
Pass parameters test for java function
sfc-gh-asawicki Dec 11, 2024
2fd37ce
Continue with create and read
sfc-gh-asawicki Dec 11, 2024
7ea11ba
Add note about return type
sfc-gh-asawicki Dec 11, 2024
fbb6c09
Add recreation
sfc-gh-asawicki Dec 11, 2024
e6c9dbf
Prepare language change test
sfc-gh-asawicki Dec 11, 2024
1937a9e
Prepare basic staged setup
sfc-gh-asawicki Dec 11, 2024
f57c04b
Check behavior for stage other than user's
sfc-gh-asawicki Dec 11, 2024
62927be
Parse import location
sfc-gh-asawicki Dec 11, 2024
b53d053
Assert import location correct
sfc-gh-asawicki Dec 11, 2024
e3cc9fb
Add import assertions to every function test
sfc-gh-asawicki Dec 11, 2024
d7a2602
Change imports schema
sfc-gh-asawicki Dec 11, 2024
7613493
Prepare import handling
sfc-gh-asawicki Dec 11, 2024
369fc86
Run make pre-push
sfc-gh-asawicki Dec 11, 2024
6acfc14
Pass test with external type change
sfc-gh-asawicki Dec 11, 2024
52fa10d
Add basic test for staged
sfc-gh-asawicki Dec 11, 2024
92589be
Assert imports
sfc-gh-asawicki Dec 11, 2024
fdb6482
Prepare target path parsing
sfc-gh-asawicki Dec 11, 2024
7e53d4a
Add target path logic
sfc-gh-asawicki Dec 11, 2024
181536a
Test setting target path
sfc-gh-asawicki Dec 11, 2024
bd1c97e
Test setting runtime version
sfc-gh-asawicki Dec 11, 2024
0d90e67
Handle return type
sfc-gh-asawicki Dec 11, 2024
a5fc8f5
Update TODO comments
sfc-gh-asawicki Dec 11, 2024
6ce0e50
Prepare signature parsing
sfc-gh-asawicki Dec 11, 2024
632e297
Test default values
sfc-gh-asawicki Dec 11, 2024
bbae0ee
Set arguments in read
sfc-gh-asawicki Dec 11, 2024
bdebe4c
Test argument parsing
sfc-gh-asawicki Dec 11, 2024
ab8c894
dd new assertions in integration tests
sfc-gh-asawicki Dec 11, 2024
40ba6b3
Update TODOs
sfc-gh-asawicki Dec 11, 2024
15e0714
Update TODOs part 2
sfc-gh-asawicki Dec 11, 2024
60d663c
Test no arguments and default values
sfc-gh-asawicki Dec 11, 2024
391bb3a
Regenerate model builders
sfc-gh-asawicki Dec 11, 2024
20601b1
Run make pre-push
sfc-gh-asawicki Dec 11, 2024
2eef779
Fix procedures integration tests
sfc-gh-asawicki Dec 11, 2024
afaba5a
Fix after review
sfc-gh-asawicki Dec 11, 2024
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
86 changes: 78 additions & 8 deletions docs/resources/function_java.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ Resource used to manage java function objects. For more information, check [func
### Required

- `database` (String) The database in which to create the function. Due to technical limitations (read more [here](https://github.com/Snowflake-Labs/terraform-provider-snowflake/blob/main/docs/technical-documentation/identifiers_rework_design_decisions.md#known-limitations-and-identifier-recommendations)), avoid using the following characters: `|`, `.`, `"`.
- `function_definition` (String) Defines the handler code executed when the UDF is called. Wrapping `$$` signs are added by the provider automatically; do not include them. The `function_definition` value must be Java source code. For more information, see [Introduction to Java UDFs](https://docs.snowflake.com/en/developer-guide/udf/java/udf-java-introduction). To mitigate permadiff on this field, the provider replaces blank characters with a space. This can lead to false positives in cases where a change in case or run of whitespace is semantically significant.
- `handler` (String) The name of the handler method or class. If the handler is for a scalar UDF, returning a non-tabular value, the HANDLER value should be a method name, as in the following form: `MyClass.myMethod`. If the handler is for a tabular UDF, the HANDLER value should be the name of a handler class.
- `name` (String) The name of the function; the identifier does not need to be unique for the schema in which the function is created because UDFs are identified and resolved by the combination of the name and argument types. Check the [docs](https://docs.snowflake.com/en/sql-reference/sql/create-function#all-languages). Due to technical limitations (read more [here](https://github.com/Snowflake-Labs/terraform-provider-snowflake/blob/main/docs/technical-documentation/identifiers_rework_design_decisions.md#known-limitations-and-identifier-recommendations)), avoid using the following characters: `|`, `.`, `"`.
- `return_type` (String) Specifies the results returned by the UDF, which determines the UDF type. Use `<result_data_type>` to create a scalar UDF that returns a single value with the specified data type. Use `TABLE (col_name col_data_type, ...)` to creates a table UDF that returns tabular results with the specified table column(s) and column type(s). For the details, consult the [docs](https://docs.snowflake.com/en/sql-reference/sql/create-function#all-languages).
Expand All @@ -29,16 +28,17 @@ Resource used to manage java function objects. For more information, check [func
- `comment` (String) Specifies a comment for the function.
- `enable_console_output` (Boolean) Enable stdout/stderr fast path logging for anonyous stored procs. This is a public parameter (similar to LOG_LEVEL). For more information, check [ENABLE_CONSOLE_OUTPUT docs](https://docs.snowflake.com/en/sql-reference/parameters#enable-console-output).
- `external_access_integrations` (Set of String) The names of [external access integrations](https://docs.snowflake.com/en/sql-reference/sql/create-external-access-integration) needed in order for this function’s handler code to access external networks. An external access integration specifies [network rules](https://docs.snowflake.com/en/sql-reference/sql/create-network-rule) and [secrets](https://docs.snowflake.com/en/sql-reference/sql/create-secret) that specify external locations and credentials (if any) allowed for use by handler code when making requests of an external network, such as an external REST API.
- `imports` (Set of String) The location (stage), path, and name of the file(s) to import. A file can be a JAR file or another type of file. If the file is a JAR file, it can contain one or more .class files and zero or more resource files. JNI (Java Native Interface) is not supported. Snowflake prohibits loading libraries that contain native code (as opposed to Java bytecode). Java UDFs can also read non-JAR files. For an example, see [Reading a file specified statically in IMPORTS](https://docs.snowflake.com/en/developer-guide/udf/java/udf-java-cookbook.html#label-reading-file-from-java-udf-imports). Consult the [docs](https://docs.snowflake.com/en/sql-reference/sql/create-function#java).
- `function_definition` (String) Defines the handler code executed when the UDF is called. Wrapping `$$` signs are added by the provider automatically; do not include them. The `function_definition` value must be Java source code. For more information, see [Introduction to Java UDFs](https://docs.snowflake.com/en/developer-guide/udf/java/udf-java-introduction). To mitigate permadiff on this field, the provider replaces blank characters with a space. This can lead to false positives in cases where a change in case or run of whitespace is semantically significant.
- `imports` (Block Set) The location (stage), path, and name of the file(s) to import. A file can be a JAR file or another type of file. If the file is a JAR file, it can contain one or more .class files and zero or more resource files. JNI (Java Native Interface) is not supported. Snowflake prohibits loading libraries that contain native code (as opposed to Java bytecode). Java UDFs can also read non-JAR files. For an example, see [Reading a file specified statically in IMPORTS](https://docs.snowflake.com/en/developer-guide/udf/java/udf-java-cookbook.html#label-reading-file-from-java-udf-imports). Consult the [docs](https://docs.snowflake.com/en/sql-reference/sql/create-function#java). (see [below for nested schema](#nestedblock--imports))
- `is_secure` (String) Specifies that the function is secure. By design, the Snowflake's `SHOW FUNCTIONS` command does not provide information about secure functions (consult [function docs](https://docs.snowflake.com/en/sql-reference/sql/create-function#id1) and [Protecting Sensitive Information with Secure UDFs and Stored Procedures](https://docs.snowflake.com/en/developer-guide/secure-udf-procedure)) which is essential to manage/import function with Terraform. Use the role owning the function while managing secure functions. Available options are: "true" or "false". When the value is not set in the configuration the provider will put "default" there which means to use the Snowflake default for this value.
- `log_level` (String) LOG_LEVEL to use when filtering events For more information, check [LOG_LEVEL docs](https://docs.snowflake.com/en/sql-reference/parameters#log-level).
- `metric_level` (String) METRIC_LEVEL value to control whether to emit metrics to Event Table For more information, check [METRIC_LEVEL docs](https://docs.snowflake.com/en/sql-reference/parameters#metric-level).
- `null_input_behavior` (String) Specifies the behavior of the function when called with null inputs. Valid values are (case-insensitive): `CALLED ON NULL INPUT` | `RETURNS NULL ON NULL INPUT`.
- `packages` (Set of String) The name and version number of Snowflake system packages required as dependencies. The value should be of the form `package_name:version_number`, where `package_name` is `snowflake_domain:package`.
- `return_behavior` (String) Specifies the behavior of the function when returning results. Valid values are (case-insensitive): `VOLATILE` | `IMMUTABLE`.
- `return_results_behavior` (String) Specifies the behavior of the function when returning results. Valid values are (case-insensitive): `VOLATILE` | `IMMUTABLE`.
- `runtime_version` (String) Specifies the Java JDK runtime version to use. The supported versions of Java are 11.x and 17.x. If RUNTIME_VERSION is not set, Java JDK 11 is used.
- `secrets` (Block Set) Assigns the names of [secrets](https://docs.snowflake.com/en/sql-reference/sql/create-secret) to variables so that you can use the variables to reference the secrets when retrieving information from secrets in handler code. Secrets you specify here must be allowed by the [external access integration](https://docs.snowflake.com/en/sql-reference/sql/create-external-access-integration) specified as a value of this CREATE FUNCTION command’s EXTERNAL_ACCESS_INTEGRATIONS parameter. (see [below for nested schema](#nestedblock--secrets))
- `target_path` (String) The name of the handler method or class. If the handler is for a scalar UDF, returning a non-tabular value, the HANDLER value should be a method name, as in the following form: `MyClass.myMethod`. If the handler is for a tabular UDF, the HANDLER value should be the name of a handler class.
- `target_path` (Block Set, Max: 1) The name of the handler method or class. If the handler is for a scalar UDF, returning a non-tabular value, the HANDLER value should be a method name, as in the following form: `MyClass.myMethod`. If the handler is for a tabular UDF, the HANDLER value should be the name of a handler class. (see [below for nested schema](#nestedblock--target_path))
- `trace_level` (String) Trace level value to use when generating/filtering trace events For more information, check [TRACE_LEVEL docs](https://docs.snowflake.com/en/sql-reference/parameters#trace-level).

### Read-Only
Expand All @@ -57,6 +57,19 @@ Required:
- `arg_data_type` (String) The argument type.
- `arg_name` (String) The argument name.

Optional:

- `arg_default_value` (String) Optional default value for the argument. For text values use single quotes. Numeric values can be unquoted. External changes for this field won't be detected. In case you want to apply external changes, you can re-create the resource manually using "terraform taint".


<a id="nestedblock--imports"></a>
### Nested Schema for `imports`

Required:

- `path_on_stage` (String) Path for import on stage, without the leading `/`.
- `stage_location` (String) Stage location without leading `@`. To use your user's stage set this to `~`, otherwise pass fully qualified name of the stage (with every part contained in double quotes or use `snowflake_stage.<your stage's resource name>.fully_qualified_name` if you manage this stage through terraform).


<a id="nestedblock--secrets"></a>
### Nested Schema for `secrets`
Expand All @@ -67,15 +80,72 @@ Required:
- `secret_variable_name` (String) The variable that will be used in handler code when retrieving information from the secret.


<a id="nestedblock--target_path"></a>
### Nested Schema for `target_path`

Required:

- `path_on_stage` (String) Path for import on stage, without the leading `/`.
- `stage_location` (String) Stage location without leading `@`. To use your user's stage set this to `~`, otherwise pass fully qualified name of the stage (with every part contained in double quotes or use `snowflake_stage.<your stage's resource name>.fully_qualified_name` if you manage this stage through terraform).


<a id="nestedatt--parameters"></a>
### Nested Schema for `parameters`

Read-Only:

- `enable_console_output` (Boolean)
- `log_level` (String)
- `metric_level` (String)
- `trace_level` (String)
- `enable_console_output` (List of Object) (see [below for nested schema](#nestedobjatt--parameters--enable_console_output))
- `log_level` (List of Object) (see [below for nested schema](#nestedobjatt--parameters--log_level))
- `metric_level` (List of Object) (see [below for nested schema](#nestedobjatt--parameters--metric_level))
- `trace_level` (List of Object) (see [below for nested schema](#nestedobjatt--parameters--trace_level))

<a id="nestedobjatt--parameters--enable_console_output"></a>
### Nested Schema for `parameters.enable_console_output`

Read-Only:

- `default` (String)
- `description` (String)
- `key` (String)
- `level` (String)
- `value` (String)


<a id="nestedobjatt--parameters--log_level"></a>
### Nested Schema for `parameters.log_level`

Read-Only:

- `default` (String)
- `description` (String)
- `key` (String)
- `level` (String)
- `value` (String)


<a id="nestedobjatt--parameters--metric_level"></a>
### Nested Schema for `parameters.metric_level`

Read-Only:

- `default` (String)
- `description` (String)
- `key` (String)
- `level` (String)
- `value` (String)


<a id="nestedobjatt--parameters--trace_level"></a>
### Nested Schema for `parameters.trace_level`

Read-Only:

- `default` (String)
- `description` (String)
- `key` (String)
- `level` (String)
- `value` (String)



<a id="nestedatt--show_output"></a>
Expand Down
62 changes: 57 additions & 5 deletions docs/resources/function_javascript.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ Resource used to manage javascript function objects. For more information, check
- `log_level` (String) LOG_LEVEL to use when filtering events For more information, check [LOG_LEVEL docs](https://docs.snowflake.com/en/sql-reference/parameters#log-level).
- `metric_level` (String) METRIC_LEVEL value to control whether to emit metrics to Event Table For more information, check [METRIC_LEVEL docs](https://docs.snowflake.com/en/sql-reference/parameters#metric-level).
- `null_input_behavior` (String) Specifies the behavior of the function when called with null inputs. Valid values are (case-insensitive): `CALLED ON NULL INPUT` | `RETURNS NULL ON NULL INPUT`.
- `return_behavior` (String) Specifies the behavior of the function when returning results. Valid values are (case-insensitive): `VOLATILE` | `IMMUTABLE`.
- `return_results_behavior` (String) Specifies the behavior of the function when returning results. Valid values are (case-insensitive): `VOLATILE` | `IMMUTABLE`.
- `trace_level` (String) Trace level value to use when generating/filtering trace events For more information, check [TRACE_LEVEL docs](https://docs.snowflake.com/en/sql-reference/parameters#trace-level).

### Read-Only
Expand All @@ -50,16 +50,68 @@ Required:
- `arg_data_type` (String) The argument type.
- `arg_name` (String) The argument name.

Optional:

- `arg_default_value` (String) Optional default value for the argument. For text values use single quotes. Numeric values can be unquoted. External changes for this field won't be detected. In case you want to apply external changes, you can re-create the resource manually using "terraform taint".


<a id="nestedatt--parameters"></a>
### Nested Schema for `parameters`

Read-Only:

- `enable_console_output` (Boolean)
- `log_level` (String)
- `metric_level` (String)
- `trace_level` (String)
- `enable_console_output` (List of Object) (see [below for nested schema](#nestedobjatt--parameters--enable_console_output))
- `log_level` (List of Object) (see [below for nested schema](#nestedobjatt--parameters--log_level))
- `metric_level` (List of Object) (see [below for nested schema](#nestedobjatt--parameters--metric_level))
- `trace_level` (List of Object) (see [below for nested schema](#nestedobjatt--parameters--trace_level))

<a id="nestedobjatt--parameters--enable_console_output"></a>
### Nested Schema for `parameters.enable_console_output`

Read-Only:

- `default` (String)
- `description` (String)
- `key` (String)
- `level` (String)
- `value` (String)


<a id="nestedobjatt--parameters--log_level"></a>
### Nested Schema for `parameters.log_level`

Read-Only:

- `default` (String)
- `description` (String)
- `key` (String)
- `level` (String)
- `value` (String)


<a id="nestedobjatt--parameters--metric_level"></a>
### Nested Schema for `parameters.metric_level`

Read-Only:

- `default` (String)
- `description` (String)
- `key` (String)
- `level` (String)
- `value` (String)


<a id="nestedobjatt--parameters--trace_level"></a>
### Nested Schema for `parameters.trace_level`

Read-Only:

- `default` (String)
- `description` (String)
- `key` (String)
- `level` (String)
- `value` (String)



<a id="nestedatt--show_output"></a>
Expand Down
Loading
Loading