Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update custom-aliases: usage methods, File formatting, and version numbers #4119

Merged
merged 9 commits into from
Oct 31, 2023
30 changes: 22 additions & 8 deletions website/docs/docs/build/custom-aliases.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,19 @@ select * from ...

</File>

Or in a `schema.yml` file.

<File name='models/google_analytics/schema.yml'>

```yaml
- models:
- name: ga_sessions
config:
alias: sessions
```

</File>

When referencing the `ga_sessions` model above from a different model, use the `ref()` function with the model's _filename_ as usual. For example:

<File name='models/combined_sessions.sql'>
Expand Down Expand Up @@ -114,34 +127,35 @@ The default implementation of `generate_alias_name` simply uses the supplied `al

</VersionBlock>

<VersionBlock firstVersion="1.6">

### Managing different behaviors across packages
### Dispatch macro - SQL alias management for databases and dbt packages

See docs on macro `dispatch`: ["Managing different global overrides across packages"](/reference/dbt-jinja-functions/dispatch)
See docs on macro `dispatch`: ["Managing different global overrides across packages"](/reference/dbt-jinja-functions/dispatch#managing-different-global-overrides-across-packages)

</VersionBlock>

### Caveats

#### Ambiguous database identifiers

Using aliases, it's possible to accidentally create models with ambiguous identifiers. Given the following two models, dbt would attempt to create two <Term id="view">views</Term> with _exactly_ the same names in the database (ie. `sessions`):

```sql
-- models/snowplow_sessions.sql
<File name='models/snowplow_sessions.sql'>

```sql
{{ config(alias='sessions') }}

select * from ...
```
</File>

```sql
-- models/sessions.sql
<File name='models/sessions.sql'>

```sql
select * from ...
```

</File>

Whichever one of these models runs second would "win", and generally, the output of dbt would not be what you would expect. To avoid this failure mode, dbt will check if your model names and aliases are ambiguous in nature. If they are, you will be presented with an error message like this:

```
Expand Down