Update the derivation of the test view name
Resolves #575 Use the local MD5 macro to create a more unique hash based on the SQL of the test itself
Thanks @Benjamin-Knight. Will set some time aside this week to review.
Hi, we're having the same problem. I'm fine with the solution and this can be ignored if it causes too much trouble
Edit: I'm really fine with the solution, just leaving the rest of my world salad here for people with spare time. {{ local_md5(main_sql) }}_{{ range(1300, 19000) | random }} should do the trick and you've got all the variables at hand anyways
Isn't the more common approach to hash the "dbt name" of the test (which should be unique as well)? Or hash plus a random seed in case someone somehow manages to be really crazy with column and table names. You could probably have two tests that run the same sql but yaml logic should forbid that there is the same test twice.
So one would hash relationships_table1_conflict_column1__column2__ref_table2 instead of the underlying SQL.
Cheers Hannes
@johannes-becker-bt The pull currently uses a hash and a random seed as you mention for the exact reason you noted.
Using the name of the test does sound like a better hash target, I'll have to test if DBT allows the setting of test names to be the same value, I often override the name of tests to a more user friendly version and DBT would need to ensure this is unique as well for this to work.
Only if you feel like it. Main reason I would stick with your solution: we got main_sql available. All other solutions would need much more tinkering in different places (Unless the test name is somewhere in target or something, I'm never sure about that...)
Merry Christmas! I tested it with a local macro and it works like a charm. Also it might make sense to combine the solution with the other change regarding tests https://github.com/dbt-msft/dbt-sqlserver/pull/586 Have a great New Year! Hannes
^ Yes please! Would love to hit 2 birds with one stone on this
Added an update to resolve #586 as well, I added the update to view name derivation to the unit test materialisations as well.
@cody-scott would you be able to give this a look-over this week? Would help unblock some upstream work, well, at work. :)
@Benjamin-Knight would you be able to merge this PR?
I do not have permissions to do that, all checks are now passing that the failing tests were updated via #589 so just waiting on @cody-scott to sign it off now its all passing.
@cody-scott would you be able to merge this PR? Getting to a point where having this fix in is going to make my life a lot better at work.