-
Notifications
You must be signed in to change notification settings - Fork 161
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
implement clustering, partitioning, and auto refresh for materialized…
… views
- Loading branch information
1 parent
37b2ccd
commit 0696752
Showing
12 changed files
with
237 additions
and
128 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
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
15 changes: 15 additions & 0 deletions
15
dbt/include/bigquery/macros/relation_components/cluster/describe.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,15 @@ | ||
{% macro bigquery__get_describe_cluster_sql(relation) %} | ||
select | ||
column_name | ||
from {{ relation.information_schema('COLUMNS') }} | ||
where table_name = '{{ relation.identifier }}' | ||
and table_schema = '{{ relation.schema }}' | ||
and table_catalog = '{{ relation.database }}' | ||
and clustering_ordinal_position is not null | ||
{% endmacro %} | ||
|
||
|
||
{% macro bigquery__describe_cluster(relation) %} | ||
{%- set _sql = bigquery__get_describe_cluster_sql(relation) -%} | ||
{% do return(run_query(_sql)) %} | ||
{% endmacro %} |
15 changes: 15 additions & 0 deletions
15
dbt/include/bigquery/macros/relation_components/options/describe.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,15 @@ | ||
{% macro bigquery__get_describe_options_sql(relation) %} | ||
select | ||
option_name, | ||
option_value | ||
from {{ relation.information_schema('TABLE_OPTIONS') }} | ||
where table_name = '{{ relation.identifier }}' | ||
and table_schema = '{{ relation.schema }}' | ||
and table_catalog = '{{ relation.database }}' | ||
{% endmacro %} | ||
|
||
|
||
{% macro bigquery__describe_options(relation) %} | ||
{%- set _sql = bigquery__get_describe_options_sql(relation) -%} | ||
{% do return(run_query(_sql)) %} | ||
{% endmacro %} |
26 changes: 26 additions & 0 deletions
26
dbt/include/bigquery/macros/relation_components/partition/describe.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,26 @@ | ||
{% macro bigquery__get_describe_partition_sql(relation) %} | ||
select | ||
c.column_name as partition_column_name, | ||
c.data_type as partition_data_type, | ||
case | ||
when regexp_contains(p.partition_id, '^[0-9]{4}$') THEN 'year' | ||
when regexp_contains(p.partition_id, '^[0-9]{6}$') THEN 'month' | ||
when regexp_contains(p.partition_id, '^[0-9]{8}$') THEN 'day' | ||
when regexp_contains(p.partition_id, '^[0-9]{10}$') THEN 'hour' | ||
end as partition_type | ||
from {{ relation.information_schema('PARTITIONS') }} p | ||
join {{ relation.information_schema('COLUMNS') }} c | ||
on c.table_name = p.table_name | ||
and c.table_schema = p.table_schema | ||
and c.table_catalog = p.table_catalog | ||
where p.table_name = '{{ relation.identifier }}' | ||
and p.table_schema = '{{ relation.schema }}' | ||
and p.table_catalog = '{{ relation.database }}' | ||
and c.is_partitioning_column = 'YES' | ||
{% endmacro %} | ||
|
||
|
||
{% macro bigquery__describe_partition(relation) %} | ||
{% set _sql = bigquery__get_describe_partition_sql(relation) %} | ||
{% do return(run_query(_sql)) %} | ||
{% 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
55 changes: 17 additions & 38 deletions
55
dbt/include/bigquery/macros/relations/materialized_view/describe.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 |
---|---|---|
@@ -1,45 +1,24 @@ | ||
{% macro bigquery__describe_materialized_view(relation) %} | ||
{%- set _materialized_view_sql -%} | ||
-- checks each column to see if its a cluster_by field then adds it to a new list | ||
with ClusteringColumns as ( | ||
select | ||
table_name, | ||
ARRAY_AGG( | ||
case | ||
when clustering_ordinal_position is not null then column_name | ||
else null | ||
end | ||
ignore nulls | ||
) as clustering_fields | ||
from | ||
`{{ relation.database }}.{{ relation.schema }}.INFORMATION_SCHEMA.COLUMNS` | ||
where | ||
table_name = '{{ relation.name }}' | ||
GROUP BY | ||
table_name | ||
) | ||
select | ||
mv.table_name as materialized_view, | ||
c.column_name, | ||
c.is_partitioning_column, | ||
c.clustering_ordinal_position, | ||
topt.option_name, | ||
topt.option_value, | ||
topt.option_type | ||
from | ||
`{{ relation.database }}.{{ relation.schema }}.INFORMATION_SCHEMA.MATERIALIZED_VIEWS` mv | ||
left join | ||
`{{ relation.database }}.{{ relation.schema }}.INFORMATION_SCHEMA.COLUMNS` c | ||
on | ||
mv.table_name = c.table_name | ||
left join | ||
`{{ relation.database }}.{{ relation.schema }}.INFORMATION_SCHEMA.TABLE_OPTIONS` topt | ||
on | ||
mv.table_name = topt.table_name | ||
where | ||
mv.table_name = '{{ relation.name }}' | ||
table_name, | ||
table_schema, | ||
table_catalog | ||
from {{ relation.information_schema('MATERIALIZED_VIEWS') }} | ||
where table_name = '{{ relation.identifier }}' | ||
and table_schema = '{{ relation.schema }}' | ||
and table_catalog = '{{ relation.database }}' | ||
{%- endset %} | ||
{% set _materialized_view = run_query(_materialized_view_sql) %} | ||
|
||
{% do return({'materialized_view': _materialized_viewy}) %} | ||
{%- set _partition_by = bigquery__describe_partition(relation) -%} | ||
{%- set _cluster_by = bigquery__describe_cluster(relation) -%} | ||
{%- set _options = bigquery__describe_options(relation) -%} | ||
|
||
{% do return({ | ||
'materialized_view': _materialized_view, | ||
'partition_by': _partition_by, | ||
'cluster_by': _cluster_by, | ||
'options': _options | ||
}) %} | ||
{% endmacro %} |
Oops, something went wrong.