-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added sampling and string length tests
- Loading branch information
kevin
committed
Jan 3, 2024
1 parent
ddc92f6
commit faf18e7
Showing
12 changed files
with
346 additions
and
10 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,6 @@ | ||
packages: | ||
- local: ../ | ||
- package: dbt-labs/dbt_utils | ||
version: 1.1.1 | ||
version: 1.1.1 | ||
- package: calogica/dbt_expectations | ||
version: 0.10.1 |
32 changes: 32 additions & 0 deletions
32
integration_tests/tests/generate_string_length_tests/string_length_colnames_with_spaces.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,32 @@ | ||
|
||
|
||
{% set actual_yaml = testgen.to_yaml( | ||
testgen.get_string_length_test_suggestions( | ||
ref('colnames_with_spaces'), | ||
sample=true, | ||
limit=100 | ||
) | ||
) | ||
%} | ||
|
||
{% set expected_yaml %} | ||
models: | ||
- name: colnames_with_spaces | ||
columns: | ||
- name: first name | ||
description: String length test generated by dbt-testgen | ||
tests: | ||
- dbt_expectations.expect_column_value_lengths_to_be_between: | ||
min_value: 3 | ||
max_value: 5 | ||
row_condition: '"first name" is not null' | ||
- name: current city | ||
description: String length test generated by dbt-testgen | ||
tests: | ||
- dbt_expectations.expect_column_value_lengths_to_be_between: | ||
min_value: 7 | ||
max_value: 13 | ||
row_condition: '"current city" is not null' | ||
{% endset %} | ||
|
||
{{ assert_equal (actual_yaml | trim, expected_yaml | trim) }} |
39 changes: 39 additions & 0 deletions
39
integration_tests/tests/generate_string_length_tests/string_length_users.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,39 @@ | ||
|
||
|
||
{% set actual_yaml = testgen.to_yaml( | ||
testgen.get_string_length_test_suggestions( | ||
ref('users'), | ||
sample=true, | ||
limit=100 | ||
) | ||
) | ||
%} | ||
|
||
{% set expected_yaml %} | ||
models: | ||
- name: users | ||
columns: | ||
- name: username | ||
description: String length test generated by dbt-testgen | ||
tests: | ||
- dbt_expectations.expect_column_value_lengths_to_be_between: | ||
min_value: 8 | ||
max_value: 15 | ||
row_condition: '"username" is not null' | ||
- name: email | ||
description: String length test generated by dbt-testgen | ||
tests: | ||
- dbt_expectations.expect_column_value_lengths_to_be_between: | ||
min_value: 18 | ||
max_value: 25 | ||
row_condition: '"email" is not null' | ||
- name: user_status | ||
description: String length test generated by dbt-testgen | ||
tests: | ||
- dbt_expectations.expect_column_value_lengths_to_be_between: | ||
min_value: 6 | ||
max_value: 8 | ||
row_condition: '"user_status" is not null' | ||
{% endset %} | ||
|
||
{{ assert_equal (actual_yaml | trim, expected_yaml | trim) }} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
|
||
{% macro get_random_function() %} | ||
{{ return(adapter.dispatch('get_random_function', 'testgen')()) }} | ||
{% endmacro %} | ||
|
||
{% macro default__get_random_function(colname) %} | ||
{{ return("RANDOM") }} | ||
{% endmacro %} |
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,52 @@ | ||
version: 2 | ||
|
||
macros: | ||
- name: get_test_suggestions | ||
description: Generates YAML schema file that includes tests for your data | ||
arguments: | ||
- name: column_name | ||
type: string | ||
description: The name of the column you want to convert | ||
- name: precision | ||
type: integer | ||
description: Number of decimal places. Defaults to 2. | ||
|
||
- name: table_relation | ||
type: Relation | ||
description: | | ||
The [dbt Relation](https://docs.getdbt.com/reference/dbt-classes#relation) | ||
you wish to generate tests for. | ||
Example: ref("mymodel") | ||
- name: sample | ||
type: bool | ||
description: Take a random sample when using the `limit` argument | ||
- name: limit | ||
type: integer | ||
description: Use only this number of records to generate tests. | ||
- name: resource_type | ||
type: string | ||
description: The type of resource that `table_relation` is - 'models', 'seeds', or 'sources' | ||
- name: column_config | ||
type: dict | ||
description: "Configurations to set on columns. Example - {'quote': true}" | ||
- name: exclude_types | ||
type: list | ||
description: Column types to exclude from tests. | ||
- name: exclude_cols | ||
type: list | ||
description: Columns to exclude from tests. | ||
- name: tags | ||
type: list | ||
description: Tags to put on the tests. | ||
- name: tests | ||
type: list | ||
description: "Types of tests to generate. Example: ['uniqueness', 'accepted_values', 'range']" | ||
- name: composite_key_length | ||
type: integer | ||
description: Max length of the composite key for uniqueness tests. | ||
- name: dbt_config | ||
type: dict | ||
description: Existing parsed DBT Schema file to add tests onto. | ||
- name: return_object | ||
type: bool | ||
description: Return the DBT Schema file as a dict object instead of printing YAML. |
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
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
Oops, something went wrong.