-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support for using profiles in dbt models (#31)
* Add debug logging to get_profile * Change all the macros now accept either relation or relation_name arg * Change get_profile now returns a SQL query * Add get_profile_table macro that returns an Agate.Table * Add get_relation macro * Change select_from_information_schema_columns now takes only relation as arg * Update README * Update README * Update workflow * Remove a test * Fix a test Co-authored-by: Simo Tumelius <[email protected]>
- Loading branch information
1 parent
aaa0de3
commit 7fc757b
Showing
13 changed files
with
167 additions
and
72 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
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,4 @@ | ||
-- depends_on: {{ ref("test_data") }} | ||
{% if execute %} | ||
{{ dbt_profiler.get_profile(relation=ref("test_data")) }} | ||
{% endif %} |
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,36 @@ | ||
version: 2 | ||
|
||
models: | ||
- name: profile | ||
columns: | ||
- name: column_name | ||
tests: | ||
- not_null | ||
- unique | ||
|
||
- name: data_type | ||
tests: | ||
- not_null | ||
|
||
- name: not_null_proportion | ||
tests: | ||
- not_null | ||
|
||
- name: distinct_proportion | ||
tests: | ||
- not_null | ||
|
||
- name: distinct_count | ||
tests: | ||
- not_null | ||
|
||
- name: is_unique | ||
tests: | ||
- not_null | ||
- accepted_values: | ||
quote: false | ||
values: ["TRUE", "FALSE"] | ||
|
||
- name: profiled_at | ||
tests: | ||
- not_null |
2 changes: 1 addition & 1 deletion
2
..._tests/tests/test_get_profile_columns.sql → .../tests/test_get_profile_table_columns.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
2 changes: 1 addition & 1 deletion
2
...ion_tests/tests/test_get_profile_rows.sql → ...sts/tests/test_get_profile_table_rows.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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
{% macro get_profile_table(relation=none, relation_name=none, schema=none, database=none) %} | ||
|
||
{%- set relation = dbt_profiler.get_relation( | ||
relation=relation, | ||
relation_name=relation_name, | ||
schema=schema, | ||
database=database | ||
) -%} | ||
{%- set profile_sql = dbt_profiler.get_profile(relation=relation) -%} | ||
{{ log(profile_sql, info=False) }} | ||
{% set results = run_query(profile_sql) %} | ||
{% set results = results.rename(results.column_names | map('lower')) %} | ||
{% do return(results) %} | ||
|
||
{% 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,32 @@ | ||
{% macro get_relation(relation=none, relation_name=none, schema=none, database=none) %} | ||
|
||
{% if relation is none and relation_name is none %} | ||
{{ exceptions.raise_compiler_error("Either relation or relation_name must be specified.") }} | ||
{% endif %} | ||
|
||
{% if relation is none %} | ||
{% if schema is none %} | ||
{% set schema = target.schema %} | ||
{% endif %} | ||
|
||
{% if database is none %} | ||
{% set database = target.database %} | ||
{% endif %} | ||
|
||
{{ log("Get relation %s (database=%s, schema=%s)" | format(adapter.quote(relation_name), adapter.quote(database), adapter.quote(schema)), info=False) }} | ||
|
||
{%- | ||
set relation = adapter.get_relation( | ||
database=database, | ||
schema=schema, | ||
identifier=relation_name | ||
) | ||
-%} | ||
{% if relation is none %} | ||
{{ exceptions.raise_compiler_error("Relation " ~ adapter.quote(relation_name) ~ " does not exist or not authorized.") }} | ||
{% endif %} | ||
{% endif %} | ||
|
||
{% do return(relation) %} | ||
|
||
{% 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
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