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.
Merge pull request elementary-data#587 from elementary-data/ele-1860-…
…get-columns-descriptions-to-the-oss-and-to-the-cloud Changed the columns models.
- Loading branch information
Showing
14 changed files
with
144 additions
and
41 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 |
---|---|---|
@@ -1,5 +1,5 @@ | ||
name: "elementary" | ||
version: "0.11.2" | ||
version: "0.12.0" | ||
|
||
require-dbt-version: [">=1.0.0", "<2.0.0"] | ||
|
||
|
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.
7 changes: 7 additions & 0 deletions
7
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,7 @@ | ||
{% macro get_information_schema_columns_materialized() %} | ||
{% if var("sync", false) %} | ||
{% do return("table") %} | ||
{% endif %} | ||
{% do return("view") %} | ||
{% 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.
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,69 @@ | ||
{%- 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'), | ||
('resource_type', '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') or none, | ||
'database_name': table_node.get('database'), | ||
'schema_name': table_node.get('schema'), | ||
'table_name': table_node.get('alias'), | ||
'resource_type': table_node.get('resource_type'), | ||
'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
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,37 @@ | ||
{{ | ||
config( | ||
materialized = 'view', | ||
bind=False | ||
) | ||
}} | ||
|
||
|
||
with information_schema_columns as ( | ||
select | ||
lower(database_name) as database_name, | ||
lower(schema_name) as schema_name, | ||
lower(table_name) as table_name, | ||
lower(column_name) as name, | ||
data_type | ||
from {{ ref("information_schema_columns") }} | ||
), | ||
|
||
dbt_columns as ( | ||
select | ||
lower(database_name) as database_name, | ||
lower(schema_name) as schema_name, | ||
lower(table_name) as table_name, | ||
lower(name) as name, | ||
description | ||
from {{ ref("dbt_columns") }} | ||
) | ||
|
||
select | ||
database_name, | ||
schema_name, | ||
table_name, | ||
name, | ||
data_type, | ||
description | ||
from information_schema_columns | ||
left join dbt_columns using (database_name, schema_name, table_name, name) |
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 %} |