Skip to content

Commit

Permalink
Merge branch 'current' into update-whitespace
Browse files Browse the repository at this point in the history
  • Loading branch information
nghi-ly authored Feb 22, 2024
2 parents df144fc + 2f7af3b commit 61bb159
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 27 deletions.
2 changes: 1 addition & 1 deletion website/docs/docs/build/semantic-models.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ semantic_models:
description: same as always ## Optional
model: ref('some_model') ## Required
defaults: ## Required
agg_time_dimension: dimension_name ## Required if the model contains dimensions
agg_time_dimension: dimension_name ## Required if the model contains measures
entities: ## Required
- see more information in entities
measures: ## Optional
Expand Down
29 changes: 15 additions & 14 deletions website/docs/docs/build/unit-tests.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@ check_valid_emails as (
customers.customer_id,
customers.first_name,
customers.last_name,
coalesce (regexp_like(
customers.email,
coalesce (regexp_like(
customers.email, '^[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,}$'
)
= true
Expand Down Expand Up @@ -97,20 +98,20 @@ unit_tests:
given:
- input: ref('stg_customers')
rows:
- {customer_id: 1, email: [email protected], email_top_level_domain: example.com}
- {customer_id: 2, email: [email protected], email_top_level_domain: unknown.com}
- {customer_id: 3, email: badgmail.com, email_top_level_domain: gmail.com}
- {customer_id: 4, email: missingdot@gmailcom, email_top_level_domain: gmail.com}
- {email: [email protected], email_top_level_domain: example.com}
- {email: [email protected], email_top_level_domain: unknown.com}
- {email: badgmail.com, email_top_level_domain: gmail.com}
- {email: missingdot@gmailcom, email_top_level_domain: gmail.com}
- input: ref('top_level_email_domains')
rows:
- {tld: example.com}
- {tld: gmail.com}
expect:
rows:
- {customer_id: 1, is_valid_email_address: true}
- {customer_id: 2, is_valid_email_address: false}
- {customer_id: 3, is_valid_email_address: false}
- {customer_id: 4, is_valid_email_address: false}
- {email: [email protected], is_valid_email_address: true}
- {email: [email protected], is_valid_email_address: false}
- {email: badgmail.com, is_valid_email_address: false}
- {email: missingdot@gmailcom, is_valid_email_address: false}

```
</file>
Expand Down Expand Up @@ -166,10 +167,10 @@ dbt test --select test_is_valid_email_address

actual differs from expected:

@@ ,customer_id,is_valid_email_address
→ ,1 ,True→False
,2 ,False
...,... ,...
@@ ,email ,is_valid_email_address
→ ,[email protected],True→False
,[email protected],False
...,... ,...


16:03:51
Expand All @@ -179,7 +180,7 @@ actual differs from expected:

```

The clever regex statement wasn’t as clever as initially thought, as the model incorrectly flagged `[email protected]` (customer 1's email) as an invalid email address.
The clever regex statement wasn’t as clever as initially thought, as the model incorrectly flagged `[email protected]` as an invalid email address.

Updating the regex logic to `'^[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}$'` (those pesky escape characters) and rerunning the unit test solves the problem:

Expand Down
24 changes: 12 additions & 12 deletions website/docs/reference/resource-properties/unit-tests.md
Original file line number Diff line number Diff line change
Expand Up @@ -162,20 +162,20 @@ unit_tests:
given: # the mock data for your inputs
- input: ref('stg_customers')
rows:
- {customer_id: 1, email: [email protected], email_top_level_domain: example.com}
- {customer_id: 2, email: [email protected], email_top_level_domain: unknown.com}
- {customer_id: 3, email: badgmail.com, email_top_level_domain: gmail.com}
- {customer_id: 4, email: missingdot@gmailcom, email_top_level_domain: gmail.com}
- {email: [email protected], email_top_level_domain: example.com}
- {email: [email protected], email_top_level_domain: unknown.com}
- {email: badgmail.com, email_top_level_domain: gmail.com}
- {email: missingdot@gmailcom, email_top_level_domain: gmail.com}
- input: ref('top_level_email_domains')
rows:
- {tld: example.com}
- {tld: gmail.com}
expect: # the expected output given the inputs above
rows:
- {customer_id: 1, is_valid_email_address: true}
- {customer_id: 2, is_valid_email_address: false}
- {customer_id: 3, is_valid_email_address: false}
- {customer_id: 4, is_valid_email_address: false}
- {email: [email protected], is_valid_email_address: true}
- {email: [email protected], is_valid_email_address: false}
- {email: badgmail.com, is_valid_email_address: false}
- {email: missingdot@gmailcom, is_valid_email_address: false}
```

Expand All @@ -187,10 +187,10 @@ unit_tests:
given: # the mock data for your inputs
- input: ref('stg_customers')
rows:
- {customer_id: 1, email: [email protected], email_top_level_domain: example.com}
- {customer_id: 2, email: [email protected], email_top_level_domain: unknown.com}
- {customer_id: 3, email: badgmail.com, email_top_level_domain: gmail.com}
- {customer_id: 4, email: missingdot@gmailcom, email_top_level_domain: gmail.com}
- {email: [email protected], email_top_level_domain: example.com}
- {email: [email protected], email_top_level_domain: unknown.com}
- {email: badgmail.com, email_top_level_domain: gmail.com}
- {email: missingdot@gmailcom, email_top_level_domain: gmail.com}
- input: ref('top_level_email_domains')
format: csv
rows: |
Expand Down

0 comments on commit 61bb159

Please sign in to comment.