forked from elementary-data/dbt-data-reliability
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
'dbt_columns' now only contains columns that are documented in the dbt project. 'information_schema_columns' contains all the columns from all the schemas that your dbt project addresses.
- Loading branch information
Showing
12 changed files
with
122 additions
and
39 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
16 changes: 0 additions & 16 deletions
16
macros/edr/dbt_artifacts/dbt_columns/get_dbt_columns_materialization.sql
This file was deleted.
Oops, something went wrong.
16 changes: 16 additions & 0 deletions
16
macros/edr/dbt_artifacts/dbt_columns/get_information_schema_columns_materialized.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,16 @@ | ||
{% macro get_information_schema_columns_materialized() %} | ||
{% if var("sync", false) %} | ||
{% do return("table") %} | ||
{% endif %} | ||
{% do return(adapter.dispatch("get_information_schema_columns_materialized", "elementary")()) %} | ||
{% endmacro %} | ||
|
||
|
||
{% macro default__get_information_schema_columns_materialized() %} | ||
{% do return("view") %} | ||
{% endmacro %} | ||
|
||
|
||
{% macro bigquery__get_information_schema_columns_materialized() %} | ||
{% do return("incremental") %} | ||
{% 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 was deleted.
Oops, something went wrong.
7 changes: 7 additions & 0 deletions
7
macros/edr/dbt_artifacts/dbt_columns/upload_information_schema_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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{% macro upload_information_schema_columns() %} | ||
{% set relation = elementary.get_elementary_relation("information_schema_columns") %} | ||
{% if execute and relation %} | ||
{% set information_schema_columns_query = elementary.get_information_schema_columns_query(is_model_build_context=false) %} | ||
{% do elementary.create_or_replace(false, relation, information_schema_columns_query) %} | ||
{% endif %} | ||
{% 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
{%- macro upload_dbt_columns(should_commit=false, metadata_hashes=none) -%} | ||
{% set relation = elementary.get_elementary_relation('dbt_columns') %} | ||
{% if execute and relation %} | ||
{% set tables = graph.nodes.values() | list + graph.sources.values() | list %} | ||
{% do elementary.upload_artifacts_to_table(relation, tables, elementary.flatten_table_columns, should_commit=should_commit, metadata_hashes=metadata_hashes) %} | ||
{%- endif -%} | ||
{{- return('') -}} | ||
{%- endmacro -%} | ||
|
||
{% macro get_dbt_columns_empty_table_query() %} | ||
{% set columns = [ | ||
('unique_id', 'string'), | ||
('parent_unique_id', 'string'), | ||
('name', 'string'), | ||
('data_type', 'string'), | ||
('tags', 'long_string'), | ||
('meta', 'long_string'), | ||
('database_name', 'string'), | ||
('schema_name', 'string'), | ||
('table_name', 'string'), | ||
('description', 'long_string'), | ||
('generated_at', 'string'), | ||
('metadata_hash', 'string'), | ||
] %} | ||
{% set dbt_columns_empty_table_query = elementary.empty_table(columns) %} | ||
{{ return(dbt_columns_empty_table_query) }} | ||
{% endmacro %} | ||
|
||
{% macro flatten_table_columns(table_node) %} | ||
{% set column_nodes = table_node.get("columns") %} | ||
{% if not column_nodes %} | ||
{% do return(none) %} | ||
{% endif %} | ||
|
||
{% set flattened_columns = [] %} | ||
{% for column_node in column_nodes.values() %} | ||
{% do flattened_columns.append(elementary.flatten_column(table_node, column_node)) %} | ||
{% endfor %} | ||
{% do return(flattened_columns) %} | ||
{% endmacro %} | ||
|
||
{% macro flatten_column(table_node, column_node) %} | ||
{% set config_dict = elementary.safe_get_with_default(column_node, 'config', {}) %} | ||
{% set config_meta_dict = elementary.safe_get_with_default(config_dict, 'meta', {}) %} | ||
{% set meta_dict = elementary.safe_get_with_default(column_node, 'meta', {}) %} | ||
{% do meta_dict.update(config_meta_dict) %} | ||
{% set config_tags = elementary.safe_get_with_default(config_dict, 'tags', []) %} | ||
{% set global_tags = elementary.safe_get_with_default(column_node, 'tags', []) %} | ||
{% set meta_tags = elementary.safe_get_with_default(meta_dict, 'tags', []) %} | ||
{% set tags = elementary.union_lists(config_tags, global_tags) %} | ||
{% set tags = elementary.union_lists(tags, meta_tags) %} | ||
{% set flatten_column_metadata_dict = { | ||
'parent_unique_id': table_node.get('unique_id'), | ||
'unique_id': "column.{}.{}".format(table_node.get('unique_id'), column_node.get('name')), | ||
'name': column_node.get('name'), | ||
'data_type': column_node.get('data_type'), | ||
'tags': elementary.filter_none_and_sort(tags), | ||
'meta': meta_dict, | ||
'description': column_node.get('description'), | ||
'database_name': table_node.get('database'), | ||
'schema_name': table_node.get('schema'), | ||
'table_name': table_node.get('alias'), | ||
'generated_at': elementary.datetime_now_utc_as_string(), | ||
} %} | ||
{% do flatten_column_metadata_dict.update({"metadata_hash": elementary.get_artifact_metadata_hash(flatten_column_metadata_dict)}) %} | ||
{% do return(flatten_column_metadata_dict) %} | ||
{% 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,12 @@ | ||
{{ | ||
config( | ||
materialized=elementary.get_dbt_columns_materialized(), | ||
) | ||
materialized='incremental', | ||
transient=False, | ||
post_hook='{{ elementary.upload_dbt_columns() }}', | ||
unique_key='unique_id', | ||
on_schema_change='sync_all_columns', | ||
full_refresh=elementary.get_config_var('elementary_full_refresh') | ||
) | ||
}} | ||
{% if elementary.get_dbt_columns_materialized() == "view" %} | ||
{{ elementary.get_dbt_columns_query() }} | ||
{% else %} | ||
{{ elementary.get_empty_columns_from_information_schema_table() }} | ||
{% endif %} | ||
|
||
{{ elementary.get_dbt_columns_empty_table_query() }} |
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,10 @@ | ||
{{ | ||
config( | ||
materialized=elementary.get_information_schema_columns_materialized(), | ||
) | ||
}} | ||
{% if elementary.get_information_schema_columns_materialized() == "view" %} | ||
{{ elementary.get_information_schema_columns_query() }} | ||
{% else %} | ||
{{ elementary.get_empty_columns_from_information_schema_table() }} | ||
{% endif %} |