Skip to content

Commit

Permalink
Update builtins.md
Browse files Browse the repository at this point in the history
adding 1.5+ and <=v1.5 versioning and macro explaining for ref maco
  • Loading branch information
mirnawong1 authored Sep 8, 2023
1 parent e8d73fe commit 0bdfbd5
Showing 1 changed file with 33 additions and 1 deletion.
34 changes: 33 additions & 1 deletion website/docs/reference/dbt-jinja-functions/builtins.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,38 @@ The `builtins` variable is a dictionary containing the following keys:

## Usage

The following macro overrides the `ref` method available in the model compilation context to return a [Relation](/reference/dbt-classes#relation) with the database name overriden to `dev`.
<VersionBlock firstVersion="1.6">

The following macro extracts user-provided arguments, including `version`, and calls the `builtins.ref()` function with either a single `modelname` argument or both `packagename` and `modelname` arguments, based on the number of positional arguments in `varargs`:

```
{% macro ref() %}
-- extract user-provided positional and keyword arguments
{% set version = kwargs.get('version') %}
{% set packagename = none %}
{%- if (varargs | length) == 1 -%}
{% set modelname = varargs[0] %}
{%- else -%}
{% set packagename = varargs[0] %}
{% set modelname = varargs[1] %}
{% endif %}
-- call builtins.ref based on provided positional arguments
{% if packagename is not none %}
{% do return(builtins.ref(packagename, modelname, version=version)) %}
{% else %}
{% do return(builtins.ref(modelname, version=version)) %}
{% endif %}
{% endmacro %}
```

</VersionBlock>

<VersionBlock lastVersion="1.5">

The following macro overrides the `ref` method available in the model compilation context to return a [Relation](/reference/dbt-classes#relation) with the database name overriden to `dev`:

```
{% macro ref(model_name) %}
Expand All @@ -26,6 +57,7 @@ The following macro overrides the `ref` method available in the model compilatio
{% endmacro %}
```
</VersionBlock>

The ref macro can also be used to control which elements of the model path are rendered when run, for example the following macro overrides the `ref` method to render only the schema and object identifier, but not the database reference i.e. `my_schema.my_model` rather than `my_database.my_schema.my_model`. This is especially useful when using snowflake as a warehouse, if you intend to change the name of the database post-build and wish the references to remain accurate.

Expand Down

0 comments on commit 0bdfbd5

Please sign in to comment.