Skip to main content

Function

Configuration can be provided to the Snowflake Object Lifecycle Engine for the following operation with Function:

  • Manage the Lifecycle of new and existing Functions
  • Manage Grants of a Function

Supported Parameters

The engine supports the parameters listed below.

  • RETURN_TYPE: The return type of the function.
    • REQUIRED
    • Configuration Key: return_type
    • Data Type: String
  • STATEMENT: Specifies the JavaScript / Java / SQL/ Python code used to create the function.
    • REQUIRED
    • Configuration Key: statement
    • Data Type: String
  • ARGUMENTS: List of the arguments for the function.
    • Configuration Key: arguments
    • Data Type: Object. See here for definition of Argument
  • LANGUAGE: The language of the statement.
    • Configuration Key: language
    • Data Type: String
    • Possible Values:
      • javascript
      • java
      • sql
      • python
  • NULL_INPUT_BEHAVIOR: Specifies the behavior of the function when called with null inputs.
    • Configuration Key: null_input_behavior
    • Data Type: String
  • RETURN_BEHAVIOR: Specifies the behavior of the function when returning results.
    • Configuration Key: return_behavior
    • Data Type: String
    • RUNTIME_VERSION: Required for Python functions. Specifies Python runtime version.
      • Configuration Key: runtime_version
      • Data Type: String
        info

        The version has to be specified in a string format. Example 3.8 should be specified as:

        runtime_version: "3.8"
  • COMMENT: Specifies a comment for the function.
    • Configuration Key: comment
    • Data Type: String
  • HANDLER: The handler method for Java function.
    • Configuration Key: handler
    • Data Type: String
  • IMPORTS: Jar files to import for Java function.
    • Configuration Key: imports
    • Data Type: List of String
  • PACKAGES: Jar files to import for Java function.
    • Configuration Key: packages
    • Data Type: List of String
  • TARGET_PATH: The target path for compiled jar file for Java function.
    • Configuration Key: target_path
    • Data Type: String
  • MANAGE_MODE: Configures what properties to manage for the function.
    • Configuration key: manage_mode
    • Data Type: String
    • Possible Values:
      • none
      • grants
      • all(Default)
  • GRANTS: List of Privileges and Roles to which privileges are granted on the current function.
    • Configuration key: grants
    • Data Type: Map
caution

During subsequent pipeline runs a force-replacement behavior might be observed in PLAN and APPLY phase for few parameters like arguments, return_type, statement, language, etc.

Function Arguments

In the arguments parameter, users can specify the arguments for the function.

Multiples arguments in an object format can be listed in the arguments parameter with each having the following supported parameters:

  • TYPE: Data Type of the Column
    • REQUIRED
    • Configuration key: type
    • Data Type: String

Example

arguments:
ARG_1:
type: VARCHAR
ARG_2:
type: DATE

Basic syntax

databases:
<database-name>:
schemas:
<schema-name>:
functions:
<function-name>:
<configuration-key>: <value>
grants:
<privilege>:
- <role-name>
- <role-name>

Supported Function Grants to Roles

Following is the list of Privilege Grants to Roles that can be specified in the function definition

  • USAGE
  • OWNERSHIP

Examples

databases:
DATABASE_1:
schemas:
SCHEMA_1:
functions:
JAVASCRIPT_FUNCTION:
comment: "Function using JavaScript language"
language: JavaScript
return_type: VARCHAR
return_behavior: IMMUTABLE
null_input_behavior: "RETURNS NULL ON NULL INPUT"
statement: "return 1"