-
Notifications
You must be signed in to change notification settings - Fork 149
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create expect_column_set_to_be_unique_case_insensitive.sql (#138)
* Create expect_column_set_to_be_unique_case_insensitive.sql * adjusting consistent casing test and documentation * adjusting formatting and adding integration test * Fix formatting * Formatting updates * adjusting Readme and adding test instance * Fix spelling Co-authored-by: clausherther <[email protected]>
- Loading branch information
1 parent
590d599
commit 854e653
Showing
3 changed files
with
58 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
macros/schema_tests/column_values_basic/expect_column_values_to_have_consistent_casing.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
{% test expect_column_values_to_have_consistent_casing(model, column_name, display_inconsistent_columns=False) %} | ||
|
||
with test_data as ( | ||
|
||
select | ||
distinct {{ column_name }} as distinct_values | ||
from | ||
{{ model }} | ||
|
||
), | ||
{% if display_inconsistent_columns %} | ||
validation_errors as ( | ||
|
||
select | ||
lower(distinct_values) as inconsistent_columns, | ||
count(distinct_values) as set_count_case_insensitive | ||
from | ||
test_data | ||
group by 1 | ||
having | ||
count(distinct_values) > 1 | ||
|
||
) | ||
select * from validation_errors | ||
{% else %} | ||
validation_errors as ( | ||
|
||
select | ||
count(1) as set_count, | ||
count(distinct lower(distinct_values)) as set_count_case_insensitive | ||
from | ||
test_data | ||
|
||
) | ||
select * | ||
from | ||
validation_errors | ||
where | ||
set_count != set_count_case_insensitive | ||
{% endif %} | ||
{%- endtest -%} |