The as_bool Jinja filter will coerce Jinja-compiled output into a boolean
The as_native Jinja filter will coerce Jinja-compiled output into its
The as_number Jinja filter will coerce Jinja-compiled output into a numeric
The as_text Jinja filter will coerce Jinja-compiled output back to text. It
New in 0.16.0
📄️ cross-database macros
📄️ dbt_project.yml Context
The compilation context of the dbt_project.yml file is well-defined as
New in 0.16.0
The debug macro is new in dbt v0.14.1, and is only intended to be used in a development context with dbt. Do not deploy code to production which uses the debug macro.
- v0.18.0: Introduced dispatch as a replacement for deprecated adapter_macro
The doc function is used to reference docs blocks in the description field of schema.yml files. It is analogous to the ref function. For more information, consult the Documentation guide.
The envvar function can be used to incorporate Environment Variables from the system into your dbt project. This envvar function can be used in your profiles.yml file, the dbtproject.yml file, the sources.yml file, your schema.yml files, and in model .sql files. Essentially envvar is available anywhere dbt processes jinja code.
The exceptions namespace can be used to raise warnings and errors in dbt userspace.
execute is a Jinja variable that returns True when dbt is in "execute" mode.
The flags variable contains values of flags provided on the command line.
The fromjson context method can be used to deserialize a json string into a Python object primitive, eg. a dict or list.
The fromyaml context method can be used to deserialize a yaml string into a Python object primitive, eg. a dict or list.
The graph context variable contains information about the nodes in your dbt
The invocation_id outputs a UUID generated for this dbt command. This value is
model is the dbt graph object (or node) for the current model. It can be used to:
The modules variable in the Jinja context contains useful Python modules for operating on data.
📄️ on-run-end Context
These variables are only available in the context for on-run-end hooks. They will evaluate to none if used outside of an on-run-end hook!
📄️ profiles.yml Context
The following context variables and methods are available when configuring
New in 0.16.0
The run_query macro provides a convenient way to run queries and fetch their results. It is a wrapper around the statement block, which is more flexible, but also more complicated to use.
runstartedat outputs the timestamp that this run started, e.g. 2017-04-21 0145.678.
The schema that the model is configured to be materialized in. This is typically the same as model['schema'].
schemas is a variable available in an on-run-end hook, representing a list of schemas that dbt built objects in on this run.
The selectedresources context variable contains a list of all the nodes_
📄️ statement blocks
statements are sql queries that hit the database and return results to your Jinja context. Here’s an example of a statement which gets all of the states from a users .
target contains information about your connection to the warehouse.
this is the database representation of the current model. It is useful when:
The tojson context method can be used to serialize a Python object primitive, eg. a dict or list to a JSON string.
The toyaml context method can be used to serialize a Python object primitive, eg. a dict or list to a yaml string.
Variables can be passed from your dbt_project.yml file into models during compilation.