User-Defined Functions and Stored Procedures in Declarative Sharing in the Native Application Framework¶
Declarative Native Apps can include stored procedures and user-defined functions (UDFs) to query, visualize, and explore data. This topic describes how to include these objects in your app.
Supported User-Defined Functions and Stored Procedures¶
You can share the following types of user-defined functions (UDFs) and stored procedures (sprocs) in a Declarative Native App:
Stored procedures that have OWNERS RIGHTS or RESTRICTED CALLERS RIGHTS. For
more information, see Understanding caller’s rights and owner’s rights stored procedures.
All types of UDFs, except EXTERNAL functions
Including User-Defined Functions and Stored Procedures in your application¶
To include UDFs and stored procedures in your Declarative Native App, add the
names of the objects and their permissions to the manifest.yaml file.
You don’t need to add the objects using separate files, as you do with
notebooks.
The following example shows how to include a UDF and a stored procedure in the
manifest.yaml file:
manifest_version: 2
roles:
- ANALYST:
comment: "The ANALYST role provides access to logic objects."
shared_content:
databases:
- SNAF_POPULATION_DB:
schemas:
- LOGIC_SCHEMA:
roles: [ANALYST]
functions:
- POPULATION_ANALYSIS_FUNCTION(NUMBER):
roles: [ANALYST]
procedures:
- POPULATION_ANALYSIS_PROCEDURE():
roles: [ANALYST]
In this example, the POPULATION_ANALYSIS_FUNCTION UDF and the
POPULATION_ANALYSIS_PROCEDURE stored procedure are included in the
manifest.yaml file. The ANALYST app role is granted access to
both objects.
Manifest reference¶
This feature adds the following fields to the manifest.yaml file:
functions.{named function} field¶
Each named function (List, required [OneOfRequired] ): supports the following name value pair:
roles(list, optional): A list of app roles that can access the function, for example,[analyst]. When this field is empty ([]) or omitted, then only app owners and roles with granted IMPORTED PRIVILEGES receive access. The included roles must be defined in the top-level roles field and included in the {named schema}.roles field.
procedures.{named procedure} field¶
Each named stored procedure (List, required [OneOfRequired] ): supports the following name value pair:
roles(list, optional): A list of app roles that can access the procedure, for example,[analyst]. When this field is empty ([]) or omitted, then only app owners and roles with granted IMPORTED PRIVILEGES receive access. The included roles must be defined in the top-level roles field and included in the {named schema}.roles field.
Manifest file example¶
The following code block is an example of a Declarative Native App manifest file.
Note that data and code objects must be in different schemas.
manifest_version: 2
roles:
- VIEWER:
comment: "The VIEWER role provides access to only one view."
- ANALYST:
comment: "The ANALYST role provides access to views, the table, and logic."
shared_content:
databases:
- SNAF_POPULATION_DB:
schemas:
- DATA_SCHEMA:
roles: [VIEWER, ANALYST]
tables:
- COUNTRY_POP_BY_YEAR:
roles: [ANALYST]
views:
- COUNTRY_POP_BY_YEAR_2000:
roles: [VIEWER, ANALYST]
- LOGIC_SCHEMA:
roles: [ANALYST]
functions:
- POPULATION_ANALYSIS_FUNCTION(NUMBER):
roles: [ANALYST]
procedures:
- POPULATION_ANALYSIS_PROCEDURE():
roles: [ANALYST]
application_content:
notebooks:
- intro_notebook:
roles: [VIEWER, ANALYST]
main_file: INTRO_NB.ipynb
- analyst_notebook:
roles: [ANALYST]
main_file: ANALYST_NB.ipynb
Limitations¶
- Supported languages and types
Snowpark UDFs and stored procedures written in Python, Java, Javascript, and Scala. Snowpark Container Service Functions are not supported.
- Schemas for data objects and logic objects
You must use separate schemas for data objects (tables and views) and logic objects (UDFs and stored procedures). For example, you can use a schema named
DATA_SCHEMAfor tables and views, and a schema namedLOGIC_SCHEMAfor UDFs and stored procedures.- Referencing private objects
Your UDFs and stored procedures must reference private objects by their schema-qualified names. Your logic objects can’t reference private objects by their fully-qualified names.
- Object count
A Declarative Native App can include up to 100 UDFs and stored procedures. To raise this limit, contact Snowflake Support.
- Dynamic tables
Referencing dynamic tables in UDFs and stored procedures is not supported.