Skip to content

Commit

Permalink
fix(helpers)!: double underscore suffix (#13)
Browse files Browse the repository at this point in the history
  • Loading branch information
axel_thevenot authored and AxelThevenot committed Jan 25, 2024
1 parent 2a03638 commit 558d6a9
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 15 deletions.
14 changes: 7 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -361,8 +361,8 @@ You can also verify unique keys for nested/repeated structure. It will generate:

The following example will generate the assertions:
- `unique`: Row must be unique over the unique keys.
- `nested_1_unique`: Items must be unique **within** nested_1 in the row.
- `nested_1.nested_2_unique`: Items must be unique **within** nested_1.nested_2 in the row.
- `nested_1__unique`: Items must be unique **within** nested_1 in the row.
- `nested_1.nested_2__unique`: Items must be unique **within** nested_1.nested_2 in the row.

```yml
assertions:
Expand All @@ -386,11 +386,11 @@ the `__not_null__` helper is here to avoid writing complex and repetitive querie

```yml
assertions:
key_1_not_null:
key_1__not_null:
description: "key_1 is not null."
expression: "key_1 IS NOT NULL"
key_2_not_null:
key_2__not_null:
description: "key_2 is not null."
expression: "key_2 IS NOT NULL"
```
Expand Down Expand Up @@ -428,9 +428,9 @@ You can also verify unique keys for nested/repeated structure. It will generate:
**all the values are not null within the row**.

The following example will generate the assertions:
- `key_1_not_null`: key_1 is not null.
- `key_2_not_null`: key_2 is not null.
- `nested_1.key_3_not_null`: nested_1.key_3 **are** not null.
- `key_1__not_null`: key_1 is not null.
- `key_2__not_null`: key_2 is not null.
- `nested_1.key_3__not_null`: nested_1.key_3 **are** not null.

```yml
assertions:
Expand Down
12 changes: 6 additions & 6 deletions macros/_get_not_null_assertions.sql
Original file line number Diff line number Diff line change
Expand Up @@ -25,22 +25,22 @@
Calling the macro with these columns will generate the following:

{
'column_a_not_null': {
'column_a__not_null': {
'description': 'column_a is not null.',
'expression': 'column_a IS NOT NULL'
},
'column_b_not_null': {
'column_b__not_null': {
'description': 'column_b is not null.',
'expression': 'column_b IS NOT NULL'
},
'nested_structure_sub_column_1_not_null': {
'nested_structure_sub_column_1__not_null': {
'description': 'nested_structure.sub_column_1 are not null over the row.',
'expression': 'NOT EXISTS (SELECT 1
FROM UNNEST(nested_structure) nested_structure
WHERE nested_structure IS NOT NULL AND
nested_structure.sub_column_1 IS NULL)'
},
'nested_structure_sub_column_2_not_null': {
'nested_structure_sub_column_2__not_null': {
'description': 'nested_structure.sub_column_2 are not null over the row.',
'expression': 'NOT EXISTS (SELECT 1
FROM UNNEST(nested_structure) nested_structure
Expand Down Expand Up @@ -69,7 +69,7 @@

{%- for column in not_null_columns %}
{%- do result.update({
column ~ '_not_null': {
column ~ '__not_null': {
'description': column ~ ' is not null.',
'expression': column ~ ' IS NOT NULL'
}
Expand Down Expand Up @@ -110,7 +110,7 @@
%}

{%- do result.update({
'.'.join(depends_on + [parent_column, column]) ~'_not_null': {
'.'.join(depends_on + [parent_column, column]) ~'__not_null': {
'description': '.'.join(
depends_on + [parent_column, column]
) ~ ' are not null within the row.',
Expand Down
4 changes: 2 additions & 2 deletions macros/_get_unique_assertions.sql
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
'description': 'Row must be unique over the unique keys.',
'expression': '1 = COUNT(1) OVER(PARTITION BY column_a, column_b)'
},
'nested_structure_unique': {
'nested_structure__unique': {
'description': 'Items must be unique within nested_structure in the row.',
'expression': 'NOT EXISTS (
SELECT 1
Expand Down Expand Up @@ -110,7 +110,7 @@
{%- do expression.append('))') %}

{%- do result.update({
'.'.join(depends_on + [parent_column]) ~'_unique': {
'.'.join(depends_on + [parent_column]) ~'__unique': {
'description': 'Items must be unique within'
~ '.'.join(parents_columns) ~ ' in the row.',
'expression': ''.join(expression),
Expand Down

0 comments on commit 558d6a9

Please sign in to comment.