Function configurations
Available configurationsβ
Function-specific configurationsβ
Resource-specific configurations are applicable to only one dbt resource type rather than multiple resource types. You can define these settings in the project file (dbt_project.yml), a property file (models/properties.yml for models, similarly for other resources), or within the resourceβs file using the {{ config() }} macro.
The following resource-specific configurations are only available to Functions:
- Project file
- Property file
functions:
<resource-path>:
# Function-specific configs are defined in the property file
# See functions/schema.yml examples below
General configurationsβ
General configurations provide broader operational settings applicable across multiple resource types. Like resource-specific configurations, these can also be set in the project file, property files, or within resource-specific files.
Functions support database, schema, and alias configurations just like models. These determine where the function is created in your warehouse. The function will use the standard dbt configuration precedence (specific config > project config > target profile defaults).
- Project file
- Property file
Configuring functionsβ
Functions are configured in YAML files, either in dbt_project.yml or within an individual function's YAML properties file. The function body is defined in a SQL file in the functions/ directory.
Function configurations, like model configurations, are applied hierarchically. For more info, refer to config inheritance.
Functions respect the same name-generation macros as models: generate_database_name, generate_schema_name, and generate_alias_name.
Examplesβ
Apply the schema configuration to all functionsβ
To apply a configuration to all functions, including those in any installed packages, nest the configuration directly under the functions key:
functions:
+schema: udf_schema
Apply the schema configuration to all functions in your projectβ
To apply a configuration to all functions in your project only (i.e. excluding any functions in installed packages), provide your project name as part of the resource path.
For a project named jaffle_shop:
functions:
jaffle_shop:
+schema: udf_schema
Similarly, you can use the name of an installed package to configure functions in that package.
Apply the schema configuration to one function onlyβ
To apply a configuration to one function only in a properties file, specify the configuration in the function's config block:
functions:
- name: is_positive_int
config:
schema: udf_schema
To apply a configuration to one function only in dbt_project.yml, provide the full resource path (including the project name and subdirectories). For a project named jaffle_shop, with a function file at functions/is_positive_int.sql:
functions:
jaffle_shop:
is_positive_int:
+schema: udf_schema
Example function configurationβ
The following example shows how to configure functions in a project named jaffle_shop that has two function files:
functions/is_positive_int.sqlfunctions/marketing/clean_url.sql
name: jaffle_shop
...
functions:
jaffle_shop:
+enabled: true
+schema: udf_schema
# This configures functions/is_positive_int.sql
is_positive_int:
+tags: ['validation']
marketing:
+schema: marketing_udfs # this will take precedence
functions:
- name: is_positive_int
description: Determines if a string represents a positive integer
config:
database: analytics
schema: udf_schema
arguments:
- name: a_string
data_type: string
description: The string to check
returns:
data_type: boolean
description: Returns true if the string represents a positive integer
Was this page helpful?
This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.