-
Notifications
You must be signed in to change notification settings - Fork 101
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/fix/cross-account-delete-table' …
…into fix/cross-account-delete-table
- Loading branch information
Showing
24 changed files
with
703 additions
and
115 deletions.
There are no files selected for viewing
Validating CODEOWNERS rules …
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 @@ | ||
* @jessedobbelaere @Jrmyy @mattiamatrix @nicor88 @svdimchenko @thenaturalist | ||
* @jessedobbelaere @Jrmyy @mattiamatrix @nicor88 @svdimchenko |
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 +1 @@ | ||
version = "1.5.1" | ||
version = "1.6.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
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
52 changes: 52 additions & 0 deletions
52
dbt/include/athena/macros/materializations/models/helpers/get_partition_batches.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,52 @@ | ||
{% macro get_partition_batches(sql) -%} | ||
{%- set partitioned_by = config.get('partitioned_by') -%} | ||
{%- set athena_partitions_limit = config.get('partitions_limit', 100) | int -%} | ||
{%- set partitioned_keys = adapter.format_partition_keys(partitioned_by) -%} | ||
{% do log('PARTITIONED KEYS: ' ~ partitioned_keys) %} | ||
|
||
{% call statement('get_partitions', fetch_result=True) %} | ||
select distinct {{ partitioned_keys }} from ({{ sql }}) order by {{ partitioned_keys }}; | ||
{% endcall %} | ||
|
||
{%- set table = load_result('get_partitions').table -%} | ||
{%- set rows = table.rows -%} | ||
{%- set partitions = {} -%} | ||
{% do log('TOTAL PARTITIONS TO PROCESS: ' ~ rows | length) %} | ||
{%- set partitions_batches = [] -%} | ||
|
||
{%- 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 = "DATE'" + col | string + "'" -%} | ||
{%- elif column_type == 'timestamp' -%} | ||
{%- set value = "TIMESTAMP'" + col | string + "'" -%} | ||
{%- else -%} | ||
{%- do exceptions.raise_compiler_error('Need to add support for column type ' + column_type) -%} | ||
{%- endif -%} | ||
{%- set partition_key = adapter.format_one_partition_key(partitioned_by[loop.index0]) -%} | ||
{%- do single_partition.append(partition_key + '=' + value) -%} | ||
{%- endfor -%} | ||
|
||
{%- set single_partition_expression = single_partition | join(' and ') -%} | ||
|
||
{%- set batch_number = (loop.index0 / athena_partitions_limit) | int -%} | ||
{% if not batch_number in partitions %} | ||
{% do partitions.update({batch_number: []}) %} | ||
{% endif %} | ||
|
||
{%- do partitions[batch_number].append('(' + single_partition_expression + ')') -%} | ||
{%- if partitions[batch_number] | length == athena_partitions_limit or loop.last -%} | ||
{%- do partitions_batches.append(partitions[batch_number] | join(' or ')) -%} | ||
{%- endif -%} | ||
{%- endfor -%} | ||
|
||
{{ return(partitions_batches) }} | ||
|
||
{%- endmacro %} |
Oops, something went wrong.