-
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.
Merge pull request #9 from kgmcquate/develop
Added string length tests and sampling
- Loading branch information
Showing
17 changed files
with
364 additions
and
14 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
{ | ||
"sqltools.connections": [ | ||
{ | ||
"previewLimit": 50, | ||
"server": "lake-freeze-db.cu0bcthnum69.us-east-1.rds.amazonaws.com", | ||
"port": 5432, | ||
"driver": "PostgreSQL", | ||
"name": "weather", | ||
"database": "postgres", | ||
"username": "postgres", | ||
"password": "8bF6G!Wy" | ||
} | ||
] | ||
} |
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 +1 @@ | ||
{"metadata": {"dbt_schema_version": "https://schemas.getdbt.com/dbt/catalog/v1.json", "dbt_version": "1.7.4", "generated_at": "2024-01-03T04:59:27.467159Z", "invocation_id": "9da1e8ba-623e-4944-bd70-71b4be14443b", "env": {}}, "nodes": {"seed.testgen_integration_tests.colnames_with_spaces": {"metadata": {"type": "BASE TABLE", "schema": "main_integration_test_data", "name": "colnames_with_spaces", "database": "integration_test_data", "comment": null, "owner": null}, "columns": {"first name": {"type": "VARCHAR", "index": 1, "name": "first name", "comment": null}, "age (years)": {"type": "INTEGER", "index": 2, "name": "age (years)", "comment": null}, "current city": {"type": "VARCHAR", "index": 3, "name": "current city", "comment": null}}, "stats": {"has_stats": {"id": "has_stats", "label": "Has Stats?", "value": false, "include": false, "description": "Indicates whether there are statistics for this table"}}, "unique_id": "seed.testgen_integration_tests.colnames_with_spaces"}, "seed.testgen_integration_tests.users": {"metadata": {"type": "BASE TABLE", "schema": "main_integration_test_data", "name": "users", "database": "integration_test_data", "comment": null, "owner": null}, "columns": {"user_id": {"type": "INTEGER", "index": 1, "name": "user_id", "comment": null}, "username": {"type": "VARCHAR", "index": 2, "name": "username", "comment": null}, "email": {"type": "VARCHAR", "index": 3, "name": "email", "comment": null}, "age": {"type": "INTEGER", "index": 4, "name": "age", "comment": null}, "user_status": {"type": "VARCHAR", "index": 5, "name": "user_status", "comment": null}}, "stats": {"has_stats": {"id": "has_stats", "label": "Has Stats?", "value": false, "include": false, "description": "Indicates whether there are statistics for this table"}}, "unique_id": "seed.testgen_integration_tests.users"}}, "sources": {}, "errors": null} | ||
{"metadata": {"dbt_schema_version": "https://schemas.getdbt.com/dbt/catalog/v1.json", "dbt_version": "1.7.4", "generated_at": "2024-01-03T06:03:44.780433Z", "invocation_id": "40a950e0-7023-41e7-bb8d-8483b6e8e8c4", "env": {}}, "nodes": {"seed.testgen_integration_tests.colnames_with_spaces": {"metadata": {"type": "BASE TABLE", "schema": "main_integration_test_data", "name": "colnames_with_spaces", "database": "integration_test_data", "comment": null, "owner": null}, "columns": {"first name": {"type": "VARCHAR", "index": 1, "name": "first name", "comment": null}, "age (years)": {"type": "INTEGER", "index": 2, "name": "age (years)", "comment": null}, "current city": {"type": "VARCHAR", "index": 3, "name": "current city", "comment": null}}, "stats": {"has_stats": {"id": "has_stats", "label": "Has Stats?", "value": false, "include": false, "description": "Indicates whether there are statistics for this table"}}, "unique_id": "seed.testgen_integration_tests.colnames_with_spaces"}, "seed.testgen_integration_tests.users": {"metadata": {"type": "BASE TABLE", "schema": "main_integration_test_data", "name": "users", "database": "integration_test_data", "comment": null, "owner": null}, "columns": {"user_id": {"type": "INTEGER", "index": 1, "name": "user_id", "comment": null}, "username": {"type": "VARCHAR", "index": 2, "name": "username", "comment": null}, "email": {"type": "VARCHAR", "index": 3, "name": "email", "comment": null}, "age": {"type": "INTEGER", "index": 4, "name": "age", "comment": null}, "user_status": {"type": "VARCHAR", "index": 5, "name": "user_status", "comment": null}}, "stats": {"has_stats": {"id": "has_stats", "label": "Has Stats?", "value": false, "include": false, "description": "Indicates whether there are statistics for this table"}}, "unique_id": "seed.testgen_integration_tests.users"}}, "sources": {}, "errors": null} |
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
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.