Search code examples
dbt

DBT table alias not working and gives error `dataset.table does not match any nodes`


I have three datasets containing tables with the same name. Following documentation, I use an alias to rename each table. For example, for a table I would like to call mes_brasil the DBT model is:

{{ config(alias='mes_brasil', schema='br_ibge_ipca') }}
SELECT *
FROM ...

even though the file name is br_ibge_ipca__mes_brasil.sql. I think this is supposed to work. However, when I run the flow DBT didn't recognize the alias and gives the message 'br_ibge_ipca.mes_brasil' does not match any nodes.

The whole project configuration can be found here: https://github.com/basedosdados/queries/blob/master/models/br_ibge_ipca/br_ibge_ipca__mes_brasil.sql

What am I doing wrong here?


Solution

  • It's hard to know exactly, since you didn't share the command you ran, the warehouse you're using, or the exact error message.

    But I'm guessing that this is a warning from trying to execute dbt run -s br_ibge_ipca.mes_brasil. Here you've tried to select a dbt model to be run based on its database identifier, which is not allowed. You instead have to use dbt run -s br_ibge_ipca__mes_brasil, which is dbt's unique model name for that model.

    Also, in your models, you don't seem to be using dbt's {{ ref() }} macro. It's important to use ref so that dbt can construct a dependency graph. It's possible you're seeing a database error related to nodes that are being built out of order.