-
Notifications
You must be signed in to change notification settings - Fork 79
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Use the dbt Events Module * Upgrade dbt-core to 1.0.0 * Add a profile_template.yml file * Reorganize macros following dbt-labs/dbt-core#4154 * Use MANIFEST.in instead of package_data see: https://stackoverflow.com/questions/7522250/how-to-include-package-data-with-setuptools-distutils * Do not quote seed columns see dbt-labs/dbt-core@64fc3a3 * Upgrade to 1.0.1
- Loading branch information
Showing
23 changed files
with
218 additions
and
210 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 @@ | ||
recursive-include dbt/include *.sql *.yml |
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 @@ | ||
version = "0.21.0" | ||
version = "1.0.1" |
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 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
{% macro athena__get_columns_in_relation(relation) -%} | ||
{% call statement('get_columns_in_relation', fetch_result=True) %} | ||
|
||
select | ||
column_name, | ||
data_type, | ||
null as character_maximum_length, | ||
null as numeric_precision, | ||
null as numeric_scale | ||
|
||
from {{ relation.information_schema('columns') }} | ||
where LOWER(table_name) = LOWER('{{ relation.identifier }}') | ||
{% if relation.schema %} | ||
and LOWER(table_schema) = LOWER('{{ relation.schema }}') | ||
{% endif %} | ||
order by ordinal_position | ||
|
||
{% endcall %} | ||
|
||
{% set table = load_result('get_columns_in_relation').table %} | ||
{% do return(sql_convert_columns_in_relation(table)) %} | ||
{% 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,5 @@ | ||
{% macro athena__current_timestamp() -%} | ||
-- pyathena converts time zoned timestamps to strings so lets avoid them | ||
-- now() | ||
cast(now() as timestamp) | ||
{%- 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 |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{% macro athena__drop_relation(relation) -%} | ||
{% if config.get('incremental_strategy') == 'insert_overwrite' %} | ||
{%- do adapter.clean_up_table(relation.schema, relation.table) -%} | ||
{% endif %} | ||
{% call statement('drop_relation', auto_begin=False) -%} | ||
drop {{ relation.type }} if exists {{ relation }} | ||
{%- endcall %} | ||
{% endmacro %} |
7 changes: 7 additions & 0 deletions
7
dbt/include/athena/macros/materializations/models/helpers.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 set_table_classification(relation, default_value) -%} | ||
{%- set format = config.get('format', default=default_value) -%} | ||
|
||
{% call statement('set_table_classification', auto_begin=False) -%} | ||
alter table {{ relation }} set tblproperties ('classification' = '{{ format }}') | ||
{%- endcall %} | ||
{%- endmacro %} |
54 changes: 54 additions & 0 deletions
54
dbt/include/athena/macros/materializations/models/incremental/helpers.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,54 @@ | ||
{% macro validate_get_incremental_strategy(raw_strategy) %} | ||
{% set invalid_strategy_msg -%} | ||
Invalid incremental strategy provided: {{ raw_strategy }} | ||
Expected one of: 'append', 'insert_overwrite' | ||
{%- endset %} | ||
|
||
{% if raw_strategy not in ['append', 'insert_overwrite'] %} | ||
{% do exceptions.raise_compiler_error(invalid_strategy_msg) %} | ||
{% endif %} | ||
|
||
{% do return(raw_strategy) %} | ||
{% endmacro %} | ||
|
||
{% macro incremental_insert(tmp_relation, target_relation, statement_name="main") %} | ||
{%- set dest_columns = adapter.get_columns_in_relation(target_relation) -%} | ||
{%- set dest_cols_csv = dest_columns | map(attribute='quoted') | join(', ') -%} | ||
|
||
insert into {{ target_relation }} ({{ dest_cols_csv }}) | ||
( | ||
select {{ dest_cols_csv }} | ||
from {{ tmp_relation }} | ||
); | ||
{%- endmacro %} | ||
|
||
{% macro delete_overlapping_partitions(target_relation, tmp_relation, partitioned_by) %} | ||
{%- set partitioned_keys = partitioned_by | tojson | replace('\"', '') | replace('[', '') | replace(']', '') -%} | ||
{% call statement('get_partitions', fetch_result=True) %} | ||
select distinct {{partitioned_keys}} from {{ tmp_relation }}; | ||
{% endcall %} | ||
{%- set table = load_result('get_partitions').table -%} | ||
{%- set rows = table.rows -%} | ||
{%- set partitions = [] -%} | ||
{%- for row in rows -%} | ||
{%- set single_partition = [] -%} | ||
{%- for col in row -%} | ||
{%- set column_type = adapter.convert_type(table, loop.index0) -%} | ||
{%- if column_type == 'integer' -%} | ||
{%- set value = col|string -%} | ||
{%- elif column_type == 'string' -%} | ||
{%- set value = "'" + col + "'" -%} | ||
{%- elif column_type == 'date' -%} | ||
{%- set value = "'" + col|string + "'" -%} | ||
{%- else -%} | ||
{%- do exceptions.raise_compiler_error('Need to add support for column type ' + column_type) -%} | ||
{%- endif -%} | ||
{%- do single_partition.append(partitioned_by[loop.index0] + '=' + value) -%} | ||
{%- endfor -%} | ||
{%- set single_partition_expression = single_partition | join(' and ') -%} | ||
{%- do partitions.append('(' + single_partition_expression + ')') -%} | ||
{%- endfor -%} | ||
{%- for i in range(partitions | length) %} | ||
{%- do adapter.clean_up_partitions(target_relation.schema, target_relation.table, partitions[i]) -%} | ||
{%- endfor -%} | ||
{%- endmacro %} |
55 changes: 0 additions & 55 deletions
55
...a/macros/materializations/incremental.sql → ...ations/models/incremental/incremental.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
Oops, something went wrong.