-
Notifications
You must be signed in to change notification settings - Fork 94
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into dependabot/pip/pydantic-gte-1.10-and-lt-3.0
- Loading branch information
Showing
18 changed files
with
437 additions
and
111 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,12 @@ | ||
{% macro athena__persist_docs(relation, model, for_relation, for_columns) -%} | ||
{% set persist_relation_docs = for_relation and config.persist_relation_docs() and model.description %} | ||
{% set persist_column_docs = for_columns and config.persist_column_docs() and model.columns %} | ||
{% if (persist_relation_docs or persist_column_docs) and relation.type != 'view' %} | ||
{% set skip_archive_table_version = not is_incremental() %} | ||
{% if persist_relation_docs or persist_column_docs %} | ||
{% do adapter.persist_docs_to_glue(relation, | ||
model, | ||
persist_relation_docs, | ||
persist_column_docs) %}} | ||
persist_column_docs, | ||
skip_archive_table_version=skip_archive_table_version) %}} | ||
{% endif %} | ||
{% endmacro %} |
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 %} |
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
Oops, something went wrong.