Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Athena / Presto support for some aspects of dbt utils #547

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 10 additions & 0 deletions CHANGELOG.md
@@ -1,3 +1,13 @@
# dbt-utils v0.8.next

## Fixes
- `get_tables_by_pattern_sql()` support of Athena / Presto adapters ([#546](https://github.com/dbt-labs/dbt-utils/issues/546))
- `not_null_proportion` and `datatype numeric` support of Athena / Presto adapters ([#553] ( https://github.com/dbt-labs/dbt-utils/issues/553))

## Contributors:
- [@SOVALINUX](https://github.com/SOVALINUX) (#546, #553)


# dbt-utils v0.8.3
## New features
- A macro for deduplicating data, `deduplicate()` ([#335](https://github.com/dbt-labs/dbt-utils/issues/335), [#512](https://github.com/dbt-labs/dbt-utils/pull/512))
Expand Down
8 changes: 8 additions & 0 deletions macros/cross_db_utils/current_timestamp.sql
Expand Up @@ -14,6 +14,14 @@
current_timestamp
{% endmacro %}

{% macro athena__current_timestamp() %}
now()
{% endmacro %}

{% macro presto__current_timestamp() %}
now()
{% endmacro %}



{% macro current_timestamp_in_utc() -%}
Expand Down
8 changes: 8 additions & 0 deletions macros/cross_db_utils/datatypes.sql
Expand Up @@ -69,6 +69,14 @@
numeric
{% endmacro %}

{% macro athena__type_numeric() %}
double
{% endmacro %}

{% macro presto__type_numeric() %}
double
{% endmacro %}


{# bigint ------------------------------------------------- #}

Expand Down
20 changes: 20 additions & 0 deletions macros/cross_db_utils/dateadd.sql
Expand Up @@ -35,3 +35,23 @@
{{ return(dbt_utils.default__dateadd(datepart, interval, from_date_or_timestamp)) }}

{% endmacro %}

{% macro athena__dateadd(datepart, interval, from_date_or_timestamp) %}

date_add(
'{{ datepart | replace("'", "") }}',
{{ interval }},
{{ from_date_or_timestamp }}
)

{% endmacro %}

{% macro presto__dateadd(datepart, interval, from_date_or_timestamp) %}

date_add(
'{{ datepart | replace("'", "") }}',
{{ interval }},
{{ from_date_or_timestamp }}
)

{% endmacro %}
3 changes: 2 additions & 1 deletion macros/generic_tests/not_null_proportion.sql
Expand Up @@ -10,7 +10,7 @@

with validation as (
select
sum(case when {{ column_name }} is null then 0 else 1 end) / cast(count(*) as numeric) as not_null_proportion
sum(case when {{ column_name }} is null then 0 else 1 end) / {{ dbt_utils.safe_cast('count(*)', dbt_utils.type_numeric() ) }} as not_null_proportion
from {{ model }}
),
validation_errors as (
Expand All @@ -24,3 +24,4 @@ select
from validation_errors

{% endmacro %}

33 changes: 33 additions & 0 deletions macros/sql/get_tables_by_pattern_sql.sql
Expand Up @@ -16,6 +16,39 @@

{% endmacro %}

{% macro athena__get_tables_by_pattern_sql(schema_pattern, table_pattern, exclude='', database=target.database) %}

{% set table_schema_like_str = "regexp_like({}, '(?i)\\A{}\\Z')".format("table_schema", schema_pattern) %}
{% set table_name_like_str = "regexp_like({}, '(?i)\\A{}\\Z')".format("table_name", table_pattern) %}
{% set table_name_not_like_str = "not regexp_like({}, '(?i)\\A{}\\Z')".format("table_name", exclude) %}

select distinct
table_schema as "table_schema",
table_name as "table_name",
{{ dbt_utils.get_table_types_sql() }}
from {{ database }}.information_schema.tables
where {{ table_schema_like_str }}
and {{ table_name_like_str }}
and {{ table_name_not_like_str }}

{% endmacro %}

{% macro presto__get_tables_by_pattern_sql(schema_pattern, table_pattern, exclude='', database=target.database) %}

{% set table_schema_like_str = "regexp_like({}, '(?i)\\A{}\\Z')".format("table_schema", schema_pattern) %}
{% set table_name_like_str = "regexp_like({}, '(?i)\\A{}\\Z')".format("table_name", table_pattern) %}
{% set table_name_not_like_str = "not regexp_like({}, '(?i)\\A{}\\Z')".format("table_name", exclude) %}

select distinct
table_schema as "table_schema",
table_name as "table_name",
{{ dbt_utils.get_table_types_sql() }}
from {{ database }}.information_schema.tables
where {{ table_schema_like_str }}
and {{ table_name_like_str }}
and {{ table_name_not_like_str }}

{% endmacro %}

{% macro bigquery__get_tables_by_pattern_sql(schema_pattern, table_pattern, exclude='', database=target.database) %}

Expand Down