mjirv / dbt-datamocktool

A dbt package for unit testing your SQL analytics models
Apache License 2.0
162 stars 20 forks source link

When using alias and having duplicate alias names the test cannot find the correct model #78

Open ran-silberman-gong opened 1 year ago

ran-silberman-gong commented 1 year ago

Describe the bug

this is related to bug: add support for aliases and test model with an alias When we have multiple models in different DB's with same alias it will fail

Steps to reproduce

Create two models in two DB's with different file names. E.g. aaa.sql and bbb.sql Then give them both the same alias. The alias is different than the names of both models. E.G. {{config(alias='ccc')}}

Expected results

When running dbt test we expect the correct model to be tested

Actual results

In an arbitrary way, one of the two models that have the same alias might be selected randomly.

System information

Which database are you using dbt with?

The output of dbt --version:

Core:
  - installed: 1.4.1

Plugins:
  - snowflake: 1.4.0 - Update available!

Additional context

We have a big project with hundreds of files. the alias is not unique across the project. only file name is unique. Therefore we should not select by alias.

Are you interested in contributing the fix?

To overcome this, I have added another attribute to pass to the test the exact name of the model so the test does not need to look it out from the model name (which is wrong when using alias)

mjirv commented 1 year ago

Interesting bug. Agree we should select by file name if possible but unfortunately dbt doesn't provide it in the context where we need it, only the alias.

That said, we're also checking the schema, and I'd think schema + alias should be unique. Can you provide more detail on the use case here? i.e. what is the intention between having multiple models w/ the same alias?

ran-silberman-gong commented 1 year ago

well, there is no limit in DBT for multiple aliases. only file names should be unique. Therefore in big projects it is very probable that we will have multiple alias names. My solution is to add another keyword in the yaml file that will be the unique identification of the model by file name. this is not nice, because we need to add redundant keyword in the yaml. But I do not see other way to overcome this limitation.

WarSame commented 5 months ago

@ran-silberman-gong what keyword did you add to the YAML file that uniquely identifies the model?

I'm thinking we might just need to remove the aliasing right now to let this work, but would prefer to keep our aliasing in place.