mad_
mad_

Reputation: 8273

How to get full name in DBT models when database in target

We have models defined and everything seems to be working fine except the model names in logs.

We have database defined in profile.yml and have macros referencing this as target.database. While doing so we have observed that full model names are not getting logged (as if DBT knows that default database is the one set in target) so we see model names like with database names are stripped.

Ok Created table model <generated_schema_name>.<generated_alias_name>

While what we need in the logs (Expected output in logs)

Ok Created table model <generated_database_name>.<generated_schema_name>.<generated_alias_name>

One thing that is working if we remove database config in profile.yml and only use custom_database_name in dbt_project.yml. My theory - this makes DBT feel that there is no default database. Models are getting materialized correctly in both approaches.

How can we log complete model names without removing the database from the config?

Upvotes: 1

Views: 1660

Answers (1)

tconbeer
tconbeer

Reputation: 5805

This is the intentional behavior. The code is here, and is clearly labeled with the comment "exclude the database from output if it's the default." You could open an issue in dbt-core to try to change this behavior or make it configurable. Or you could just fork the project.

If you're parsing these logs, I'd recommend using dbt's structured logging instead, or really the other artifacts created by the dbt run, like manifest.json. The manifest will have the full config for each model, including the fully-qualified identifier.

Another option would be to patch the materialization macros to add print statements that include the info you want. This would be much easier to maintain than a full fork, but it would add logging, not change the logging that is there. You'd have to find the right macros (from your adapter's project or the core project), copy the code, and create a new macro in your project that contains that materialization code, and then add lines like this:

{{ log("Model identifier: " ~ this, info=True) }}

If you place that toward the end of the materialization, your logs will look like:

Model identifier: <generated_database_name>.<generated_schema_name>.<generated_alias_name>
Ok Created table model <generated_schema_name>.<generated_alias_name>

Upvotes: 2

Related Questions