mjirv / dbt-datamocktool

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

Scan `compare_columns` as list, not string #81

Closed pishposh closed 1 year ago

pishposh commented 1 year ago

This is a:

Description & motivation

Hey @mjirv, thanks for this incredibly useful package!

This PR is intended to fix a bug where fields are being included in the comparison even if they only match part of a field name in compare_columns. For example, if a table has the columns foo and is_foo_active, and compare_columns is ["is_foo_active"] (without foo), foo gets included anyway.

I’m new to Jinja and Python, but it looks to me like running compare_columns through upper() is converting it to a string, on which the in operator performs a substring search instead of the intended element-by-element list search. This PR uses map() to uppercase each element of compare_columns individually, preserving it as a list, I think.

I haven’t added an integration test, but I’d be happy to if you think it’s warranted, @mjirv.

Checklist

mjirv commented 1 year ago

Nice, thanks for this

pishposh commented 1 year ago

Thanks @mjirv!